~stewart/drizzle/rename-embedded-innodb-to-haildb

« back to all changes in this revision

Viewing changes to drizzled/main.cc

  • Committer: Stewart Smith
  • Date: 2010-09-30 05:47:49 UTC
  • mfrom: (1787.3.15 drizzle)
  • Revision ID: stewart@flamingspork.com-20100930054749-s1szrpe6wm2z8532
merge trunk

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
 
26
29
 
27
30
#if TIME_WITH_SYS_TIME
28
31
# include <sys/time.h>
39
42
# include <locale.h>
40
43
#endif
41
44
 
 
45
#include <boost/filesystem.hpp>
42
46
 
43
47
#include "drizzled/plugin.h"
44
48
#include "drizzled/gettext.h"
58
62
 
59
63
using namespace drizzled;
60
64
using namespace std;
 
65
namespace fs=boost::filesystem;
61
66
 
62
67
static pthread_t select_thread;
63
68
static uint32_t thr_kill_signal;
64
69
 
 
70
 
65
71
/**
66
72
  All global error messages are sent here where the first one is stored
67
73
  for the client.
230
236
  google::protobuf::SetLogHandler(&GoogleProtoErrorThrower);
231
237
 
232
238
  /* Function generates error messages before abort */
 
239
  error_handler_hook= my_message_sql;
233
240
  /* init_common_variables must get basic settings such as data_home_dir
234
241
     and plugin_load_list. */
235
 
  if (init_common_variables(argc, argv))
 
242
  if (init_common_variables(argc, argv, modules))
236
243
    unireg_abort(1);                            // Will do exit
237
244
 
 
245
  /*
 
246
    init signals & alarm
 
247
    After this we can't quit by a simple unireg_abort
 
248
  */
238
249
  init_signals();
239
250
 
240
251
 
241
252
  select_thread=pthread_self();
242
253
  select_thread_in_use=1;
243
254
 
244
 
  if (chdir(data_home_real) && !opt_help)
 
255
  if (not opt_help)
245
256
  {
246
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), data_home_real);
247
 
    unireg_abort(1);
 
257
    if (chdir(getDataHome().c_str()))
 
258
    {
 
259
      errmsg_printf(ERRMSG_LVL_ERROR,
 
260
                    _("Data directory %s does not exist\n"),
 
261
                    getDataHome().c_str());
 
262
      unireg_abort(1);
 
263
    }
 
264
    if (mkdir("local", 0700))
 
265
    {
 
266
      /* We don't actually care */
 
267
    }
 
268
    if (chdir("local"))
 
269
    {
 
270
      errmsg_printf(ERRMSG_LVL_ERROR,
 
271
                    _("Local catalog %s/local does not exist\n"),
 
272
                    getDataHome().c_str());
 
273
      unireg_abort(1);
 
274
    }
 
275
    /* TODO: This is a hack until we can properly support std::string in sys_var*/
 
276
    char **data_home_ptr= getDatadirPtr();
 
277
    fs::path full_data_home_path(fs::system_complete(fs::path(getDataHome())));
 
278
    std::string full_data_home(full_data_home_path.file_string());
 
279
    *data_home_ptr= new char[full_data_home.size()+1] ();
 
280
    memcpy(*data_home_ptr, full_data_home.c_str(), full_data_home.size());
 
281
    getDataHomeCatalog()= "./";
 
282
    getDataHome()= "../";
248
283
  }
249
 
  data_home= data_home_buff;
250
 
  data_home[0]=FN_CURLIB;               // all paths are relative from here
251
 
  data_home[1]=0;
252
 
  data_home_len= 2;
 
284
 
 
285
 
253
286
 
254
287
  if (server_id == 0)
255
288
  {
276
309
  if (plugin::Listen::setup())
277
310
    unireg_abort(1);
278
311
 
279
 
  /*
280
 
    init signals & alarm
281
 
    After this we can't quit by a simple unireg_abort
282
 
  */
283
 
  error_handler_hook= my_message_sql;
284
312
 
285
313
  assert(plugin::num_trx_monitored_objects > 0);
286
314
  if (drizzle_rm_tmp_tables() ||
321
349
  COND_thread_count.notify_all();
322
350
 
323
351
  /* Wait until cleanup is done */
324
 
  LOCK_thread_count.lock();
325
 
  while (!ready_to_exit)
326
 
    pthread_cond_wait(COND_server_end.native_handle(), LOCK_thread_count.native_handle());
327
 
  LOCK_thread_count.unlock();
 
352
  {
 
353
    boost::mutex::scoped_lock scopedLock(LOCK_thread_count);
 
354
    while (!ready_to_exit)
 
355
      COND_server_end.wait(scopedLock);
 
356
  }
328
357
 
329
358
  clean_up(1);
330
359
  module::Registry::shutdown();
331
360
  internal::my_end();
 
361
 
332
362
  return 0;
333
363
}
334
364