~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

edit

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/configmake.h>
23
 
#include <drizzled/atomics.h>
24
 
#include <drizzled/data_home.h>
 
20
#include "config.h"
 
21
#include "drizzled/configmake.h"
 
22
#include "drizzled/atomics.h"
 
23
#include "drizzled/data_home.h"
25
24
 
26
25
#include <netdb.h>
27
26
#include <sys/types.h>
32
31
#include <stdexcept>
33
32
 
34
33
#include <boost/program_options.hpp>
35
 
#include <drizzled/program_options/config_file.h>
 
34
#include "drizzled/program_options/config_file.h"
36
35
#include <boost/thread/recursive_mutex.hpp>
37
36
#include <boost/thread/mutex.hpp>
38
37
#include <boost/thread/shared_mutex.hpp>
40
39
#include <boost/filesystem.hpp>
41
40
#include <boost/detail/atomic_count.hpp>
42
41
 
43
 
#include <drizzled/cached_directory.h>
44
 
#include <drizzled/charset.h>
45
 
#include <drizzled/data_home.h>
46
 
#include <drizzled/debug.h>
47
 
#include <drizzled/definition/cache.h>
48
 
#include <drizzled/drizzled.h>
 
42
#include "drizzled/internal/my_sys.h"
 
43
#include "drizzled/internal/my_bit.h"
 
44
#include <drizzled/my_hash.h>
 
45
#include <drizzled/error.h>
49
46
#include <drizzled/errmsg_print.h>
50
 
#include <drizzled/error.h>
51
 
#include <drizzled/global_buffer.h>
52
 
#include <drizzled/internal/my_bit.h>
53
 
#include <drizzled/internal/my_sys.h>
 
47
#include <drizzled/tztime.h>
 
48
#include <drizzled/sql_base.h>
 
49
#include <drizzled/show.h>
 
50
#include <drizzled/sql_parse.h>
54
51
#include <drizzled/item/cmpfunc.h>
 
52
#include <drizzled/session.h>
55
53
#include <drizzled/item/create.h>
56
 
#include <drizzled/message/cache.h>
57
 
#include <drizzled/module/load_list.h>
58
 
#include <drizzled/module/registry.h>
59
 
#include <drizzled/my_hash.h>
60
 
#include <drizzled/plugin/client.h>
61
 
#include <drizzled/plugin/error_message.h>
62
 
#include <drizzled/plugin/event_observer.h>
63
 
#include <drizzled/plugin/listen.h>
64
 
#include <drizzled/plugin/monitored_in_transaction.h>
65
 
#include <drizzled/plugin/scheduler.h>
66
 
#include <drizzled/plugin/storage_engine.h>
67
 
#include <drizzled/plugin/xa_resource_manager.h>
68
 
#include <drizzled/probes.h>
69
 
#include <drizzled/replication_services.h> /* For ReplicationServices::evaluateRegisteredPlugins() */
70
 
#include <drizzled/session.h>
71
 
#include <drizzled/session/cache.h>
72
 
#include <drizzled/show.h>
73
 
#include <drizzled/sql_base.h>
74
 
#include <drizzled/sql_parse.h>
75
 
#include <drizzled/temporal_format.h> /* For init_temporal_formats() */
76
 
#include <drizzled/tztime.h>
77
54
#include <drizzled/unireg.h>
78
 
#include <plugin/myisam/myisam.h>
79
 
#include <drizzled/typelib.h>
80
 
#include <drizzled/visibility.h>
 
55
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
 
56
#include "drizzled/plugin/listen.h"
 
57
#include "drizzled/plugin/error_message.h"
 
58
#include "drizzled/plugin/client.h"
 
59
#include "drizzled/plugin/scheduler.h"
 
60
#include "drizzled/plugin/xa_resource_manager.h"
 
61
#include "drizzled/plugin/monitored_in_transaction.h"
 
62
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
 
63
#include "drizzled/probes.h"
 
64
#include "drizzled/session/cache.h"
 
65
#include "drizzled/charset.h"
 
66
#include "plugin/myisam/myisam.h"
 
67
#include "drizzled/drizzled.h"
 
68
#include "drizzled/module/registry.h"
 
69
#include "drizzled/module/load_list.h"
 
70
#include "drizzled/global_buffer.h"
 
71
 
 
72
#include "drizzled/definition/cache.h"
 
73
 
 
74
#include "drizzled/plugin/event_observer.h"
 
75
 
 
76
#include "drizzled/message/cache.h"
81
77
 
82
78
#include <google/protobuf/stubs/common.h>
83
79
 
84
 
#include <drizzled/refresh_version.h>
85
 
 
86
80
#if TIME_WITH_SYS_TIME
87
81
# include <sys/time.h>
88
82
# include <time.h>
102
96
 
103
97
#include <errno.h>
104
98
#include <sys/stat.h>
105
 
#include <drizzled/option.h>
 
99
#include "drizzled/option.h"
106
100
#ifdef HAVE_SYSENT_H
107
101
#include <sysent.h>
108
102
#endif
136
130
#include <sys/fpu.h>
137
131
#endif
138
132
 
139
 
#include <drizzled/internal/my_pthread.h>                       // For thr_setconcurency()
140
 
#include <drizzled/constrained_value.h>
 
133
#include "drizzled/internal/my_pthread.h"                       // For thr_setconcurency()
 
134
#include "drizzled/constrained_value.h"
141
135
 
142
136
#include <drizzled/gettext.h>
143
137
 
158
152
namespace po=boost::program_options;
159
153
namespace dpo=drizzled::program_options;
160
154
 
161
 
bool opt_daemon= false;
162
155
 
163
156
namespace drizzled
164
157
{
234
227
 
235
228
/* Global variables */
236
229
 
 
230
bool volatile ready_to_exit;
237
231
char *drizzled_user;
238
232
bool volatile select_thread_in_use;
239
233
bool volatile abort_loop;
240
 
DRIZZLED_API bool volatile shutdown_in_progress;
 
234
bool volatile shutdown_in_progress;
241
235
char *opt_scheduler_default;
242
236
const char *opt_scheduler= NULL;
243
237
 
244
 
DRIZZLED_API size_t my_thread_stack_size= 0;
 
238
size_t my_thread_stack_size= 0;
245
239
 
246
240
/*
247
241
  Legacy global plugin::StorageEngine. These will be removed (please do not add more).
252
246
bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
253
247
 
254
248
uint32_t drizzled_bind_timeout;
 
249
std::bitset<12> test_flags;
255
250
uint32_t dropping_tables, ha_open_options;
256
251
uint32_t tc_heuristic_recover= 0;
257
252
uint64_t session_startup_options;
258
253
back_log_constraints back_log(50);
259
 
DRIZZLED_API uint32_t server_id;
 
254
uint32_t server_id;
260
255
uint64_t table_cache_size;
261
256
size_t table_def_size;
262
257
uint32_t global_thread_id= 1UL;
308
303
fs::path system_config_dir(SYSCONFDIR);
309
304
 
310
305
 
 
306
char system_time_zone[30];
 
307
char *default_tz_name;
 
308
char glob_hostname[FN_REFLEN];
 
309
 
311
310
char *opt_tc_log_file;
312
311
const key_map key_map_empty(0);
313
312
key_map key_map_full(0);                        // Will be initialized later
321
320
const char *in_additional_cond= "<IN COND>";
322
321
const char *in_having_cond= "<IN HAVING>";
323
322
 
 
323
type::Decimal decimal_zero;
324
324
/* classes for comparation parsing/processing */
325
325
 
326
326
FILE *stderror_file=0;
327
327
 
328
 
drizzle_system_variables global_system_variables;
329
 
drizzle_system_variables max_system_variables;
330
 
global_counters current_global_counters;
 
328
struct drizzle_system_variables global_system_variables;
 
329
struct drizzle_system_variables max_system_variables;
 
330
struct global_counters current_global_counters;
331
331
 
332
 
DRIZZLED_API const CHARSET_INFO *system_charset_info;
333
 
const CHARSET_INFO *files_charset_info;
 
332
const CHARSET_INFO *system_charset_info, *files_charset_info ;
334
333
const CHARSET_INFO *table_alias_charset;
335
334
const CHARSET_INFO *character_set_filesystem;
336
335
 
338
337
 
339
338
SHOW_COMP_OPTION have_symlink;
340
339
 
 
340
/* Thread specific variables */
 
341
boost::mutex LOCK_global_system_variables;
 
342
 
341
343
boost::condition_variable_any COND_refresh;
342
344
boost::condition_variable COND_thread_count;
343
345
pthread_t signal_thread;
 
346
boost::condition_variable COND_server_end;
344
347
 
345
348
/* Static variables */
346
349
 
355
358
global_buffer_constraint<uint64_t> global_read_rnd_buffer(0);
356
359
global_buffer_constraint<uint64_t> global_read_buffer(0);
357
360
 
358
 
DRIZZLED_API size_t transaction_message_threshold;
 
361
/** 
 
362
  Refresh value. We use to test this to find out if a refresh even has happened recently.
 
363
*/
 
364
uint64_t refresh_version;  /* Increments on each reload */
 
365
 
 
366
/* Function declarations */
 
367
bool drizzle_rm_tmp_tables();
359
368
 
360
369
static void drizzle_init_variables(void);
361
370
static void get_options();
366
375
 
367
376
fs::path base_plugin_dir(PKGPLUGINDIR);
368
377
 
369
 
po::options_description config_options(_("Config File Options"));
370
 
po::options_description long_options(_("Kernel Options"));
371
 
po::options_description plugin_load_options(_("Plugin Loading Options"));
372
 
po::options_description plugin_options(_("Plugin Options"));
373
 
po::options_description initial_options(_("Config and Plugin Loading"));
374
 
po::options_description full_options(_("Kernel and Plugin Loading and Plugin"));
 
378
po::options_description config_options("Config File Options");
 
379
po::options_description long_options("Kernel Options");
 
380
po::options_description plugin_load_options("Plugin Loading Options");
 
381
po::options_description plugin_options("Plugin Options");
 
382
po::options_description initial_options("Config and Plugin Loading");
 
383
po::options_description full_options("Kernel and Plugin Loading and Plugin");
375
384
vector<string> unknown_options;
376
385
vector<string> defaults_file_list;
377
386
po::variables_map vm;
378
387
 
 
388
fs::path data_home(LOCALSTATEDIR);
 
389
fs::path full_data_home(LOCALSTATEDIR);
 
390
 
379
391
po::variables_map &getVariablesMap()
380
392
{
381
393
  return vm;
382
394
}
383
395
 
384
 
namespace
385
 
{
386
 
 
387
 
std::string &getGlobHostname()
388
 
{
389
 
  static std::string glob_hostname("localhost");
390
 
  return glob_hostname;
391
 
}
392
 
 
393
 
void setServerHostname(const std::string &hostname)
394
 
{
395
 
  getGlobHostname()= hostname;
396
 
}
397
 
}
398
 
 
399
 
const std::string &getServerHostname()
400
 
{
401
 
  return getGlobHostname();
402
 
}
403
 
 
 
396
fs::path& getFullDataHome()
 
397
{
 
398
  return full_data_home;
 
399
}
 
400
 
 
401
fs::path& getDataHome()
 
402
{
 
403
  return data_home;
 
404
}
 
405
 
 
406
fs::path& getDataHomeCatalog()
 
407
{
 
408
  static fs::path data_home_catalog(getDataHome());
 
409
  return data_home_catalog;
 
410
}
 
411
 
 
412
 
404
413
/****************************************************************************
405
414
** Code to end drizzled
406
415
****************************************************************************/
479
488
{
480
489
 
481
490
  if (exit_code)
482
 
  {
483
 
    errmsg_printf(error::ERROR, _("Aborting"));
484
 
  }
 
491
    errmsg_printf(ERRMSG_LVL_ERROR, _("Aborting\n"));
485
492
  else if (opt_help)
486
 
  {
487
493
    usage();
488
 
  }
489
 
 
490
494
  clean_up(!opt_help && (exit_code));
491
495
  internal::my_end();
492
496
  exit(exit_code);
513
517
  (void) unlink(pid_file.file_string().c_str());        // This may not always exist
514
518
 
515
519
  if (print_message && server_start_time)
516
 
    errmsg_printf(drizzled::error::INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
 
520
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
 
521
  {
 
522
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
523
    ready_to_exit= true;
517
524
 
518
 
  session::Cache::singleton().shutdownFirst();
 
525
    /* do the broadcast inside the lock to ensure that my_end() is not called */
 
526
    COND_server_end.notify_all();
 
527
  }
519
528
 
520
529
  /*
521
530
    The following lines may never be executed as the main thread may have
540
549
      tmp_user_info= getpwnam(user);
541
550
      if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
542
551
          global_system_variables.log_warnings)
543
 
            errmsg_printf(error::WARN, _("One can only use the --user switch "
 
552
            errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
544
553
                            "if running as root\n"));
545
554
    }
546
555
    return NULL;
547
556
  }
548
557
  if (not user)
549
558
  {
550
 
      errmsg_printf(error::ERROR, _("Fatal error: Please read \"Security\" section of "
551
 
                                    "the manual to find out how to run drizzled as root"));
 
559
      errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
 
560
                      "the manual to find out how to run drizzled as root!\n"));
552
561
    unireg_abort(1);
553
562
  }
554
 
 
555
 
  if (not strcmp(user, "root"))
 
563
  if (!strcmp(user,"root"))
556
564
    return NULL;                        // Avoid problem with dynamic libraries
557
565
 
558
566
  if (!(tmp_user_info= getpwnam(user)))
568
576
  return tmp_user_info;
569
577
 
570
578
err:
571
 
  errmsg_printf(error::ERROR, _("Fatal error: Can't change to run as user '%s' ;  "
 
579
  errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Can't change to run as user '%s' ;  "
572
580
                    "Please check that the user exists!\n"),user);
573
581
  unireg_abort(1);
574
582
 
575
583
#ifdef PR_SET_DUMPABLE
576
 
  if (getDebug().test(debug::CORE_ON_SIGNAL))
 
584
  if (test_flags.test(TEST_CORE_ON_SIGNAL))
577
585
  {
578
586
    /* inform kernel that process is dumpable */
579
587
    (void) prctl(PR_SET_DUMPABLE, 1);
665
673
 
666
674
static void find_plugin_dir(string progname)
667
675
{
668
 
  fs::path full_progname(fs::system_complete(progname));
669
 
 
670
 
  fs::path progdir(full_progname.parent_path());
671
 
  if (progdir.filename() == ".libs")
672
 
  {
673
 
    progdir= progdir.parent_path();
674
 
  }
675
 
 
676
 
  if (fs::exists(progdir / "drizzled.lo") || fs::exists(progdir / "drizzled.o"))
 
676
  if (progname[0] != FN_LIBCHAR)
 
677
  {
 
678
    /* We have a relative path and need to find the absolute */
 
679
    char working_dir[FN_REFLEN];
 
680
    char *working_dir_ptr= working_dir;
 
681
    working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
 
682
    string new_path(working_dir);
 
683
    if (*(new_path.end()-1) != '/')
 
684
      new_path.push_back('/');
 
685
    if (progname[0] == '.' && progname[1] == '/')
 
686
      new_path.append(progname.substr(2));
 
687
    else
 
688
      new_path.append(progname);
 
689
    progname.swap(new_path);
 
690
  }
 
691
 
 
692
  /* Now, trim off the exe name */
 
693
  string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
 
694
  if (progdir.rfind(".libs/") != string::npos)
 
695
  {
 
696
    progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
 
697
  }
 
698
  string testlofile(progdir);
 
699
  testlofile.append("drizzled.lo");
 
700
  string testofile(progdir);
 
701
  testofile.append("drizzled.o");
 
702
  struct stat testfile_stat;
 
703
  if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
677
704
  {
678
705
    /* We are in a source dir! Plugin dir is ../plugin/.libs */
679
 
    base_plugin_dir= progdir.parent_path();
 
706
    size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
 
707
    base_plugin_dir= progdir.substr(0,last_libchar_pos);
680
708
    base_plugin_dir /= "plugin";
681
709
    base_plugin_dir /= ".libs";
682
710
  }
1006
1034
 
1007
1035
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1008
1036
{
1009
 
  transaction_message_threshold= 1024*1024;
 
1037
  global_system_variables.transaction_message_threshold= 1024*1024;
1010
1038
  if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1011
1039
  {
1012
1040
    cout << _("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1013
1041
    exit(-1);
1014
1042
  }
1015
 
  transaction_message_threshold= in_transaction_message_threshold;
 
1043
  global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
1016
1044
}
1017
1045
 
1018
1046
static void process_defaults_files()
1066
1094
      defaults_file_list.push_back(*it);
1067
1095
    else
1068
1096
    {
1069
 
      errmsg_printf(error::ERROR,
 
1097
      errmsg_printf(ERRMSG_LVL_ERROR,
1070
1098
                  _("Defaults file '%s' not found\n"), (*it).c_str());
1071
1099
      unireg_abort(1);
1072
1100
    }
1074
1102
  }
1075
1103
}
1076
1104
 
1077
 
int init_basic_variables(int argc, char **argv)
 
1105
int init_common_variables(int argc, char **argv, module::Registry &plugins)
1078
1106
{
1079
1107
  time_t curr_time;
1080
1108
  umask(((~internal::my_umask) & 0666));
1091
1119
  drizzle_init_variables();
1092
1120
 
1093
1121
  find_plugin_dir(argv[0]);
 
1122
  {
 
1123
    struct tm tm_tmp;
 
1124
    localtime_r(&server_start_time,&tm_tmp);
 
1125
    strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
 
1126
            sizeof(system_time_zone)-1);
1094
1127
 
 
1128
  }
1095
1129
  /*
1096
1130
    We set SYSTEM time zone as reasonable default and
1097
1131
    also for failure of my_tz_init() and bootstrap mode.
1100
1134
  */
1101
1135
  global_system_variables.time_zone= my_tz_SYSTEM;
1102
1136
 
1103
 
  char ret_hostname[FN_REFLEN];
1104
 
  if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
 
1137
  if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1105
1138
  {
1106
 
    errmsg_printf(error::WARN,
1107
 
                  _("gethostname failed, using '%s' as hostname"),
1108
 
                  getServerHostname().c_str());
 
1139
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
 
1140
    errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
 
1141
                  glob_hostname);
1109
1142
    pid_file= "drizzle";
1110
1143
  }
1111
1144
  else
1112
1145
  {
1113
 
    setServerHostname(ret_hostname);
1114
 
    pid_file= getServerHostname();
 
1146
    pid_file= glob_hostname;
1115
1147
  }
1116
1148
  pid_file.replace_extension(".pid");
1117
1149
 
1120
1152
  config_options.add_options()
1121
1153
  ("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1122
1154
  _("Display this help and exit."))
1123
 
  ("daemon,d", po::value<bool>(&opt_daemon)->default_value(false)->zero_tokens(),
1124
 
  _("Run as a daemon."))
1125
1155
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1126
1156
  _("Configuration file defaults are not used if no-defaults is set"))
1127
1157
  ("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1162
1192
  ("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1163
1193
  _("Default completion type."))
1164
1194
  ("core-file",  _("Write core on errors."))
1165
 
  ("datadir", po::value<fs::path>(&getDataHome()),
 
1195
  ("datadir", po::value<fs::path>(&data_home),
1166
1196
  _("Path to the database root."))
1167
1197
  ("default-storage-engine", po::value<string>(),
1168
1198
  _("Set the default storage engine for tables."))
1199
1229
  _("Path for temporary files."))
1200
1230
  ("transaction-isolation", po::value<string>(),
1201
1231
  _("Default transaction isolation level."))
1202
 
  ("transaction-message-threshold", po::value<size_t>(&transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
 
1232
  ("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1203
1233
  _("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1204
1234
  ("user,u", po::value<string>(),
1205
1235
  _("Run drizzled daemon as user."))  
1305
1335
  po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1306
1336
  _("If an internal in-memory temporary table exceeds this size, Drizzle will"
1307
1337
     " automatically convert it to an on-disk MyISAM table."))
1308
 
  ("verbose", po::value<std::string>()->default_value(error::verbose_string())->notifier(&error::check_verbosity),
1309
 
  _("The stack size for each thread."))
1310
1338
  ;
1311
1339
 
1312
1340
  full_options.add(long_options);
1328
1356
  }
1329
1357
  catch (std::exception&)
1330
1358
  {
1331
 
    errmsg_printf(error::ERROR, _("Duplicate entry for command line option\n"));
 
1359
    errmsg_printf(ERRMSG_LVL_ERROR, _("Duplicate entry for command line option\n"));
1332
1360
    unireg_abort(1);
1333
1361
  }
1334
1362
 
1374
1402
  }
1375
1403
  catch (po::validation_error &err)
1376
1404
  {
1377
 
    errmsg_printf(error::ERROR,  
 
1405
    errmsg_printf(ERRMSG_LVL_ERROR,  
1378
1406
                  _("%s: %s.\n"
1379
1407
                    "Use --help to get a list of available options\n"),
1380
1408
                  internal::my_progname, err.what());
1392
1420
  }
1393
1421
  catch (po::validation_error &err)
1394
1422
  {
1395
 
    errmsg_printf(error::ERROR,
 
1423
    errmsg_printf(ERRMSG_LVL_ERROR,
1396
1424
                  _("%s: %s.\n"
1397
1425
                    "Use --help to get a list of available options\n"),
1398
1426
                  internal::my_progname, err.what());
1399
1427
    unireg_abort(1);
1400
1428
  }
1401
1429
 
1402
 
  return 0;
1403
 
}
1404
 
 
1405
 
int init_remaining_variables(module::Registry &plugins)
1406
 
{
1407
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1408
 
 
1409
 
  current_pid= getpid();                /* Save for later ref */
1410
 
 
1411
1430
  /* At this point, we've read all the options we need to read from files and
1412
1431
     collected most of them into unknown options - now let's load everything
1413
1432
  */
1414
1433
 
1415
1434
  if (plugin_init(plugins, plugin_options))
1416
1435
  {
1417
 
    errmsg_printf(error::ERROR, _("Failed to initialize plugins\n"));
 
1436
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1418
1437
    unireg_abort(1);
1419
1438
  }
1420
1439
 
1435
1454
  }
1436
1455
  catch (po::validation_error &err)
1437
1456
  {
1438
 
    errmsg_printf(error::ERROR,
 
1457
    errmsg_printf(ERRMSG_LVL_ERROR,
1439
1458
                  _("%s: %s.\n"
1440
1459
                    "Use --help to get a list of available options\n"),
1441
1460
                  internal::my_progname, err.what());
1443
1462
  }
1444
1463
  catch (po::invalid_command_line_syntax &err)
1445
1464
  {
1446
 
    errmsg_printf(error::ERROR,
 
1465
    errmsg_printf(ERRMSG_LVL_ERROR,
1447
1466
                  _("%s: %s.\n"
1448
1467
                    "Use --help to get a list of available options\n"),
1449
1468
                  internal::my_progname, err.what());
1451
1470
  }
1452
1471
  catch (po::unknown_option &err)
1453
1472
  {
1454
 
    errmsg_printf(error::ERROR,
 
1473
    errmsg_printf(ERRMSG_LVL_ERROR,
1455
1474
                  _("%s\nUse --help to get a list of available options\n"),
1456
1475
                  err.what());
1457
1476
    unireg_abort(1);
1463
1482
  }
1464
1483
  catch (po::validation_error &err)
1465
1484
  {
1466
 
    errmsg_printf(error::ERROR,  
 
1485
    errmsg_printf(ERRMSG_LVL_ERROR,  
1467
1486
                  _("%s: %s.\n"
1468
1487
                    "Use --help to get a list of available options\n"),
1469
1488
                  internal::my_progname, err.what());
1487
1506
 
1488
1507
  fix_paths();
1489
1508
 
 
1509
  current_pid= getpid();                /* Save for later ref */
1490
1510
  init_time();                          /* Init time-functions (read zone) */
1491
1511
 
1492
1512
  if (item_create_init())
1500
1520
  if (!(default_charset_info=
1501
1521
        get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
1502
1522
  {
1503
 
    errmsg_printf(error::ERROR, _("Error getting default charset"));
 
1523
    errmsg_printf(ERRMSG_LVL_ERROR, _("Error getting default charset"));
1504
1524
    return 1;                           // Eof of the list
1505
1525
  }
1506
1526
 
1512
1532
    const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1513
1533
    if (not default_collation)
1514
1534
    {
1515
 
      errmsg_printf(error::ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
 
1535
      errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1516
1536
      return 1;
1517
1537
    }
1518
1538
    if (not my_charset_same(default_charset_info, default_collation))
1519
1539
    {
1520
 
      errmsg_printf(error::ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
 
1540
      errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1521
1541
                    default_collation_name,
1522
1542
                    default_charset_info->csname);
1523
1543
      return 1;
1530
1550
  if (not (character_set_filesystem=
1531
1551
           get_charset_by_csname(character_set_filesystem_name, MY_CS_PRIMARY)))
1532
1552
  {
1533
 
    errmsg_printf(error::ERROR, _("Error setting collation"));
 
1553
    errmsg_printf(ERRMSG_LVL_ERROR, _("Error setting collation"));
1534
1554
    return 1;
1535
1555
  }
1536
1556
  global_system_variables.character_set_filesystem= character_set_filesystem;
1538
1558
  if (!(my_default_lc_time_names=
1539
1559
        my_locale_by_name(lc_time_names_name)))
1540
1560
  {
1541
 
    errmsg_printf(error::ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
 
1561
    errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
1542
1562
    return 1;
1543
1563
  }
1544
1564
  global_system_variables.lc_time_names= my_default_lc_time_names;
1558
1578
  */
1559
1579
  if (table_cache_init())
1560
1580
  {
1561
 
    errmsg_printf(error::ERROR, _("Could not initialize table cache\n"));
 
1581
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not initialize table cache\n"));
1562
1582
    unireg_abort(1);
1563
1583
  }
1564
1584
 
1573
1593
 
1574
1594
  if (xid_cache_init())
1575
1595
  {
1576
 
    errmsg_printf(error::ERROR, _("XA cache initialization failed: Out of memory\n"));
 
1596
    errmsg_printf(ERRMSG_LVL_ERROR, _("XA cache initialization failed: Out of memory\n"));
1577
1597
    unireg_abort(1);
1578
1598
  }
1579
1599
 
1602
1622
 
1603
1623
  if (plugin::Scheduler::setPlugin(scheduler_name))
1604
1624
  {
1605
 
      errmsg_printf(error::ERROR,
 
1625
      errmsg_printf(ERRMSG_LVL_ERROR,
1606
1626
                   _("No scheduler found, cannot continue!\n"));
1607
1627
      unireg_abort(1);
1608
1628
  }
1627
1647
    engine= plugin::StorageEngine::findByName(name);
1628
1648
    if (engine == NULL)
1629
1649
    {
1630
 
      errmsg_printf(error::ERROR, _("Unknown/unsupported storage engine: %s\n"),
 
1650
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown/unsupported storage engine: %s\n"),
1631
1651
                    default_storage_engine_str);
1632
1652
      unireg_abort(1);
1633
1653
    }
1721
1741
  {"help", '?', N_("Display this help and exit."),
1722
1742
   (char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1723
1743
   0, 0},
1724
 
  {"daemon", 'd', N_("Run as daemon."),
1725
 
   (char**) &opt_daemon, (char**) &opt_daemon, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1726
 
   0, 0},
1727
1744
  {"auto-increment-increment", OPT_AUTO_INCREMENT,
1728
1745
   N_("Auto-increment columns are incremented by this"),
1729
1746
   (char**) &global_system_variables.auto_increment_increment,
2061
2078
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
2062
2079
  cleanup_done= 0;
2063
2080
  dropping_tables= ha_open_options=0;
2064
 
  getDebug().reset();
 
2081
  test_flags.reset();
2065
2082
  wake_thread=0;
2066
2083
  abort_loop= select_thread_in_use= false;
2067
 
  shutdown_in_progress= 0;
 
2084
  ready_to_exit= shutdown_in_progress= 0;
2068
2085
  drizzled_user= drizzled_chroot= 0;
2069
2086
  memset(&current_global_counters, 0, sizeof(current_global_counters));
2070
2087
  key_map_full.set();
2149
2166
      drizzled_user= (char *)vm["user"].as<string>().c_str();
2150
2167
 
2151
2168
    else
2152
 
      errmsg_printf(error::WARN, _("Ignoring user change to '%s' because the user was "
 
2169
      errmsg_printf(ERRMSG_LVL_WARN, _("Ignoring user change to '%s' because the user was "
2153
2170
                                       "set to '%s' earlier on the command line\n"),
2154
2171
                    vm["user"].as<string>().c_str(), drizzled_user);
2155
2172
  }
2216
2233
  {
2217
2234
    if (vm["exit-info"].as<long>())
2218
2235
    {
2219
 
      getDebug().set((uint32_t) vm["exit-info"].as<long>());
 
2236
      test_flags.set((uint32_t) vm["exit-info"].as<long>());
2220
2237
    }
2221
2238
  }
2222
2239
 
2223
2240
  if (vm.count("want-core"))
2224
2241
  {
2225
 
    getDebug().set(debug::CORE_ON_SIGNAL);
 
2242
    test_flags.set(TEST_CORE_ON_SIGNAL);
2226
2243
  }
2227
2244
 
2228
2245
  if (vm.count("skip-stack-trace"))
2229
2246
  {
2230
 
    getDebug().set(debug::NO_STACKTRACE);
 
2247
    test_flags.set(TEST_NO_STACKTRACE);
2231
2248
  }
2232
2249
 
2233
2250
  if (vm.count("skip-symlinks"))
2237
2254
 
2238
2255
  if (vm.count("transaction-isolation"))
2239
2256
  {
2240
 
    int type= tx_isolation_typelib.find_type_or_exit(vm["transaction-isolation"].as<string>().c_str(), "transaction-isolation");
2241
 
    global_system_variables.tx_isolation= type - 1;
 
2257
    int type;
 
2258
    type= find_type_or_exit((char *)vm["transaction-isolation"].as<string>().c_str(), &tx_isolation_typelib, "transaction-isolation");
 
2259
    global_system_variables.tx_isolation= (type-1);
2242
2260
  }
2243
2261
 
2244
2262
  /* @TODO Make this all strings */
2265
2283
  if (opt_debugging)
2266
2284
  {
2267
2285
    /* Allow break with SIGINT, no core or stack trace */
2268
 
    getDebug().set(debug::ALLOW_SIGINT);
2269
 
    getDebug().set(debug::NO_STACKTRACE);
2270
 
    getDebug().reset(debug::CORE_ON_SIGNAL);
 
2286
    test_flags.set(TEST_SIGINT);
 
2287
    test_flags.set(TEST_NO_STACKTRACE);
 
2288
    test_flags.reset(TEST_CORE_ON_SIGNAL);
2271
2289
  }
2272
2290
 
2273
2291
  if (drizzled_chroot)
2319
2337
    {
2320
2338
      if (errno != EEXIST)
2321
2339
      {
2322
 
        errmsg_printf(error::ERROR, _("There was an error creating the '%s' part of the path '%s'.  Please check the path exists and is writable.\n"), fs::path(drizzle_tmpdir).leaf().c_str(), drizzle_tmpdir.c_str());
 
2340
        perror(drizzle_tmpdir.c_str());
2323
2341
        exit(1);
2324
2342
      }
2325
2343
    }
2326
2344
 
2327
2345
    if (stat(drizzle_tmpdir.c_str(), &buf) || (S_ISDIR(buf.st_mode) == false))
2328
2346
    {
2329
 
      errmsg_printf(error::ERROR, _("There was an error opening the path '%s', please check the path exists and is writable.\n"), drizzle_tmpdir.c_str());
 
2347
      perror(drizzle_tmpdir.c_str());
2330
2348
      exit(1);
2331
2349
    }
2332
2350
  }