42
39
# include <locale.h>
45
#include <boost/filesystem.hpp>
47
43
#include "drizzled/plugin.h"
48
44
#include "drizzled/gettext.h"
49
45
#include "drizzled/configmake.h"
50
46
#include "drizzled/session.h"
51
#include "drizzled/session/cache.h"
52
47
#include "drizzled/internal/my_sys.h"
53
48
#include "drizzled/unireg.h"
54
49
#include "drizzled/drizzled.h"
60
55
#include "drizzled/tztime.h"
61
56
#include "drizzled/signal_handler.h"
62
57
#include "drizzled/replication_services.h"
63
#include "drizzled/transaction_services.h"
65
#include "drizzled/util/backtrace.h"
67
59
using namespace drizzled;
68
60
using namespace std;
69
namespace fs=boost::filesystem;
71
62
static pthread_t select_thread;
72
63
static uint32_t thr_kill_signal;
76
66
All global error messages are sent here where the first one is stored
216
203
case google::protobuf::LOGLEVEL_ERROR:
217
204
case google::protobuf::LOGLEVEL_FATAL:
219
std::cerr << "GoogleProtoErrorThrower(" << filename << ", " << line << ", " << message << ")";
220
206
throw("error in google protocol buffer parsing");
243
230
google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
234
After this we can't quit by a simple unireg_abort
236
error_handler_hook= my_message_sql;
245
238
/* Function generates error messages before abort */
246
error_handler_hook= my_message_sql;
247
/* init_common_variables must get basic settings such as data_home_dir
248
and plugin_load_list. */
249
if (init_common_variables(argc, argv, modules))
239
if (init_common_variables(DRIZZLE_CONFIG_NAME,
240
argc, argv, load_default_groups))
250
241
unireg_abort(1); // Will do exit
254
After this we can't quit by a simple unireg_abort
259
246
select_thread=pthread_self();
260
247
select_thread_in_use=1;
249
if (chdir(data_home_real) && !opt_help)
264
if (chdir(getDataHome().file_string().c_str()))
266
errmsg_printf(ERRMSG_LVL_ERROR,
267
_("Data directory %s does not exist\n"),
268
getDataHome().file_string().c_str());
271
if (mkdir("local", 0700))
273
/* We don't actually care */
277
errmsg_printf(ERRMSG_LVL_ERROR,
278
_("Local catalog %s/local does not exist\n"),
279
getDataHome().file_string().c_str());
283
full_data_home= fs::system_complete(getDataHome());
284
getDataHomeCatalog()= "./";
285
getDataHome()= "../";
251
errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), data_home_real);
254
data_home= data_home_buff;
255
data_home[0]=FN_CURLIB; // all paths are relative from here
290
259
if (server_id == 0)
312
281
if (plugin::Listen::setup())
316
284
assert(plugin::num_trx_monitored_objects > 0);
317
285
if (drizzle_rm_tmp_tables() ||
318
286
my_tz_init((Session *)0, default_tz_name))
330
298
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
301
/* Listen for new connections and start new session for each connection
350
302
accepted. The listen.getClient() method will return NULL when the server
351
303
should be shutdown. */
352
304
while ((client= plugin::Listen::getClient()) != NULL)
354
Session::shared_ptr session(new Session(client));
306
if (!(session= new Session(client)))
362
312
/* If we error on creation we drop the connection and delete the session. */
363
if (Session::schedule(session))
313
if (session->schedule())
364
314
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
317
LOCK_thread_count.lock();
318
select_thread_in_use=0; // For close_connections
319
LOCK_thread_count.unlock();
384
320
COND_thread_count.notify_all();
386
322
/* 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);
323
LOCK_thread_count.lock();
324
while (!ready_to_exit)
325
pthread_cond_wait(COND_server_end.native_handle(), LOCK_thread_count.native_handle());
326
LOCK_thread_count.unlock();
394
329
module::Registry::shutdown();
395
330
internal::my_end();