~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/main.cc

  • Committer: Brian Aker
  • Date: 2010-08-03 19:24:14 UTC
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: brian@gaz-20100803192414-jk20j0u6cnze3ja6
Do comparison via non-case.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <signal.h>
24
24
#include <sys/resource.h>
25
25
#include <unistd.h>
26
 
#include <sys/stat.h>
27
 
#include <sys/types.h>
28
 
 
29
26
 
30
27
#if TIME_WITH_SYS_TIME
31
28
# include <sys/time.h>
42
39
# include <locale.h>
43
40
#endif
44
41
 
45
 
#include <boost/filesystem.hpp>
46
42
 
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"
64
 
 
65
 
#include "drizzled/util/backtrace.h"
66
59
 
67
60
using namespace drizzled;
68
61
using namespace std;
69
 
namespace fs=boost::filesystem;
70
62
 
71
63
static pthread_t select_thread;
72
64
static uint32_t thr_kill_signal;
73
65
 
74
 
 
75
66
/**
76
67
  All global error messages are sent here where the first one is stored
77
68
  for the client.
140
131
    sigemptyset(&sa.sa_mask);
141
132
    sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
142
133
 
 
134
    init_stacktrace();
143
135
    sa.sa_handler= drizzled_handle_segfault;
144
136
    sigaction(SIGSEGV, &sa, NULL);
145
137
    sigaction(SIGABRT, &sa, NULL);
205
197
  (void)filename;
206
198
  (void)line;
207
199
  (void)message;
208
 
  std::cerr << "\n";
209
 
  drizzled::util::custom_backtrace();
210
 
  std::cerr << "\n";
211
200
  switch(level)
212
201
  {
213
202
  case google::protobuf::LOGLEVEL_INFO:
216
205
  case google::protobuf::LOGLEVEL_ERROR:
217
206
  case google::protobuf::LOGLEVEL_FATAL:
218
207
  default:
219
 
    std::cerr << "GoogleProtoErrorThrower(" << filename << ", " << line << ", " << message << ")";
220
208
    throw("error in google protocol buffer parsing");
221
209
  }
222
210
}
233
221
 
234
222
  module::Registry &modules= module::Registry::singleton();
235
223
  plugin::Client *client;
 
224
  Session *session;
236
225
 
237
226
  MY_INIT(argv[0]);             // init my_sys library & pthreads
238
227
  /* nothing should come before this line ^^^ */
239
228
 
240
229
  /* Set signal used to kill Drizzle */
 
230
#if defined(SIGUSR2)
 
231
  thr_kill_signal= internal::thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
 
232
#else
241
233
  thr_kill_signal= SIGINT;
 
234
#endif
242
235
 
243
236
  google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
244
237
 
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
251
241
 
252
 
  /*
253
 
    init signals & alarm
254
 
    After this we can't quit by a simple unireg_abort
255
 
  */
256
242
  init_signals();
257
243
 
258
244
 
259
245
  select_thread=pthread_self();
260
246
  select_thread_in_use=1;
261
247
 
262
 
  if (not opt_help)
263
 
  {
264
 
    if (chdir(getDataHome().file_string().c_str()))
265
 
    {
266
 
      errmsg_printf(ERRMSG_LVL_ERROR,
267
 
                    _("Data directory %s does not exist\n"),
268
 
                    getDataHome().file_string().c_str());
269
 
      unireg_abort(1);
270
 
    }
271
 
    if (mkdir("local", 0700))
272
 
    {
273
 
      /* We don't actually care */
274
 
    }
275
 
    if (chdir("local"))
276
 
    {
277
 
      errmsg_printf(ERRMSG_LVL_ERROR,
278
 
                    _("Local catalog %s/local does not exist\n"),
279
 
                    getDataHome().file_string().c_str());
280
 
      unireg_abort(1);
281
 
    }
282
 
 
283
 
    full_data_home= fs::system_complete(getDataHome());
284
 
    getDataHomeCatalog()= "./";
285
 
    getDataHome()= "../";
286
 
  }
287
 
 
288
 
 
 
248
  if (chdir(data_home_real) && !opt_help)
 
249
  {
 
250
    errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), data_home_real);
 
251
    unireg_abort(1);
 
252
  }
 
253
  data_home= data_home_buff;
 
254
  data_home[0]=FN_CURLIB;               // all paths are relative from here
 
255
  data_home[1]=0;
 
256
  data_home_len= 2;
 
257
 
 
258
  if ((user_info= check_user(drizzled_user)))
 
259
  {
 
260
    set_user(drizzled_user, user_info);
 
261
  }
289
262
 
290
263
  if (server_id == 0)
291
264
  {
312
285
  if (plugin::Listen::setup())
313
286
    unireg_abort(1);
314
287
 
 
288
  /*
 
289
    init signals & alarm
 
290
    After this we can't quit by a simple unireg_abort
 
291
  */
 
292
  error_handler_hook= my_message_sql;
315
293
 
316
294
  assert(plugin::num_trx_monitored_objects > 0);
317
295
  if (drizzle_rm_tmp_tables() ||
321
299
    select_thread_in_use=0;
322
300
    (void) pthread_kill(signal_thread, SIGTERM);
323
301
 
324
 
    (void) unlink(pid_file.file_string().c_str());      // Not needed anymore
 
302
    (void) unlink(pidfile_name);        // Not needed anymore
325
303
 
326
304
    exit(1);
327
305
  }
330
308
                PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
331
309
 
332
310
 
333
 
  TransactionServices &transaction_services= TransactionServices::singleton();
334
 
 
335
 
  /* Send server startup event */
336
 
  {
337
 
    Session *session;
338
 
 
339
 
    if ((session= new Session(plugin::Listen::getNullClient())))
340
 
    {
341
 
      currentSession().release();
342
 
      currentSession().reset(session);
343
 
      transaction_services.sendStartupEvent(session);
344
 
      delete session;
345
 
    }
346
 
  }
347
 
 
348
 
 
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)
353
315
  {
354
 
    Session::shared_ptr session(new Session(client));
355
 
 
356
 
    if (not session)
 
316
    if (!(session= new Session(client)))
357
317
    {
358
318
      delete client;
359
319
      continue;
360
320
    }
361
321
 
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);
365
325
  }
366
326
 
367
 
  /* Send server shutdown event */
368
 
  {
369
 
    Session *session;
370
 
 
371
 
    if ((session= new Session(plugin::Listen::getNullClient())))
372
 
    {
373
 
      currentSession().release();
374
 
      currentSession().reset(session);
375
 
      transaction_services.sendShutdownEvent(session);
376
 
      delete session;
377
 
    }
378
 
  }
379
 
 
380
 
  {
381
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
382
 
    select_thread_in_use= false;                        // For close_connections
383
 
  }
384
 
  COND_thread_count.notify_all();
 
327
  /* (void) pthread_attr_destroy(&connection_attrib); */
 
328
 
 
329
 
 
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);
385
334
 
386
335
  /* Wait until cleanup is done */
387
 
  {
388
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
389
 
    while (not ready_to_exit)
390
 
      COND_server_end.wait(scopedLock);
391
 
  }
 
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);
392
340
 
393
341
  clean_up(1);
394
342
  module::Registry::shutdown();
 
343
  clean_up_mutexes();
395
344
  internal::my_end();
396
 
 
397
345
  return 0;
398
346
}
399
347