1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
48
48
#include "drizzled/gettext.h"
49
49
#include "drizzled/configmake.h"
50
50
#include "drizzled/session.h"
51
#include "drizzled/session/cache.h"
52
51
#include "drizzled/internal/my_sys.h"
53
52
#include "drizzled/unireg.h"
54
53
#include "drizzled/drizzled.h"
60
59
#include "drizzled/tztime.h"
61
60
#include "drizzled/signal_handler.h"
62
61
#include "drizzled/replication_services.h"
63
#include "drizzled/transaction_services.h"
65
#include "drizzled/util/backtrace.h"
67
63
using namespace drizzled;
68
64
using namespace std;
216
209
case google::protobuf::LOGLEVEL_ERROR:
217
210
case google::protobuf::LOGLEVEL_FATAL:
219
std::cerr << "GoogleProtoErrorThrower(" << filename << ", " << line << ", " << message << ")";
220
212
throw("error in google protocol buffer parsing");
243
236
google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
245
238
/* Function generates error messages before abort */
246
error_handler_hook= my_message_sql;
247
239
/* init_common_variables must get basic settings such as data_home_dir
248
240
and plugin_load_list. */
249
if (init_common_variables(argc, argv, modules))
241
if (init_common_variables(argc, argv))
250
242
unireg_abort(1); // Will do exit
254
After this we can't quit by a simple unireg_abort
262
250
if (not opt_help)
264
if (chdir(getDataHome().file_string().c_str()))
252
if (chdir(getDataHome().c_str()))
266
254
errmsg_printf(ERRMSG_LVL_ERROR,
267
255
_("Data directory %s does not exist\n"),
268
getDataHome().file_string().c_str());
256
getDataHome().c_str());
271
259
if (mkdir("local", 0700))
277
265
errmsg_printf(ERRMSG_LVL_ERROR,
278
266
_("Local catalog %s/local does not exist\n"),
279
getDataHome().file_string().c_str());
267
getDataHome().c_str());
283
full_data_home= fs::system_complete(getDataHome());
270
/* TODO: This is a hack until we can properly support std::string in sys_var*/
271
char **data_home_ptr= getDatadirPtr();
272
*data_home_ptr= new char[getDataHome().size()+1] ();
273
fs::path full_data_home_path(fs::system_complete(fs::path(getDataHome())));
274
std::string full_data_home(full_data_home_path.file_string());
275
memcpy(*data_home_ptr, full_data_home.c_str(), full_data_home.size());
284
276
getDataHomeCatalog()= "./";
285
277
getDataHome()= "../";
312
304
if (plugin::Listen::setup())
309
After this we can't quit by a simple unireg_abort
311
error_handler_hook= my_message_sql;
316
313
assert(plugin::num_trx_monitored_objects > 0);
317
314
if (drizzle_rm_tmp_tables() ||
330
327
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
333
TransactionServices &transaction_services= TransactionServices::singleton();
335
/* Send server startup event */
339
if ((session= new Session(plugin::Listen::getNullClient())))
341
currentSession().release();
342
currentSession().reset(session);
343
transaction_services.sendStartupEvent(session);
349
330
/* Listen for new connections and start new session for each connection
350
331
accepted. The listen.getClient() method will return NULL when the server
351
332
should be shutdown. */
352
333
while ((client= plugin::Listen::getClient()) != NULL)
354
Session::shared_ptr session(new Session(client));
335
if (!(session= new Session(client)))
362
341
/* If we error on creation we drop the connection and delete the session. */
363
if (Session::schedule(session))
342
if (session->schedule())
364
343
Session::unlink(session);
367
/* Send server shutdown event */
371
if ((session= new Session(plugin::Listen::getNullClient())))
373
currentSession().release();
374
currentSession().reset(session);
375
transaction_services.sendShutdownEvent(session);
381
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
382
select_thread_in_use= false; // For close_connections
346
LOCK_thread_count.lock();
347
select_thread_in_use=0; // For close_connections
348
LOCK_thread_count.unlock();
384
349
COND_thread_count.notify_all();
386
351
/* Wait until cleanup is done */
388
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
389
while (not ready_to_exit)
390
COND_server_end.wait(scopedLock);
352
LOCK_thread_count.lock();
353
while (!ready_to_exit)
354
pthread_cond_wait(COND_server_end.native_handle(), LOCK_thread_count.native_handle());
355
LOCK_thread_count.unlock();
394
358
module::Registry::shutdown();
395
359
internal::my_end();