~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-26 17:58:17 UTC
  • mto: (1795.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1796.
  • Revision ID: andrew@linuxjedi.co.uk-20100926175817-3pwsapakdfte1izu
Fix spelling mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include "config.h"
21
 
#include "drizzled/configmake.h"
22
 
#include "drizzled/atomics.h"
23
 
#include "drizzled/data_home.h"
 
21
#include <drizzled/configmake.h>
 
22
#include <drizzled/atomics.h>
24
23
 
25
24
#include <netdb.h>
26
25
#include <sys/types.h>
31
30
#include <stdexcept>
32
31
 
33
32
#include <boost/program_options.hpp>
34
 
#include "drizzled/program_options/config_file.h"
35
33
#include <boost/thread/recursive_mutex.hpp>
36
34
#include <boost/thread/mutex.hpp>
37
 
#include <boost/thread/shared_mutex.hpp>
38
35
#include <boost/thread/condition_variable.hpp>
39
 
#include <boost/filesystem.hpp>
40
36
 
41
37
#include "drizzled/internal/my_sys.h"
42
38
#include "drizzled/internal/my_bit.h"
60
56
#include "drizzled/plugin/monitored_in_transaction.h"
61
57
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
62
58
#include "drizzled/probes.h"
63
 
#include "drizzled/session/cache.h"
 
59
#include "drizzled/session_list.h"
64
60
#include "drizzled/charset.h"
65
61
#include "plugin/myisam/myisam.h"
66
62
#include "drizzled/drizzled.h"
67
63
#include "drizzled/module/registry.h"
68
64
#include "drizzled/module/load_list.h"
69
 
#include "drizzled/global_buffer.h"
70
 
 
71
 
#include "drizzled/definition/cache.h"
72
 
 
73
 
#include "drizzled/plugin/event_observer.h"
74
 
 
75
 
#include "drizzled/message/cache.h"
76
65
 
77
66
#include <google/protobuf/stubs/common.h>
78
67
 
130
119
#endif
131
120
 
132
121
#include "drizzled/internal/my_pthread.h"                       // For thr_setconcurency()
133
 
#include "drizzled/constrained_value.h"
134
122
 
135
123
#include <drizzled/gettext.h>
136
124
 
137
125
 
138
 
#ifdef HAVE_VALGRIND
 
126
#ifdef HAVE_purify
139
127
#define IF_PURIFY(A,B) (A)
140
128
#else
141
129
#define IF_PURIFY(A,B) (B)
147
135
 
148
136
 
149
137
using namespace std;
150
 
namespace fs=boost::filesystem;
151
138
namespace po=boost::program_options;
152
 
namespace dpo=drizzled::program_options;
153
139
 
154
140
 
155
141
namespace drizzled
205
191
  Used with --help for detailed option
206
192
*/
207
193
bool opt_help= false;
 
194
bool opt_help_extended= false;
208
195
 
209
196
arg_cmp_func Arg_comparator::comparator_matrix[5][2] =
210
197
{{&Arg_comparator::compare_string,     &Arg_comparator::compare_e_string},
215
202
 
216
203
/* static variables */
217
204
 
218
 
static bool opt_debugging= false;
 
205
static bool opt_debugging= 0;
219
206
static uint32_t wake_thread;
220
207
static char *drizzled_chroot;
 
208
static char *language_ptr;
221
209
static const char *default_character_set_name;
222
210
static const char *character_set_filesystem_name;
223
211
static char *lc_time_names_name;
233
221
bool volatile abort_loop;
234
222
bool volatile shutdown_in_progress;
235
223
char *opt_scheduler_default;
236
 
const char *opt_scheduler= NULL;
 
224
char *opt_scheduler= NULL;
237
225
 
238
226
size_t my_thread_stack_size= 0;
239
227
 
243
231
plugin::StorageEngine *heap_engine;
244
232
plugin::StorageEngine *myisam_engine;
245
233
 
 
234
char* opt_secure_file_priv= 0;
 
235
 
246
236
bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
247
237
 
248
238
uint32_t drizzled_bind_timeout;
250
240
uint32_t dropping_tables, ha_open_options;
251
241
uint32_t tc_heuristic_recover= 0;
252
242
uint64_t session_startup_options;
253
 
back_log_constraints back_log(50);
 
243
uint32_t back_log;
254
244
uint32_t server_id;
255
245
uint64_t table_cache_size;
256
246
size_t table_def_size;
297
287
time_t server_start_time;
298
288
time_t flush_status_time;
299
289
 
300
 
fs::path basedir(PREFIX);
301
 
fs::path pid_file;
302
 
fs::path secure_file_priv("");
303
 
fs::path plugin_dir;
304
 
fs::path system_config_dir(SYSCONFDIR);
305
 
 
306
 
 
307
 
char system_time_zone[30];
 
290
char drizzle_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
308
291
char *default_tz_name;
309
292
char glob_hostname[FN_REFLEN];
310
 
 
311
 
char *opt_tc_log_file;
 
293
char data_home_real[FN_REFLEN],
 
294
     language[FN_REFLEN], 
 
295
     *opt_tc_log_file;
312
296
const key_map key_map_empty(0);
313
297
key_map key_map_full(0);                        // Will be initialized later
314
298
 
 
299
uint32_t data_home_len;
 
300
char data_home_buff[2], *data_home=data_home_real;
315
301
std::string drizzle_tmpdir;
316
302
char *opt_drizzle_tmpdir= NULL;
317
303
 
326
312
 
327
313
FILE *stderror_file=0;
328
314
 
329
 
struct drizzle_system_variables global_system_variables;
330
 
struct drizzle_system_variables max_system_variables;
 
315
struct system_variables global_system_variables;
 
316
struct system_variables max_system_variables;
331
317
struct global_counters current_global_counters;
332
318
 
333
319
const CHARSET_INFO *system_charset_info, *files_charset_info ;
339
325
SHOW_COMP_OPTION have_symlink;
340
326
 
341
327
/* Thread specific variables */
 
328
 
 
329
boost::mutex LOCK_open;
342
330
boost::mutex LOCK_global_system_variables;
 
331
boost::mutex LOCK_thread_count;
343
332
 
344
 
boost::condition_variable_any COND_refresh;
 
333
boost::condition_variable COND_refresh;
345
334
boost::condition_variable COND_thread_count;
346
335
pthread_t signal_thread;
347
336
boost::condition_variable COND_server_end;
349
338
/* Static variables */
350
339
 
351
340
int cleanup_done;
 
341
static char *drizzle_home_ptr, *pidfile_name_ptr;
352
342
 
353
343
passwd *user_info;
354
344
 
355
345
atomic<uint32_t> connection_count;
356
346
 
357
 
global_buffer_constraint<uint64_t> global_sort_buffer(0);
358
 
global_buffer_constraint<uint64_t> global_join_buffer(0);
359
 
global_buffer_constraint<uint64_t> global_read_rnd_buffer(0);
360
 
global_buffer_constraint<uint64_t> global_read_buffer(0);
361
 
 
362
347
/** 
363
348
  Refresh value. We use to test this to find out if a refresh even has happened recently.
364
349
*/
369
354
 
370
355
static void drizzle_init_variables(void);
371
356
static void get_options();
372
 
static void fix_paths();
 
357
static const char *get_relative_path(const char *path);
 
358
static void fix_paths(string progname);
373
359
 
374
360
static void usage(void);
375
361
void close_connections(void);
376
362
 
377
 
fs::path base_plugin_dir(PKGPLUGINDIR);
378
 
 
379
 
po::options_description config_options("Config File Options");
380
363
po::options_description long_options("Kernel Options");
381
 
po::options_description plugin_load_options("Plugin Loading Options");
382
364
po::options_description plugin_options("Plugin Options");
383
 
po::options_description initial_options("Config and Plugin Loading");
384
 
po::options_description full_options("Kernel and Plugin Loading and Plugin");
385
365
vector<string> unknown_options;
386
366
vector<string> defaults_file_list;
387
367
po::variables_map vm;
388
368
 
389
 
fs::path data_home(LOCALSTATEDIR);
390
 
fs::path full_data_home(LOCALSTATEDIR);
391
 
 
392
369
po::variables_map &getVariablesMap()
393
370
{
394
371
  return vm;
395
372
}
396
 
 
397
 
fs::path& getDataHome()
398
 
{
399
 
  return data_home;
400
 
}
401
 
 
402
 
fs::path& getDataHomeCatalog()
403
 
{
404
 
  static fs::path data_home_catalog(getDataHome());
405
 
  return data_home_catalog;
406
 
}
407
 
 
408
373
 
409
374
/****************************************************************************
410
375
** Code to end drizzled
417
382
 
418
383
  /* kill connection thread */
419
384
  {
420
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
 
385
    boost::mutex::scoped_lock scopedLock(LOCK_thread_count);
421
386
 
422
387
    while (select_thread_in_use)
423
388
    {
441
406
    statements and inform their clients that the server is about to die.
442
407
  */
443
408
 
 
409
  Session *tmp;
 
410
 
 
411
  LOCK_thread_count.lock(); // For unlink from list
 
412
 
 
413
  for( SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
444
414
  {
445
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
446
 
    session::Cache::list list= session::Cache::singleton().getCache();
447
 
 
448
 
    for (session::Cache::list::iterator it= list.begin(); it != list.end(); ++it )
449
 
    {
450
 
      Session::shared_ptr tmp(*it);
451
 
 
452
 
      tmp->setKilled(Session::KILL_CONNECTION);
453
 
      tmp->scheduler->killSession(tmp.get());
454
 
      DRIZZLE_CONNECTION_DONE(tmp->thread_id);
455
 
 
456
 
      tmp->lockOnSys();
457
 
    }
 
415
    tmp= *it;
 
416
    tmp->killed= Session::KILL_CONNECTION;
 
417
    tmp->scheduler->killSession(tmp);
 
418
    DRIZZLE_CONNECTION_DONE(tmp->thread_id);
 
419
    tmp->lockOnSys();
458
420
  }
 
421
  LOCK_thread_count.unlock(); // For unlink from list
459
422
 
460
 
  if (session::Cache::singleton().count())
 
423
  if (connection_count)
461
424
    sleep(2);                                   // Give threads time to die
462
425
 
463
426
  /*
467
430
  */
468
431
  for (;;)
469
432
  {
470
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
471
 
    session::Cache::list list= session::Cache::singleton().getCache();
472
 
 
473
 
    if (list.empty())
 
433
    LOCK_thread_count.lock(); // For unlink from list
 
434
    if (getSessionList().empty())
474
435
    {
 
436
      LOCK_thread_count.unlock();
475
437
      break;
476
438
    }
 
439
    tmp= getSessionList().front();
477
440
    /* Close before unlock, avoiding crash. See LP bug#436685 */
478
 
    list.front()->client->close();
 
441
    tmp->client->close();
 
442
    LOCK_thread_count.unlock();
479
443
  }
480
444
}
481
445
 
 
446
/**
 
447
  cleanup all memory and end program nicely.
 
448
 
 
449
    If SIGNALS_DONT_BREAK_READ is defined, this function is called
 
450
    by the main thread. To get Drizzle to shut down nicely in this case
 
451
    (Mac OS X) we have to call exit() instead if pthread_exit().
 
452
 
 
453
  @note
 
454
    This function never returns.
 
455
*/
 
456
void unireg_end(void)
 
457
{
 
458
  clean_up(1);
 
459
  internal::my_thread_end();
 
460
#if defined(SIGNALS_DONT_BREAK_READ)
 
461
  exit(0);
 
462
#else
 
463
  pthread_exit(0);                              // Exit is in main thread
 
464
#endif
 
465
}
 
466
 
482
467
 
483
468
void unireg_abort(int exit_code)
484
469
{
485
470
 
486
471
  if (exit_code)
487
472
    errmsg_printf(ERRMSG_LVL_ERROR, _("Aborting\n"));
488
 
  else if (opt_help)
 
473
  else if (opt_help || opt_help_extended)
489
474
    usage();
490
475
  clean_up(!opt_help && (exit_code));
491
476
  internal::my_end();
499
484
    return;
500
485
 
501
486
  table_cache_free();
 
487
  set_var_free();
502
488
  free_charsets();
503
489
  module::Registry &modules= module::Registry::singleton();
504
490
  modules.shutdownModules();
505
491
  xid_cache_free();
 
492
  if (opt_secure_file_priv)
 
493
    free(opt_secure_file_priv);
506
494
 
507
495
  deinit_temporal_formats();
508
496
 
510
498
  google::protobuf::ShutdownProtobufLibrary();
511
499
#endif
512
500
 
513
 
  (void) unlink(pid_file.file_string().c_str());        // This may not always exist
 
501
  (void) unlink(pidfile_name);  // This may not always exist
514
502
 
515
503
  if (print_message && server_start_time)
516
504
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
517
 
  {
518
 
    boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
519
 
    ready_to_exit= true;
520
 
 
521
 
    /* do the broadcast inside the lock to ensure that my_end() is not called */
522
 
    COND_server_end.notify_all();
523
 
  }
 
505
  LOCK_thread_count.lock();
 
506
  ready_to_exit=1;
 
507
  /* do the broadcast inside the lock to ensure that my_end() is not called */
 
508
  COND_server_end.notify_all();
 
509
  LOCK_thread_count.unlock();
524
510
 
525
511
  /*
526
512
    The following lines may never be executed as the main thread may have
550
536
    }
551
537
    return NULL;
552
538
  }
553
 
  if (not user)
 
539
  if (!user)
554
540
  {
555
541
      errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
556
542
                      "the manual to find out how to run drizzled as root!\n"));
626
612
  SYNOPSIS
627
613
    Session::unlink()
628
614
    session              Thread handler
 
615
 
 
616
  NOTES
 
617
    LOCK_thread_count is locked and left locked
629
618
*/
630
619
 
631
 
void drizzled::Session::unlink(Session::shared_ptr &session)
 
620
void Session::unlink(Session *session)
632
621
{
633
622
  connection_count.decrement();
634
623
 
635
624
  session->cleanup();
636
625
 
637
 
  boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
638
 
 
639
 
  if (unlikely(plugin::EventObserver::disconnectSession(*session)))
640
 
  {
641
 
    // We should do something about an error...
642
 
  }
643
 
  session::Cache::singleton().erase(session);
 
626
  LOCK_thread_count.lock();
 
627
  session->lockForDelete();
 
628
 
 
629
  getSessionList().erase(remove(getSessionList().begin(),
 
630
                         getSessionList().end(),
 
631
                         session));
 
632
 
 
633
  delete session;
 
634
  LOCK_thread_count.unlock();
644
635
}
645
636
 
646
637
 
659
650
  DRIZZLE_CONFIG_NAME, "server", 0, 0
660
651
};
661
652
 
662
 
static void find_plugin_dir(string progname)
663
 
{
664
 
  if (progname[0] != FN_LIBCHAR)
665
 
  {
666
 
    /* We have a relative path and need to find the absolute */
667
 
    char working_dir[FN_REFLEN];
668
 
    char *working_dir_ptr= working_dir;
669
 
    working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
670
 
    string new_path(working_dir);
671
 
    if (*(new_path.end()-1) != '/')
672
 
      new_path.push_back('/');
673
 
    if (progname[0] == '.' && progname[1] == '/')
674
 
      new_path.append(progname.substr(2));
675
 
    else
676
 
      new_path.append(progname);
677
 
    progname.swap(new_path);
678
 
  }
679
 
 
680
 
  /* Now, trim off the exe name */
681
 
  string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
682
 
  if (progdir.rfind(".libs/") != string::npos)
683
 
  {
684
 
    progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
685
 
  }
686
 
  string testlofile(progdir);
687
 
  testlofile.append("drizzled.lo");
688
 
  string testofile(progdir);
689
 
  testofile.append("drizzled.o");
690
 
  struct stat testfile_stat;
691
 
  if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
692
 
  {
693
 
    /* We are in a source dir! Plugin dir is ../plugin/.libs */
694
 
    size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
695
 
    base_plugin_dir= progdir.substr(0,last_libchar_pos);
696
 
    base_plugin_dir /= "plugin";
697
 
    base_plugin_dir /= ".libs";
698
 
  }
699
 
 
700
 
  if (plugin_dir.root_directory() == "")
701
 
  {
702
 
    fs::path full_plugin_dir(fs::system_complete(base_plugin_dir));
703
 
    full_plugin_dir /= plugin_dir;
704
 
    plugin_dir= full_plugin_dir;
705
 
  }
706
 
}
707
 
 
708
 
static void notify_plugin_dir(fs::path in_plugin_dir)
709
 
{
710
 
  plugin_dir= in_plugin_dir;
711
 
  if (plugin_dir.root_directory() == "")
712
 
  {
713
 
    fs::path full_plugin_dir(fs::system_complete(basedir));
714
 
    full_plugin_dir /= plugin_dir;
715
 
    plugin_dir= full_plugin_dir;
716
 
  }
717
 
}
718
 
 
719
 
static void expand_secure_file_priv(fs::path in_secure_file_priv)
720
 
{
721
 
  secure_file_priv= fs::system_complete(in_secure_file_priv);
722
 
}
723
 
 
724
653
static void check_limits_aii(uint64_t in_auto_increment_increment)
725
654
{
726
655
  global_system_variables.auto_increment_increment= 1;
754
683
  global_system_variables.completion_type= in_completion_type;
755
684
}
756
685
 
 
686
static void check_limits_back_log(uint32_t in_back_log)
 
687
{
 
688
  back_log= 50;
 
689
  if (in_back_log < 1 || in_back_log > 65535)
 
690
  {
 
691
    cout << N_("Error: Invalid Value for back_log");
 
692
    exit(-1);
 
693
  }
 
694
  back_log= in_back_log;
 
695
}
757
696
 
758
697
static void check_limits_dpi(uint32_t in_div_precincrement)
759
698
{
791
730
 
792
731
static void check_limits_map(uint32_t in_max_allowed_packet)
793
732
{
794
 
  global_system_variables.max_allowed_packet= (64*1024*1024L);
 
733
  global_system_variables.max_allowed_packet= (1024*1024L);
795
734
  if (in_max_allowed_packet < 1024 || in_max_allowed_packet > 1024*1024L*1024L)
796
735
  {
797
736
    cout << N_("Error: Invalid Value for max_allowed_packet");
890
829
  global_system_variables.max_sort_length= in_max_sort_length;
891
830
}
892
831
 
 
832
static void check_limits_mwlc(uint64_t in_min_examined_row_limit)
 
833
{
 
834
  global_system_variables.min_examined_row_limit= ULONG_MAX;
 
835
  if (in_min_examined_row_limit > ULONG_MAX)
 
836
  {
 
837
    cout << N_("Error: Invalid Value for min_examined_row_limit");
 
838
    exit(-1);
 
839
  }
 
840
  global_system_variables.min_examined_row_limit= in_min_examined_row_limit;
 
841
}
 
842
 
893
843
static void check_limits_osd(uint32_t in_optimizer_search_depth)
894
844
{
895
845
  global_system_variables.optimizer_search_depth= 0;
1031
981
  global_system_variables.tmp_table_size= in_tmp_table_size;
1032
982
}
1033
983
 
1034
 
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1035
 
{
1036
 
  global_system_variables.transaction_message_threshold= 1024*1024;
1037
 
  if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1038
 
  {
1039
 
    cout << N_("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1040
 
    exit(-1);
1041
 
  }
1042
 
  global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
 
984
static pair<string, string> parse_size_suffixes(string s)
 
985
{
 
986
  size_t equal_pos= s.find("=");
 
987
  if (equal_pos != string::npos)
 
988
  {
 
989
    string arg_key(s.substr(0, equal_pos));
 
990
    string arg_val(s.substr(equal_pos+1));
 
991
 
 
992
    try
 
993
    {
 
994
      size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
 
995
      if (size_suffix_pos == arg_val.size()-1)
 
996
      {
 
997
        char suffix= arg_val[size_suffix_pos];
 
998
        string size_val(arg_val.substr(0, size_suffix_pos));
 
999
 
 
1000
        uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
 
1001
        uint64_t new_size= 0;
 
1002
 
 
1003
        switch (suffix)
 
1004
        {
 
1005
        case 'K':
 
1006
        case 'k':
 
1007
          new_size= base_size * 1024;
 
1008
          break;
 
1009
        case 'M':
 
1010
        case 'm':
 
1011
          new_size= base_size * 1024 * 1024;
 
1012
          break;
 
1013
        case 'G':
 
1014
        case 'g':
 
1015
          new_size= base_size * 1024 * 1024 * 1024;
 
1016
          break;
 
1017
        }
 
1018
        return make_pair(arg_key,
 
1019
                         boost::lexical_cast<string>(new_size));
 
1020
      }
 
1021
    }
 
1022
    catch (...)
 
1023
    {
 
1024
      /* Screw it, let the normal parser take over */
 
1025
    }
 
1026
  }
 
1027
 
 
1028
  return make_pair(string(""), string(""));
 
1029
}
 
1030
 
 
1031
static pair<string, string> parse_size_arg(string s)
 
1032
{
 
1033
  if (s.find("--") == 0)
 
1034
  {
 
1035
    return parse_size_suffixes(s.substr(2));
 
1036
  }
 
1037
  return make_pair(string(""), string(""));
1043
1038
}
1044
1039
 
1045
1040
static void process_defaults_files()
1048
1043
       iter != defaults_file_list.end();
1049
1044
       ++iter)
1050
1045
  {
1051
 
    fs::path file_location= *iter;
 
1046
    string file_location(vm["config-dir"].as<string>());
 
1047
    if ((*iter)[0] != '/')
 
1048
    {
 
1049
      /* Relative path - add config dir */
 
1050
      file_location.push_back('/');
 
1051
      file_location.append(*iter);
 
1052
    }
 
1053
    else
 
1054
    {
 
1055
      file_location= *iter;
 
1056
    }
1052
1057
 
1053
 
    ifstream input_defaults_file(file_location.file_string().c_str());
 
1058
    ifstream input_defaults_file(file_location.c_str());
1054
1059
    
1055
1060
    po::parsed_options file_parsed=
1056
 
      dpo::parse_config_file(input_defaults_file, full_options, true);
 
1061
      po::parse_config_file(input_defaults_file, long_options, true);
1057
1062
    vector<string> file_unknown= 
1058
1063
      po::collect_unrecognized(file_parsed.options, po::include_positional);
1059
1064
 
1088
1093
       it != in_options.end();
1089
1094
       ++it)
1090
1095
  {
1091
 
    fs::path p(*it);
1092
 
    if (fs::is_regular_file(p))
1093
 
      defaults_file_list.push_back(*it);
1094
 
    else
1095
 
    {
1096
 
      errmsg_printf(ERRMSG_LVL_ERROR,
1097
 
                  _("Defaults file '%s' not found\n"), (*it).c_str());
1098
 
      unireg_abort(1);
1099
 
    }
1100
 
 
 
1096
    defaults_file_list.push_back(*it);
1101
1097
  }
1102
1098
}
1103
1099
 
1104
 
int init_common_variables(int argc, char **argv, module::Registry &plugins)
 
1100
int init_common_variables(int argc, char **argv)
1105
1101
{
1106
1102
  time_t curr_time;
1107
1103
  umask(((~internal::my_umask) & 0666));
1117
1113
 
1118
1114
  drizzle_init_variables();
1119
1115
 
1120
 
  find_plugin_dir(argv[0]);
1121
1116
  {
1122
1117
    struct tm tm_tmp;
1123
1118
    localtime_r(&server_start_time,&tm_tmp);
1138
1133
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1139
1134
    errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1140
1135
                  glob_hostname);
1141
 
    pid_file= "drizzle";
 
1136
    strncpy(pidfile_name, STRING_WITH_LEN("drizzle"));
1142
1137
  }
1143
1138
  else
1144
 
  {
1145
 
    pid_file= glob_hostname;
1146
 
  }
1147
 
  pid_file.replace_extension(".pid");
1148
 
 
1149
 
  system_config_dir /= "drizzle";
1150
 
 
1151
 
  config_options.add_options()
 
1139
    strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
 
1140
  strcpy(internal::fn_ext(pidfile_name),".pid");                // Add proper extension
 
1141
 
 
1142
  std::string system_config_dir_drizzle(SYSCONFDIR);
 
1143
  system_config_dir_drizzle.append("/drizzle");
 
1144
 
 
1145
  std::string system_config_file_drizzle("drizzled.cnf");
 
1146
 
 
1147
  long_options.add_options()
 
1148
  ("help-extended", po::value<bool>(&opt_help_extended)->default_value(false)->zero_tokens(),
 
1149
  N_("Display this help and exit after initializing plugins."))
1152
1150
  ("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1153
1151
  N_("Display this help and exit."))
1154
 
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1155
 
  N_("Configuration file defaults are not used if no-defaults is set"))
1156
 
  ("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1157
 
   N_("Configuration file to use"))
1158
 
  ("config-dir", po::value<fs::path>(&system_config_dir),
1159
 
   N_("Base location for config files"))
1160
 
  ("plugin-dir", po::value<fs::path>(&plugin_dir)->notifier(&notify_plugin_dir),
1161
 
  N_("Directory for plugins."))
1162
 
  ;
1163
 
 
1164
 
  plugin_load_options.add_options()
1165
 
  ("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1166
 
  N_("Optional comma separated list of plugins to load at startup in addition "
1167
 
     "to the default list of plugins. "
1168
 
     "[for example: --plugin_add=crc32,logger_gearman]"))    
1169
 
  ("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1170
 
  N_("Optional comma separated list of plugins to not load at startup. Effectively "
1171
 
     "removes a plugin from the list of plugins to be loaded. "
1172
 
     "[for example: --plugin_remove=crc32,logger_gearman]"))
1173
 
  ("plugin-load", po::value<string>()->notifier(&notify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1174
 
  N_("Optional comma separated list of plugins to load at starup instead of "
1175
 
     "the default plugin load list. "
1176
 
     "[for example: --plugin_load=crc32,logger_gearman]"))
1177
 
  ;
1178
 
 
1179
 
  long_options.add_options()
1180
1152
  ("auto-increment-increment", po::value<uint64_t>(&global_system_variables.auto_increment_increment)->default_value(1)->notifier(&check_limits_aii),
1181
1153
  N_("Auto-increment columns are incremented by this"))
1182
1154
  ("auto-increment-offset", po::value<uint64_t>(&global_system_variables.auto_increment_offset)->default_value(1)->notifier(&check_limits_aio),
1183
1155
  N_("Offset added to Auto-increment columns. Used when auto-increment-increment != 1"))
1184
 
  ("basedir,b", po::value<fs::path>(&basedir),
 
1156
  ("basedir,b", po::value<string>(),
1185
1157
  N_("Path to installation directory. All paths are usually resolved "
1186
1158
     "relative to this."))
1187
1159
  ("chroot,r", po::value<string>(),
1191
1163
  ("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1192
1164
  N_("Default completion type."))
1193
1165
  ("core-file",  N_("Write core on errors."))
1194
 
  ("datadir", po::value<fs::path>(&data_home),
 
1166
  ("datadir,h", po::value<string>(),
1195
1167
  N_("Path to the database root."))
1196
1168
  ("default-storage-engine", po::value<string>(),
1197
 
  N_("Set the default storage engine for tables."))
 
1169
  N_("Set the default storage engine (table type) for tables."))
1198
1170
  ("default-time-zone", po::value<string>(),
1199
1171
  N_("Set the default time zone."))
1200
1172
  ("exit-info,T", po::value<long>(),
1201
1173
  N_("Used for debugging;  Use at your own risk!"))
1202
1174
  ("gdb", po::value<bool>(&opt_debugging)->default_value(false)->zero_tokens(),
1203
1175
  N_("Set up signals usable for debugging"))
 
1176
  ("language,L", po::value<string>(),
 
1177
  N_("(IGNORED)"))  
1204
1178
  ("lc-time-name", po::value<string>(),
1205
1179
  N_("Set the language used for the month names and the days of the week."))
1206
 
  ("log-warnings,W", po::value<bool>(&global_system_variables.log_warnings)->default_value(false)->zero_tokens(),
 
1180
  ("log-warnings,W", po::value<string>(),
1207
1181
  N_("Log some not critical warnings to the log file."))  
1208
 
  ("pid-file", po::value<fs::path>(&pid_file),
1209
 
  N_("Pid file used by drizzled."))
 
1182
  ("pid-file", po::value<string>(),
 
1183
  N_("Pid file used by safe_mysqld."))
1210
1184
  ("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1211
 
  N_("Maximum time in seconds to wait for the port to become free. "))
1212
 
  ("replicate-query", po::value<bool>(&global_system_variables.replicate_query)->default_value(false)->zero_tokens(),
1213
 
  N_("Include the SQL query in replicated protobuf messages."))
1214
 
  ("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
 
1185
  N_("Maximum time in seconds to wait for the port to become free. "
 
1186
     "(Default: no wait)"))
 
1187
  ("secure-file-priv", po::value<string>(),
1215
1188
  N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1216
1189
     "within specified directory"))
1217
1190
  ("server-id", po::value<uint32_t>(&server_id)->default_value(0),
1228
1201
  N_("Path for temporary files."))
1229
1202
  ("transaction-isolation", po::value<string>(),
1230
1203
  N_("Default transaction isolation level."))
1231
 
  ("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1232
 
  N_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1233
1204
  ("user,u", po::value<string>(),
1234
1205
  N_("Run drizzled daemon as user."))  
1235
1206
  ("version,V", 
1236
1207
  N_("Output version information and exit."))
1237
 
  ("back-log", po::value<back_log_constraints>(&back_log),
 
1208
  ("back-log", po::value<uint32_t>(&back_log)->default_value(50)->notifier(&check_limits_back_log),
1238
1209
  N_("The number of outstanding connection requests Drizzle can have. This "
1239
1210
     "comes into play when the main Drizzle thread gets very many connection "
1240
1211
     "requests in a very short time."))
1249
1220
  N_("The maximum length of the result of function  group_concat."))
1250
1221
  ("join-buffer-size", po::value<uint64_t>(&global_system_variables.join_buff_size)->default_value(128*1024L)->notifier(&check_limits_join_buffer_size),
1251
1222
  N_("The size of the buffer that is used for full joins."))
1252
 
  ("join-heap-threshold",
1253
 
  po::value<uint64_t>()->default_value(0),
1254
 
  N_("A global cap on the amount of memory that can be allocated by session join buffers (0 means unlimited)"))
1255
 
  ("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
 
1223
  ("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(1024*1024L)->notifier(&check_limits_map),
1256
1224
  N_("Max packetlength to send/receive from to server."))
1257
1225
  ("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
1258
1226
  N_("If there is more than this number of interrupted connections from a "
1272
1240
  N_("The number of bytes to use when sorting BLOB or TEXT values "
1273
1241
     "(only the first max_sort_length bytes of each value are used; the "
1274
1242
     "rest are ignored)."))
1275
 
  ("max-write-lock-count", po::value<uint64_t>(&max_write_lock_count)->default_value(UINT64_MAX),
 
1243
  ("max-write-lock-count", po::value<uint64_t>(&max_write_lock_count)->default_value(ULONG_MAX)->notifier(&check_limits_mwlc),
1276
1244
  N_("After this many write locks, allow some read locks to run in between."))
1277
1245
  ("min-examined-row-limit", po::value<uint64_t>(&global_system_variables.min_examined_row_limit)->default_value(0)->notifier(&check_limits_merl),
1278
1246
  N_("Don't log queries which examine less than min_examined_row_limit "
1289
1257
     "automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1290
1258
     "optimizer will switch to the original find_best (used for "
1291
1259
     "testing/comparison)."))
 
1260
  ("plugin-dir", po::value<string>(),
 
1261
  N_("Directory for plugins."))
 
1262
  ("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
 
1263
  N_("Optional comma separated list of plugins to load at startup in addition "
 
1264
     "to the default list of plugins. "
 
1265
     "[for example: --plugin_add=crc32,logger_gearman]"))    
 
1266
  ("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
 
1267
  N_("Optional comma separated list of plugins to not load at startup. Effectively "
 
1268
     "removes a plugin from the list of plugins to be loaded. "
 
1269
     "[for example: --plugin_remove=crc32,logger_gearman]"))
 
1270
  ("plugin-load", po::value<string>()->notifier(&notify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
 
1271
  N_("Optional comma separated list of plugins to load at starup instead of "
 
1272
     "the default plugin load list. "
 
1273
     "[for example: --plugin_load=crc32,logger_gearman]"))  
1292
1274
  ("preload-buffer-size", po::value<uint64_t>(&global_system_variables.preload_buff_size)->default_value(32*1024L)->notifier(&check_limits_pbs),
1293
1275
  N_("The size of the buffer that is allocated when preloading indexes"))
1294
1276
  ("query-alloc-block-size", 
1305
1287
  N_("Each thread that does a sequential scan allocates a buffer of this "
1306
1288
      "size for each table it scans. If you do many sequential scans, you may "
1307
1289
      "want to increase this value."))
1308
 
  ("read-buffer-threshold",
1309
 
  po::value<uint64_t>()->default_value(0),
1310
 
  N_("A global cap on the size of read-buffer-size (0 means unlimited)"))
1311
1290
  ("read-rnd-buffer-size",
1312
1291
  po::value<uint32_t>(&global_system_variables.read_rnd_buff_size)->default_value(256*1024L)->notifier(&check_limits_read_rnd_buffer_size),
1313
1292
  N_("When reading rows in sorted order after a sort, the rows are read "
1314
1293
     "through this buffer to avoid a disk seeks. If not set, then it's set "
1315
1294
     "to the value of record_buffer."))
1316
 
  ("read-rnd-threshold",
1317
 
  po::value<uint64_t>()->default_value(0),
1318
 
  N_("A global cap on the size of read-rnd-buffer-size (0 means unlimited)"))
1319
1295
  ("scheduler", po::value<string>(),
1320
1296
  N_("Select scheduler to be used (by default multi-thread)."))
1321
1297
  ("sort-buffer-size",
1322
1298
  po::value<size_t>(&global_system_variables.sortbuff_size)->default_value(MAX_SORT_MEMORY)->notifier(&check_limits_sort_buffer_size),
1323
1299
  N_("Each thread that needs to do a sort allocates a buffer of this size."))
1324
 
  ("sort-heap-threshold",
1325
 
  po::value<uint64_t>()->default_value(0),
1326
 
  N_("A global cap on the amount of memory that can be allocated by session sort buffers (0 means unlimited)"))
1327
1300
  ("table-definition-cache", po::value<size_t>(&table_def_size)->default_value(128)->notifier(&check_limits_tdc),
1328
1301
  N_("The number of cached table definitions."))
1329
1302
  ("table-open-cache", po::value<uint64_t>(&table_cache_size)->default_value(TABLE_OPEN_CACHE_DEFAULT)->notifier(&check_limits_toc),
1337
1310
  po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1338
1311
  N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
1339
1312
     " automatically convert it to an on-disk MyISAM table."))
 
1313
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
 
1314
  N_("Configuration file defaults are not used if no-defaults is set"))
 
1315
  ("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
 
1316
   N_("Configuration file to use"))
 
1317
  ("config-dir", po::value<string>()->default_value(system_config_dir_drizzle),
 
1318
   N_("Base location for config files"))
1340
1319
  ;
1341
1320
 
1342
 
  full_options.add(long_options);
1343
 
  full_options.add(plugin_load_options);
1344
 
 
1345
 
  initial_options.add(config_options);
1346
 
  initial_options.add(plugin_load_options);
1347
 
 
 
1321
  // Disable allow_guessing
1348
1322
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1349
 
  /* Get options about where config files and the like are */
 
1323
 
1350
1324
  po::parsed_options parsed= po::command_line_parser(argc, argv).style(style).
1351
 
    options(initial_options).allow_unregistered().run();
 
1325
    options(long_options).allow_unregistered().extra_parser(parse_size_arg).run();
1352
1326
  unknown_options=
1353
1327
    po::collect_unrecognized(parsed.options, po::include_positional);
1354
1328
 
1356
1330
  {
1357
1331
    po::store(parsed, vm);
1358
1332
  }
1359
 
  catch (std::exception&)
 
1333
  catch (...)
1360
1334
  {
1361
1335
    errmsg_printf(ERRMSG_LVL_ERROR, _("Duplicate entry for command line option\n"));
1362
1336
    unireg_abort(1);
1364
1338
 
1365
1339
  if (not vm["no-defaults"].as<bool>())
1366
1340
  {
1367
 
    fs::path system_config_file_drizzle(system_config_dir);
1368
 
    system_config_file_drizzle /= "drizzled.cnf";
1369
1341
    defaults_file_list.insert(defaults_file_list.begin(),
1370
 
                              system_config_file_drizzle.file_string());
1371
 
 
1372
 
    fs::path config_conf_d_location(system_config_dir);
1373
 
    config_conf_d_location /= "conf.d";
1374
 
 
1375
 
 
1376
 
    CachedDirectory config_conf_d(config_conf_d_location.file_string());
1377
 
    if (not config_conf_d.fail())
 
1342
                              system_config_file_drizzle);
 
1343
  }
 
1344
 
 
1345
  string config_conf_d_location(vm["config-dir"].as<string>());
 
1346
  config_conf_d_location.append("/conf.d");
 
1347
  CachedDirectory config_conf_d(config_conf_d_location);
 
1348
  if (not config_conf_d.fail())
 
1349
  {
 
1350
 
 
1351
    for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
 
1352
         iter != config_conf_d.getEntries().end();
 
1353
         ++iter)
1378
1354
    {
1379
 
 
1380
 
      for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1381
 
           iter != config_conf_d.getEntries().end();
1382
 
           ++iter)
 
1355
      string file_entry((*iter)->filename);
 
1356
          
 
1357
      if (not file_entry.empty()
 
1358
          && file_entry != "."
 
1359
          && file_entry != "..")
1383
1360
      {
1384
 
        string file_entry((*iter)->filename);
1385
 
 
1386
 
        if (not file_entry.empty()
1387
 
            && file_entry != "."
1388
 
            && file_entry != "..")
1389
 
        {
1390
 
          fs::path the_entry(config_conf_d_location);
1391
 
          the_entry /= file_entry;
1392
 
          defaults_file_list.push_back(the_entry.file_string());
1393
 
        }
 
1361
        string the_entry(config_conf_d_location);
 
1362
        the_entry.push_back('/');
 
1363
        the_entry.append(file_entry);
 
1364
        defaults_file_list.push_back(the_entry);
1394
1365
      }
1395
1366
    }
1396
1367
  }
1397
1368
 
1398
 
  /* TODO: here is where we should add a process_env_vars */
1399
 
 
1400
 
  /* We need a notify here so that plugin_init will work properly */
1401
 
  try
1402
 
  {
1403
 
    po::notify(vm);
1404
 
  }
1405
 
  catch (po::validation_error &err)
1406
 
  {
1407
 
    errmsg_printf(ERRMSG_LVL_ERROR,  
1408
 
                  _("%s: %s.\n"
1409
 
                    "Use --help to get a list of available options\n"),
1410
 
                  internal::my_progname, err.what());
1411
 
    unireg_abort(1);
1412
 
  }
1413
 
 
 
1369
  po::notify(vm);
1414
1370
  process_defaults_files();
1415
 
 
1416
 
  /* Process with notify a second time because a config file may contain
1417
 
     plugin loader options */
1418
 
 
1419
 
  try
1420
 
  {
1421
 
    po::notify(vm);
1422
 
  }
1423
 
  catch (po::validation_error &err)
1424
 
  {
1425
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1426
 
                  _("%s: %s.\n"
1427
 
                    "Use --help to get a list of available options\n"),
1428
 
                  internal::my_progname, err.what());
1429
 
    unireg_abort(1);
1430
 
  }
1431
 
 
1432
 
  /* At this point, we've read all the options we need to read from files and
1433
 
     collected most of them into unknown options - now let's load everything
1434
 
  */
1435
 
 
1436
 
  if (plugin_init(plugins, plugin_options))
1437
 
  {
1438
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1439
 
    unireg_abort(1);
1440
 
  }
1441
 
 
1442
 
  full_options.add(plugin_options);
1443
 
 
1444
 
  vector<string> final_unknown_options;
1445
 
  try
1446
 
  {
1447
 
    po::parsed_options final_parsed=
1448
 
      po::command_line_parser(unknown_options).style(style).
1449
 
      options(full_options).extra_parser(dpo::parse_size_arg).run();
1450
 
 
1451
 
    final_unknown_options=
1452
 
      po::collect_unrecognized(final_parsed.options, po::include_positional);
1453
 
 
1454
 
    po::store(final_parsed, vm);
1455
 
 
1456
 
  }
1457
 
  catch (po::validation_error &err)
1458
 
  {
1459
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1460
 
                  _("%s: %s.\n"
1461
 
                    "Use --help to get a list of available options\n"),
1462
 
                  internal::my_progname, err.what());
1463
 
    unireg_abort(1);
1464
 
  }
1465
 
  catch (po::invalid_command_line_syntax &err)
1466
 
  {
1467
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1468
 
                  _("%s: %s.\n"
1469
 
                    "Use --help to get a list of available options\n"),
1470
 
                  internal::my_progname, err.what());
1471
 
    unireg_abort(1);
1472
 
  }
1473
 
  catch (po::unknown_option &err)
1474
 
  {
1475
 
    errmsg_printf(ERRMSG_LVL_ERROR,
1476
 
                  _("%s\nUse --help to get a list of available options\n"),
1477
 
                  err.what());
1478
 
    unireg_abort(1);
1479
 
  }
1480
 
 
1481
 
  try
1482
 
  {
1483
 
    po::notify(vm);
1484
 
  }
1485
 
  catch (po::validation_error &err)
1486
 
  {
1487
 
    errmsg_printf(ERRMSG_LVL_ERROR,  
1488
 
                  _("%s: %s.\n"
1489
 
                    "Use --help to get a list of available options\n"),
1490
 
                  internal::my_progname, err.what());
1491
 
    unireg_abort(1);
1492
 
  }
 
1371
  po::notify(vm);
1493
1372
 
1494
1373
  get_options();
1495
1374
 
1506
1385
    }
1507
1386
  }
1508
1387
 
1509
 
  fix_paths();
 
1388
  fix_paths(argv[0]);
1510
1389
 
1511
1390
  current_pid= getpid();                /* Save for later ref */
1512
1391
  init_time();                          /* Init time-functions (read zone) */
1513
1392
 
1514
1393
  if (item_create_init())
1515
1394
    return 1;
1516
 
  if (sys_var_init())
 
1395
  if (set_var_init())
1517
1396
    return 1;
1518
1397
  /* Creates static regex matching for temporal values */
1519
1398
  if (! init_temporal_formats())
1526
1405
    return 1;                           // Eof of the list
1527
1406
  }
1528
1407
 
1529
 
  if (vm.count("scheduler"))
1530
 
    opt_scheduler= vm["scheduler"].as<string>().c_str();
1531
 
 
1532
1408
  if (default_collation_name)
1533
1409
  {
1534
1410
    const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1583
1459
    errmsg_printf(ERRMSG_LVL_ERROR, _("Could not initialize table cache\n"));
1584
1460
    unireg_abort(1);
1585
1461
  }
1586
 
 
1587
 
  // Resize the definition Cache at startup
1588
 
  table::Cache::singleton().rehash(table_def_size);
1589
 
  definition::Cache::singleton().rehash(table_def_size);
1590
 
  message::Cache::singleton().rehash(table_def_size);
 
1462
  TableShare::cacheStart();
1591
1463
 
1592
1464
  setup_fpu();
1593
1465
 
1602
1474
  /* Allow storage engine to give real error messages */
1603
1475
  ha_init_errors();
1604
1476
 
1605
 
 
1606
 
  if (opt_help)
 
1477
  if (plugin_init(plugins, plugin_options))
 
1478
  {
 
1479
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
 
1480
    unireg_abort(1);
 
1481
  }
 
1482
 
 
1483
 
 
1484
  if (opt_help || opt_help_extended)
1607
1485
    unireg_abort(0);
1608
1486
 
1609
 
  if (plugin_finalize(plugins))
1610
 
  {
1611
 
    unireg_abort(1);
1612
 
  }
 
1487
  vector<string> final_unknown_options;
 
1488
  try
 
1489
  {
 
1490
    // Disable allow_guessing
 
1491
    int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
 
1492
    po::parsed_options parsed=
 
1493
      po::command_line_parser(unknown_options).style(style).
 
1494
      options(plugin_options).extra_parser(parse_size_arg).run();
 
1495
 
 
1496
    final_unknown_options=
 
1497
      po::collect_unrecognized(parsed.options, po::include_positional);
 
1498
 
 
1499
    po::store(parsed, vm);
 
1500
 
 
1501
  }
 
1502
  catch (po::invalid_command_line_syntax &err)
 
1503
  {
 
1504
    errmsg_printf(ERRMSG_LVL_ERROR,
 
1505
                  _("%s: %s.\n"
 
1506
                    "Use --help to get a list of available options\n"),
 
1507
                  internal::my_progname, err.what());
 
1508
    unireg_abort(1);
 
1509
  }
 
1510
  catch (po::unknown_option &err)
 
1511
  {
 
1512
    errmsg_printf(ERRMSG_LVL_ERROR,
 
1513
                  _("%s\nUse --help to get a list of available options\n"),
 
1514
                  err.what());
 
1515
    unireg_abort(1);
 
1516
  }
 
1517
 
 
1518
  po::notify(vm);
 
1519
 
 
1520
  plugin_finalize(plugins);
1613
1521
 
1614
1522
  string scheduler_name;
1615
1523
  if (opt_scheduler)
1744
1652
  {"help", '?', N_("Display this help and exit."),
1745
1653
   (char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1746
1654
   0, 0},
 
1655
  {"help-extended", '?',
 
1656
   N_("Display this help and exit after initializing plugins."),
 
1657
   (char**) &opt_help_extended, (char**) &opt_help_extended,
 
1658
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1747
1659
  {"auto-increment-increment", OPT_AUTO_INCREMENT,
1748
1660
   N_("Auto-increment columns are incremented by this"),
1749
1661
   (char**) &global_system_variables.auto_increment_increment,
1750
1662
   (char**) &max_system_variables.auto_increment_increment, 0, GET_ULL,
1751
 
   OPT_ARG, 1, 1, INT64_MAX, 0, 1, 0 },
 
1663
   OPT_ARG, 1, 1, UINT64_MAX, 0, 1, 0 },
1752
1664
  {"auto-increment-offset", OPT_AUTO_INCREMENT_OFFSET,
1753
1665
   N_("Offset added to Auto-increment columns. Used when "
1754
1666
      "auto-increment-increment != 1"),
1755
1667
   (char**) &global_system_variables.auto_increment_offset,
1756
1668
   (char**) &max_system_variables.auto_increment_offset, 0, GET_ULL, OPT_ARG,
1757
 
   1, 1, INT64_MAX, 0, 1, 0 },
 
1669
   1, 1, UINT64_MAX, 0, 1, 0 },
1758
1670
  {"basedir", 'b',
1759
1671
   N_("Path to installation directory. All paths are usually resolved "
1760
1672
      "relative to this."),
1761
 
   NULL, NULL, 0, GET_STR, REQUIRED_ARG,
 
1673
   (char**) &drizzle_home_ptr, (char**) &drizzle_home_ptr, 0, GET_STR, REQUIRED_ARG,
1762
1674
   0, 0, 0, 0, 0, 0},
1763
1675
  {"chroot", 'r',
1764
1676
   N_("Chroot drizzled daemon during startup."),
1779
1691
   NO_ARG, 0, 0, 0, 0, 0, 0},
1780
1692
  {"datadir", 'h',
1781
1693
   N_("Path to the database root."),
1782
 
   NULL, NULL, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1694
   (char**) &data_home,
 
1695
   (char**) &data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1783
1696
  {"default-storage-engine", OPT_STORAGE_ENGINE,
1784
1697
   N_("Set the default storage engine (table type) for tables."),
1785
1698
   (char**)&default_storage_engine_str, (char**)&default_storage_engine_str,
1798
1711
   N_("Set up signals usable for debugging"),
1799
1712
   (char**) &opt_debugging, (char**) &opt_debugging,
1800
1713
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1714
  {"language", 'L',
 
1715
   N_("(IGNORED)"),
 
1716
   (char**) &language_ptr, (char**) &language_ptr, 0, GET_STR, REQUIRED_ARG,
 
1717
   0, 0, 0, 0, 0, 0},
1801
1718
  {"lc-time-names", OPT_LC_TIME_NAMES,
1802
1719
   N_("Set the language used for the month names and the days of the week."),
1803
1720
   (char**) &lc_time_names_name,
1809
1726
   (char**) &max_system_variables.log_warnings, 0, GET_BOOL, OPT_ARG, 1, 0, 0,
1810
1727
   0, 0, 0},
1811
1728
  {"pid-file", OPT_PID_FILE,
1812
 
   N_("Pid file used by drizzled."),
1813
 
   NULL, NULL, 0, GET_STR,
 
1729
   N_("Pid file used by safe_mysqld."),
 
1730
   (char**) &pidfile_name_ptr, (char**) &pidfile_name_ptr, 0, GET_STR,
1814
1731
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1815
1732
  {"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
1816
1733
   N_("Maximum time in seconds to wait for the port to become free. "
1820
1737
  {"secure-file-priv", OPT_SECURE_FILE_PRIV,
1821
1738
   N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1822
1739
      "within specified directory"),
1823
 
   NULL, NULL, 0,
 
1740
   (char**) &opt_secure_file_priv, (char**) &opt_secure_file_priv, 0,
1824
1741
   GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1825
1742
  {"server-id", OPT_SERVER_ID,
1826
1743
   N_("Uniquely identifies the server instance in the community of "
1894
1811
   N_("Max packetlength to send/receive from to server."),
1895
1812
   (char**) &global_system_variables.max_allowed_packet,
1896
1813
   (char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
1897
 
   REQUIRED_ARG, 64*1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
1814
   REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1898
1815
  {"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
1899
1816
   N_("If there is more than this number of interrupted connections from a "
1900
1817
      "host this host will be blocked from further connections."),
1909
1826
   N_("Don't allow creation of heap tables bigger than this."),
1910
1827
   (char**) &global_system_variables.max_heap_table_size,
1911
1828
   (char**) &max_system_variables.max_heap_table_size, 0, GET_ULL,
1912
 
   REQUIRED_ARG, 16*1024*1024L, 16384, (int64_t)MAX_MEM_TABLE_SIZE,
 
1829
   REQUIRED_ARG, 16*1024*1024L, 16384, MAX_MEM_TABLE_SIZE,
1913
1830
   MALLOC_OVERHEAD, 1024, 0},
1914
1831
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1915
1832
   N_("Joins that are probably going to read more than max_join_size records "
1966
1883
   0, GET_UINT, OPT_ARG, 0, 0, MAX_TABLES+2, 0, 1, 0},
1967
1884
  {"plugin_dir", OPT_PLUGIN_DIR,
1968
1885
   N_("Directory for plugins."),
1969
 
   NULL, NULL, 0,
 
1886
   (char**) &opt_plugin_dir_ptr, (char**) &opt_plugin_dir_ptr, 0,
1970
1887
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1971
1888
  {"plugin_add", OPT_PLUGIN_ADD,
1972
1889
   N_("Optional comma separated list of plugins to load at startup in addition "
2006
1923
   N_("Allocation block size for storing ranges during optimization"),
2007
1924
   (char**) &global_system_variables.range_alloc_block_size,
2008
1925
   (char**) &max_system_variables.range_alloc_block_size, 0, GET_SIZE,
2009
 
   REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, (int64_t)SIZE_MAX,
 
1926
   REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, SIZE_MAX,
2010
1927
   0, 1024, 0},
2011
1928
  {"read_buffer_size", OPT_RECORD_BUFFER,
2012
1929
    N_("Each thread that does a sequential scan allocates a buffer of this "
2033
1950
   N_("Each thread that needs to do a sort allocates a buffer of this size."),
2034
1951
   (char**) &global_system_variables.sortbuff_size,
2035
1952
   (char**) &max_system_variables.sortbuff_size, 0, GET_SIZE, REQUIRED_ARG,
2036
 
   MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*8, (int64_t)SIZE_MAX,
 
1953
   MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*8, SIZE_MAX,
2037
1954
   MALLOC_OVERHEAD, 1, 0},
2038
1955
  {"table_definition_cache", OPT_TABLE_DEF_CACHE,
2039
1956
   N_("The number of cached table definitions."),
2053
1970
   (char**) &my_thread_stack_size,
2054
1971
   (char**) &my_thread_stack_size, 0, GET_SIZE,
2055
1972
   REQUIRED_ARG,DEFAULT_THREAD_STACK,
2056
 
   UINT32_C(1024*512), (int64_t)SIZE_MAX, 0, 1024, 0},
 
1973
   UINT32_C(1024*512), SIZE_MAX, 0, 1024, 0},
2057
1974
  {"tmp_table_size", OPT_TMP_TABLE_SIZE,
2058
1975
   N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
2059
1976
      " automatically convert it to an on-disk MyISAM table."),
2060
1977
   (char**) &global_system_variables.tmp_table_size,
2061
1978
   (char**) &max_system_variables.tmp_table_size, 0, GET_ULL,
2062
 
   REQUIRED_ARG, 16*1024*1024L, 1024, (int64_t)MAX_MEM_TABLE_SIZE, 0, 1, 0},
 
1979
   REQUIRED_ARG, 16*1024*1024L, 1024, MAX_MEM_TABLE_SIZE, 0, 1, 0},
2063
1980
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2064
1981
};
2065
1982
 
2091
2008
  printf(_("Usage: %s [OPTIONS]\n"), internal::my_progname);
2092
2009
 
2093
2010
  po::options_description all_options("Drizzled Options");
2094
 
  all_options.add(config_options);
2095
 
  all_options.add(plugin_load_options);
2096
2011
  all_options.add(long_options);
2097
2012
  all_options.add(plugin_options);
2098
2013
  cout << all_options << endl;
2118
2033
static void drizzle_init_variables(void)
2119
2034
{
2120
2035
  /* Things reset to zero */
 
2036
  drizzle_home[0]= pidfile_name[0]= 0;
2121
2037
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
 
2038
  opt_secure_file_priv= 0;
2122
2039
  cleanup_done= 0;
2123
2040
  dropping_tables= ha_open_options=0;
2124
2041
  test_flags.reset();
2136
2053
  character_set_filesystem= &my_charset_bin;
2137
2054
 
2138
2055
  /* Things with default values that are not zero */
 
2056
  drizzle_home_ptr= drizzle_home;
 
2057
  pidfile_name_ptr= pidfile_name;
 
2058
  language_ptr= language;
 
2059
  data_home= data_home_real;
2139
2060
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
2140
2061
  refresh_version= 1L;  /* Increments on each reload */
2141
2062
  global_thread_id= 1UL;
2142
 
  session::Cache::singleton().getCache().clear();
 
2063
  getSessionList().clear();
 
2064
 
 
2065
  /* Set directory paths */
 
2066
  strncpy(language, LANGUAGE, sizeof(language)-1);
 
2067
  strncpy(data_home_real, get_relative_path(LOCALSTATEDIR),
 
2068
          sizeof(data_home_real)-1);
 
2069
  data_home_buff[0]=FN_CURLIB;  // all paths are relative from here
 
2070
  data_home_buff[1]=0;
 
2071
  data_home_len= 2;
2143
2072
 
2144
2073
  /* Variables in libraries */
2145
2074
  default_character_set_name= "utf8";
2157
2086
  max_system_variables.auto_increment_increment= UINT64_MAX;
2158
2087
  max_system_variables.auto_increment_offset= UINT64_MAX;
2159
2088
  max_system_variables.completion_type= 2;
2160
 
  max_system_variables.log_warnings= true;
 
2089
  max_system_variables.log_warnings= 1;
2161
2090
  max_system_variables.bulk_insert_buff_size= ULONG_MAX;
2162
2091
  max_system_variables.div_precincrement= DECIMAL_MAX_SCALE;
2163
2092
  max_system_variables.group_concat_max_len= ULONG_MAX;
2190
2119
  have_symlink=SHOW_OPTION_YES;
2191
2120
#endif
2192
2121
 
 
2122
  const char *tmpenv;
 
2123
  if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
 
2124
    tmpenv = PREFIX;
 
2125
  (void) strncpy(drizzle_home, tmpenv, sizeof(drizzle_home)-1);
 
2126
  
2193
2127
  connection_count= 0;
2194
2128
}
2195
2129
 
2201
2135
static void get_options()
2202
2136
{
2203
2137
 
2204
 
  fs::path &data_home_catalog= getDataHomeCatalog();
2205
 
  data_home_catalog= getDataHome();
2206
 
  data_home_catalog /= "local"; 
 
2138
  if (vm.count("base-dir"))
 
2139
  {
 
2140
    strncpy(drizzle_home,vm["base-dir"].as<string>().c_str(),sizeof(drizzle_home)-1);
 
2141
  }
 
2142
 
 
2143
  if (vm.count("datadir"))
 
2144
  {
 
2145
    strncpy(data_home_real,vm["datadir"].as<string>().c_str(), sizeof(data_home_real)-1);
 
2146
    /* Correct pointer set by my_getopt (for embedded library) */
 
2147
    data_home= data_home_real;
 
2148
    data_home_len= strlen(data_home);
 
2149
  }
2207
2150
 
2208
2151
  if (vm.count("user"))
2209
2152
  {
2216
2159
                    vm["user"].as<string>().c_str(), drizzled_user);
2217
2160
  }
2218
2161
 
 
2162
  if (vm.count("language"))
 
2163
  {
 
2164
    strncpy(language, vm["language"].as<string>().c_str(), sizeof(language)-1);
 
2165
  }
 
2166
 
2219
2167
  if (vm.count("version"))
2220
2168
  {
2221
2169
    print_version();
2222
2170
    exit(0);
2223
2171
  }
2224
2172
 
2225
 
  if (vm.count("sort-heap-threshold"))
2226
 
  {
2227
 
    if ((vm["sort-heap-threshold"].as<uint64_t>() > 0) and
2228
 
      (vm["sort-heap-threshold"].as<uint64_t>() < 
2229
 
      global_system_variables.sortbuff_size))
2230
 
    {
2231
 
      cout << N_("Error: sort-heap-threshold cannot be less than sort-buffer-size") << endl;
2232
 
      exit(-1);
2233
 
    }
2234
 
 
2235
 
    global_sort_buffer.setMaxSize(vm["sort-heap-threshold"].as<uint64_t>());
2236
 
  }
2237
 
 
2238
 
  if (vm.count("join-heap-threshold"))
2239
 
  {
2240
 
    if ((vm["join-heap-threshold"].as<uint64_t>() > 0) and
2241
 
      (vm["join-heap-threshold"].as<uint64_t>() <
2242
 
      global_system_variables.join_buff_size))
2243
 
    {
2244
 
      cout << N_("Error: join-heap-threshold cannot be less than join-buffer-size") << endl;
2245
 
      exit(-1);
2246
 
    }
2247
 
 
2248
 
    global_join_buffer.setMaxSize(vm["join-heap-threshold"].as<uint64_t>());
2249
 
  }
2250
 
 
2251
 
  if (vm.count("read-rnd-threshold"))
2252
 
  {
2253
 
    if ((vm["read-rnd-threshold"].as<uint64_t>() > 0) and
2254
 
      (vm["read-rnd-threshold"].as<uint64_t>() <
2255
 
      global_system_variables.read_rnd_buff_size))
2256
 
    {
2257
 
      cout << N_("Error: read-rnd-threshold cannot be less than read-rnd-buffer-size") << endl;
2258
 
      exit(-1);
2259
 
    }
2260
 
 
2261
 
    global_read_rnd_buffer.setMaxSize(vm["read-rnd-threshold"].as<uint64_t>());
2262
 
  }
2263
 
 
2264
 
  if (vm.count("read-buffer-threshold"))
2265
 
  {
2266
 
    if ((vm["read-buffer-threshold"].as<uint64_t>() > 0) and
2267
 
      (vm["read-buffer-threshold"].as<uint64_t>() <
2268
 
      global_system_variables.read_buff_size))
2269
 
    {
2270
 
      cout << N_("Error: read-buffer-threshold cannot be less than read-buffer-size") << endl;
2271
 
      exit(-1);
2272
 
    }
2273
 
 
2274
 
    global_read_buffer.setMaxSize(vm["read-buffer-threshold"].as<uint64_t>());
 
2173
  if (vm.count("log-warnings"))
 
2174
  {
 
2175
    if (vm["log-warnings"].as<string>().empty())
 
2176
      global_system_variables.log_warnings++;
 
2177
    else if (vm["log-warnings"].as<string>().compare("0"))
 
2178
      global_system_variables.log_warnings= 0L;
 
2179
    else
 
2180
      global_system_variables.log_warnings= atoi(vm["log-warnings"].as<string>().c_str());
2275
2181
  }
2276
2182
 
2277
2183
  if (vm.count("exit-info"))
2297
2203
    internal::my_use_symdir=0;
2298
2204
  }
2299
2205
 
 
2206
  if (vm.count("pid-file"))
 
2207
  {
 
2208
    strncpy(pidfile_name, vm["pid-file"].as<string>().c_str(), sizeof(pidfile_name)-1);
 
2209
  }
 
2210
 
2300
2211
  if (vm.count("transaction-isolation"))
2301
2212
  {
2302
2213
    int type;
2344
2255
}
2345
2256
 
2346
2257
 
2347
 
static void fix_paths()
2348
 
{
2349
 
  fs::path pid_file_path(pid_file);
2350
 
  if (pid_file_path.root_path().string() == "")
2351
 
  {
2352
 
    pid_file_path= getDataHome();
2353
 
    pid_file_path /= pid_file;
2354
 
  }
2355
 
  pid_file= fs::system_complete(pid_file_path);
2356
 
 
2357
 
  if (not opt_help)
 
2258
static const char *get_relative_path(const char *path)
 
2259
{
 
2260
  if (internal::test_if_hard_path(path) &&
 
2261
      (strncmp(path, PREFIX, strlen(PREFIX)) == 0) &&
 
2262
      strcmp(PREFIX,FN_ROOTDIR))
 
2263
  {
 
2264
    if (strlen(PREFIX) < strlen(path))
 
2265
      path+=(size_t) strlen(PREFIX);
 
2266
    while (*path == FN_LIBCHAR)
 
2267
      path++;
 
2268
  }
 
2269
  return path;
 
2270
}
 
2271
 
 
2272
 
 
2273
static void fix_paths(string progname)
 
2274
{
 
2275
  char buff[FN_REFLEN],*pos,rp_buff[PATH_MAX];
 
2276
  internal::convert_dirname(drizzle_home,drizzle_home,NULL);
 
2277
  /* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */
 
2278
#if defined(HAVE_BROKEN_REALPATH)
 
2279
   internal::my_load_path(drizzle_home, drizzle_home, NULL);
 
2280
#else
 
2281
  if (!realpath(drizzle_home,rp_buff))
 
2282
    internal::my_load_path(rp_buff, drizzle_home, NULL);
 
2283
  rp_buff[FN_REFLEN-1]= '\0';
 
2284
  strcpy(drizzle_home,rp_buff);
 
2285
  /* Ensure that drizzle_home ends in FN_LIBCHAR */
 
2286
  pos= strchr(drizzle_home, '\0');
 
2287
#endif
 
2288
  if (pos[-1] != FN_LIBCHAR)
 
2289
  {
 
2290
    pos[0]= FN_LIBCHAR;
 
2291
    pos[1]= 0;
 
2292
  }
 
2293
  internal::convert_dirname(data_home_real,data_home_real,NULL);
 
2294
  (void) internal::fn_format(buff, data_home_real, "", "",
 
2295
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
 
2296
  internal::convert_dirname(language,language,NULL);
 
2297
  (void) internal::my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
 
2298
  (void) internal::my_load_path(data_home_real, data_home_real,drizzle_home);
 
2299
  (void) internal::my_load_path(pidfile_name, pidfile_name,data_home_real);
 
2300
 
 
2301
  if (opt_plugin_dir_ptr == NULL)
 
2302
  {
 
2303
    /* No plugin dir has been specified. Figure out where the plugins are */
 
2304
    if (progname[0] != FN_LIBCHAR)
 
2305
    {
 
2306
      /* We have a relative path and need to find the absolute */
 
2307
      char working_dir[FN_REFLEN];
 
2308
      char *working_dir_ptr= working_dir;
 
2309
      working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
 
2310
      string new_path(working_dir);
 
2311
      if (*(new_path.end()-1) != '/')
 
2312
        new_path.push_back('/');
 
2313
      if (progname[0] == '.' && progname[1] == '/')
 
2314
        new_path.append(progname.substr(2));
 
2315
      else
 
2316
        new_path.append(progname);
 
2317
      progname.swap(new_path);
 
2318
    }
 
2319
 
 
2320
    /* Now, trim off the exe name */
 
2321
    string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
 
2322
    if (progdir.rfind(".libs/") != string::npos)
 
2323
    {
 
2324
      progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
 
2325
    }
 
2326
    string testlofile(progdir);
 
2327
    testlofile.append("drizzled.lo");
 
2328
    string testofile(progdir);
 
2329
    testofile.append("drizzled.o");
 
2330
    struct stat testfile_stat;
 
2331
    if (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat))
 
2332
    {
 
2333
      /* neither drizzled.lo or drizzled.o exist - we are not in a source dir.
 
2334
       * Go on as usual
 
2335
       */
 
2336
      (void) internal::my_load_path(opt_plugin_dir, get_relative_path(PKGPLUGINDIR),
 
2337
                                          drizzle_home);
 
2338
    }
 
2339
    else
 
2340
    {
 
2341
      /* We are in a source dir! Plugin dir is ../plugin/.libs */
 
2342
      size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
 
2343
      string source_plugindir(progdir.substr(0,last_libchar_pos));
 
2344
      source_plugindir.append("plugin/.libs");
 
2345
      (void) internal::my_load_path(opt_plugin_dir, source_plugindir.c_str(), "");
 
2346
    }
 
2347
  }
 
2348
  else
 
2349
  {
 
2350
    (void) internal::my_load_path(opt_plugin_dir, opt_plugin_dir_ptr, drizzle_home);
 
2351
  }
 
2352
  opt_plugin_dir_ptr= opt_plugin_dir;
 
2353
 
 
2354
  const char *sharedir= get_relative_path(PKGDATADIR);
 
2355
  if (internal::test_if_hard_path(sharedir))
 
2356
    strncpy(buff,sharedir,sizeof(buff)-1);
 
2357
  else
 
2358
  {
 
2359
    strcpy(buff, drizzle_home);
 
2360
    strncat(buff, sharedir, sizeof(buff)-strlen(drizzle_home)-1);
 
2361
  }
 
2362
  internal::convert_dirname(buff,buff,NULL);
 
2363
  (void) internal::my_load_path(language,language,buff);
 
2364
 
 
2365
  if (not opt_help and not opt_help_extended)
2358
2366
  {
2359
2367
    const char *tmp_string= getenv("TMPDIR") ? getenv("TMPDIR") : NULL;
2360
2368
    struct stat buf;
2366
2374
    }
2367
2375
    else if (tmp_string == NULL)
2368
2376
    {
2369
 
      drizzle_tmpdir.append(getDataHome().file_string());
 
2377
      drizzle_tmpdir.append(data_home);
2370
2378
      drizzle_tmpdir.push_back(FN_LIBCHAR);
2371
2379
      drizzle_tmpdir.append(GLOBAL_TEMPORARY_EXT);
2372
2380
    }
2375
2383
      drizzle_tmpdir.append(tmp_string);
2376
2384
    }
2377
2385
 
2378
 
    drizzle_tmpdir= fs::path(fs::system_complete(fs::path(drizzle_tmpdir))).file_string();
2379
2386
    assert(drizzle_tmpdir.size());
2380
2387
 
2381
2388
    if (mkdir(drizzle_tmpdir.c_str(), 0777) == -1)
2394
2401
    }
2395
2402
  }
2396
2403
 
 
2404
  /*
 
2405
    Convert the secure-file-priv option to system format, allowing
 
2406
    a quick strcmp to check if read or write is in an allowed dir
 
2407
   */
 
2408
  if (vm.count("secure-file-priv"))
 
2409
  {
 
2410
    internal::convert_dirname(buff, vm["secure-file-priv"].as<string>().c_str(), NULL);
 
2411
    free(opt_secure_file_priv);
 
2412
    opt_secure_file_priv= strdup(buff);
 
2413
    if (opt_secure_file_priv == NULL)
 
2414
      exit(1);
 
2415
  }
2397
2416
}
2398
2417
 
2399
2418
} /* namespace drizzled */