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"
49
#include "drizzled/stacktrace.h"
54
50
#include "drizzled/drizzled.h"
55
51
#include "drizzled/errmsg_print.h"
56
52
#include "drizzled/data_home.h"
60
56
#include "drizzled/tztime.h"
61
57
#include "drizzled/signal_handler.h"
62
58
#include "drizzled/replication_services.h"
63
#include "drizzled/transaction_services.h"
65
#include "drizzled/util/backtrace.h"
67
60
using namespace drizzled;
68
61
using namespace std;
69
namespace fs=boost::filesystem;
71
63
static pthread_t select_thread;
72
64
static uint32_t thr_kill_signal;
76
67
All global error messages are sent here where the first one is stored
140
131
sigemptyset(&sa.sa_mask);
141
132
sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
143
135
sa.sa_handler= drizzled_handle_segfault;
144
136
sigaction(SIGSEGV, &sa, NULL);
145
137
sigaction(SIGABRT, &sa, NULL);
216
205
case google::protobuf::LOGLEVEL_ERROR:
217
206
case google::protobuf::LOGLEVEL_FATAL:
219
std::cerr << "GoogleProtoErrorThrower(" << filename << ", " << line << ", " << message << ")";
220
208
throw("error in google protocol buffer parsing");
234
222
module::Registry &modules= module::Registry::singleton();
235
223
plugin::Client *client;
237
226
MY_INIT(argv[0]); // init my_sys library & pthreads
238
227
/* nothing should come before this line ^^^ */
240
229
/* Set signal used to kill Drizzle */
231
thr_kill_signal= internal::thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
241
233
thr_kill_signal= SIGINT;
243
236
google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
245
/* 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))
238
if (init_common_variables(DRIZZLE_CONFIG_NAME,
239
argc, argv, load_default_groups))
250
240
unireg_abort(1); // Will do exit
254
After this we can't quit by a simple unireg_abort
259
245
select_thread=pthread_self();
260
246
select_thread_in_use=1;
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()= "../";
248
if (chdir(data_home_real) && !opt_help)
250
errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), data_home_real);
253
data_home= data_home_buff;
254
data_home[0]=FN_CURLIB; // all paths are relative from here
258
if ((user_info= check_user(drizzled_user)))
260
set_user(drizzled_user, user_info);
290
263
if (server_id == 0)
312
285
if (plugin::Listen::setup())
290
After this we can't quit by a simple unireg_abort
292
error_handler_hook= my_message_sql;
316
294
assert(plugin::num_trx_monitored_objects > 0);
317
295
if (drizzle_rm_tmp_tables() ||
330
308
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
311
/* Listen for new connections and start new session for each connection
350
312
accepted. The listen.getClient() method will return NULL when the server
351
313
should be shutdown. */
352
314
while ((client= plugin::Listen::getClient()) != NULL)
354
Session::shared_ptr session(new Session(client));
316
if (!(session= new Session(client)))
362
322
/* If we error on creation we drop the connection and delete the session. */
363
if (Session::schedule(session))
323
if (session->schedule())
364
324
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
384
COND_thread_count.notify_all();
327
/* (void) pthread_attr_destroy(&connection_attrib); */
330
(void) pthread_mutex_lock(&LOCK_thread_count);
331
select_thread_in_use=0; // For close_connections
332
(void) pthread_mutex_unlock(&LOCK_thread_count);
333
(void) pthread_cond_broadcast(&COND_thread_count);
386
335
/* 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);
336
(void) pthread_mutex_lock(&LOCK_thread_count);
337
while (!ready_to_exit)
338
pthread_cond_wait(&COND_server_end,&LOCK_thread_count);
339
(void) pthread_mutex_unlock(&LOCK_thread_count);
394
342
module::Registry::shutdown();
395
344
internal::my_end();