~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

Merged in latest plugin-slot-reorg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
15
19
 
16
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/configmake.h>
 
22
#include <drizzled/atomics.h>
 
23
 
 
24
#include <netdb.h>
 
25
#include <netinet/tcp.h>
 
26
#include <signal.h>
 
27
 
17
28
#include <mysys/my_bit.h>
18
 
#include "slave.h"
19
 
#include "rpl_mi.h"
20
 
#include "sql_repl.h"
21
 
#include "rpl_filter.h"
22
 
#include "repl_failsafe.h"
23
 
#include "stacktrace.h"
 
29
#include <mysys/hash.h>
 
30
#include <drizzled/stacktrace.h>
24
31
#include <mysys/mysys_err.h>
25
 
#include <sys/poll.h>
26
 
#include <netinet/tcp.h>
27
 
#include <drizzled/drizzled_error_messages.h>
28
 
 
29
 
#include <storage/myisam/ha_myisam.h>
 
32
#include <drizzled/error.h>
 
33
#include <drizzled/errmsg_print.h>
 
34
#include <drizzled/tztime.h>
 
35
#include <drizzled/sql_base.h>
 
36
#include <drizzled/show.h>
 
37
#include <drizzled/sql_parse.h>
 
38
#include <drizzled/item/cmpfunc.h>
 
39
#include <drizzled/session.h>
 
40
#include <drizzled/db.h>
 
41
#include <drizzled/item/create.h>
 
42
#include <drizzled/unireg.h>
 
43
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
 
44
#include "drizzled/plugin/listen.h"
 
45
#include "drizzled/plugin/error_message.h"
 
46
#include "drizzled/plugin/client.h"
 
47
#include "drizzled/plugin/scheduler.h"
 
48
#include "drizzled/probes.h"
 
49
 
 
50
#include <google/protobuf/stubs/common.h>
 
51
 
 
52
#if TIME_WITH_SYS_TIME
 
53
# include <sys/time.h>
 
54
# include <time.h>
 
55
#else
 
56
# if HAVE_SYS_TIME_H
 
57
#  include <sys/time.h>
 
58
# else
 
59
#  include <time.h>
 
60
# endif
 
61
#endif
30
62
 
31
63
#ifdef HAVE_SYS_PRCTL_H
32
64
#include <sys/prctl.h>
33
65
#endif
34
66
 
35
 
#ifndef DEFAULT_SKIP_THREAD_PRIORITY
36
 
#define DEFAULT_SKIP_THREAD_PRIORITY 0
37
 
#endif
38
 
 
39
 
#include <mysys/thr_alarm.h>
40
 
#include <libdrizzle/errmsg.h>
41
67
#include <locale.h>
42
68
 
43
69
#define mysqld_charset &my_charset_utf8_general_ci
48
74
#define IF_PURIFY(A,B) (B)
49
75
#endif
50
76
 
51
 
#if SIZEOF_CHARP == 4
52
 
#define MAX_MEM_TABLE_SIZE ~(uint32_t) 0
53
 
#else
54
 
#define MAX_MEM_TABLE_SIZE ~(uint64_t) 0
55
 
#endif
56
 
 
57
 
/* We have HAVE_purify below as this speeds up the shutdown of MySQL */
58
 
 
59
 
#if defined(HAVE_DEC_3_2_THREADS) || defined(SIGNALS_DONT_BREAK_READ) || defined(HAVE_purify) && defined(__linux__)
60
 
#define HAVE_CLOSE_SERVER_SOCK 1
61
 
#endif
 
77
#define MAX_MEM_TABLE_SIZE SIZE_MAX
62
78
 
63
79
extern "C" {                                    // Because of SCO 3.2V4.2
64
80
#include <errno.h>
65
81
#include <sys/stat.h>
66
 
#ifndef __GNU_LIBRARY__
67
 
#define __GNU_LIBRARY__                         // Skip warnings in getopt.h
68
 
#endif
69
82
#include <mysys/my_getopt.h>
70
83
#ifdef HAVE_SYSENT_H
71
84
#include <sysent.h>
93
106
#include <sys/mman.h>
94
107
#endif
95
108
 
96
 
#define SIGNAL_FMT "signal %d"
97
 
 
98
 
 
99
109
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H)
100
110
#include <ieeefp.h>
101
111
#ifdef HAVE_FP_EXCEPT                           // Fix type conflict
143
153
 
144
154
} /* cplusplus */
145
155
 
146
 
#define DRIZZLE_KILL_SIGNAL SIGTERM
147
 
 
148
156
#include <mysys/my_pthread.h>                   // For thr_setconcurency()
149
157
 
150
 
#include <libdrizzle/gettext.h>
 
158
#include <drizzled/gettext.h>
151
159
 
152
160
#ifdef SOLARIS
153
161
extern "C" int gethostname(char *name, int namelen);
154
162
#endif
155
163
 
156
 
extern "C" RETSIGTYPE handle_segfault(int sig);
 
164
extern "C" void handle_segfault(int sig);
 
165
 
 
166
using namespace std;
 
167
using namespace drizzled;
157
168
 
158
169
/* Constants */
159
170
 
160
171
const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"};
161
 
/*
162
 
  WARNING: When adding new SQL modes don't forget to update the
163
 
           tables definitions that stores it's value.
164
 
           (ie: mysql.event, mysql.proc)
165
 
*/
166
172
static const char *optimizer_switch_names[]=
167
173
{
168
174
  "no_materialization", "no_semijoin",
190
196
  tc_heuristic_recover_names, NULL
191
197
};
192
198
 
193
 
const char *first_keyword= "first", *binary_keyword= "BINARY";
194
 
const char *my_localhost= "localhost";
195
 
#if SIZEOF_OFF_T > 4 && defined(BIG_TABLES)
 
199
const char *first_keyword= "first";
 
200
const char *binary_keyword= "BINARY";
 
201
const char * const DRIZZLE_CONFIG_NAME= "drizzled";
196
202
#define GET_HA_ROWS GET_ULL
197
 
#else
198
 
#define GET_HA_ROWS GET_ULONG
199
 
#endif
200
203
 
201
204
/*
202
205
  Used with --help for detailed option
203
206
*/
204
207
static bool opt_help= false;
 
208
static bool opt_help_extended= false;
205
209
 
206
210
arg_cmp_func Arg_comparator::comparator_matrix[5][2] =
207
211
{{&Arg_comparator::compare_string,     &Arg_comparator::compare_e_string},
210
214
 {&Arg_comparator::compare_row,        &Arg_comparator::compare_e_row},
211
215
 {&Arg_comparator::compare_decimal,    &Arg_comparator::compare_e_decimal}};
212
216
 
213
 
const char *log_output_names[] = { "NONE", "FILE", NULL};
214
 
static const unsigned int log_output_names_len[]= { 4, 4, 0 };
215
 
TYPELIB log_output_typelib= {array_elements(log_output_names)-1,"",
216
 
                             log_output_names,
217
 
                             (unsigned int *) log_output_names_len};
218
 
 
219
217
/* static variables */
220
218
 
221
 
/* the default log output is log tables */
222
 
static bool volatile select_thread_in_use, signal_thread_in_use;
 
219
static bool volatile select_thread_in_use;
223
220
static bool volatile ready_to_exit;
224
 
static bool opt_debugging= 0, opt_console= 0;
225
 
static uint32_t kill_cached_threads, wake_thread;
226
 
static uint32_t killed_threads, thread_created;
227
 
static uint32_t max_used_connections;
228
 
static volatile uint32_t cached_thread_count= 0;
229
 
static char *mysqld_user, *mysqld_chroot, *log_error_file_ptr;
230
 
static char *opt_init_slave, *language_ptr, *opt_init_connect;
231
 
static char *default_character_set_name;
232
 
static char *character_set_filesystem_name;
 
221
static bool opt_debugging= 0;
 
222
static uint32_t wake_thread;
 
223
static uint32_t killed_threads;
 
224
static char *drizzled_user, *drizzled_chroot;
 
225
static char *language_ptr;
 
226
static const char *default_character_set_name;
 
227
static const char *character_set_filesystem_name;
233
228
static char *lc_time_names_name;
234
 
static char *my_bind_addr_str;
235
229
static char *default_collation_name;
236
230
static char *default_storage_engine_str;
237
 
static char compiled_default_collation_name[]= DRIZZLE_DEFAULT_COLLATION_NAME;
238
 
static I_List<THD> thread_cache;
239
 
static double long_query_time;
240
 
 
241
 
static pthread_cond_t COND_thread_cache, COND_flush_thread_cache;
 
231
static const char *compiled_default_collation_name= "utf8_general_ci";
242
232
 
243
233
/* Global variables */
244
234
 
245
 
bool opt_bin_log;
246
 
ulong log_output_options;
247
 
bool opt_log_queries_not_using_indexes= false;
248
 
bool opt_error_log= 0;
249
 
bool opt_skip_show_db= false;
250
 
bool opt_character_set_client_handshake= 1;
251
 
bool server_id_supplied = 0;
252
 
bool opt_endinfo, using_udf_functions;
 
235
bool opt_endinfo;
253
236
bool locked_in_memory;
254
 
bool opt_using_transactions, using_update_log;
255
237
bool volatile abort_loop;
256
238
bool volatile shutdown_in_progress;
257
 
bool opt_skip_slave_start = 0; ///< If set, slave is not autostarted
258
 
bool opt_reckless_slave = 0;
259
 
bool opt_enable_named_pipe= 0;
260
 
bool opt_local_infile;
261
 
bool opt_slave_compressed_protocol;
262
 
bool opt_safe_user_create = 0;
263
 
bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
264
 
bool opt_log_slave_updates= 0;
265
 
static struct pollfd fds[UINT8_MAX];
266
 
static uint8_t pollfd_count= 0;
 
239
uint32_t max_used_connections;
 
240
const string opt_scheduler_default("multi_thread");
 
241
char *opt_scheduler= NULL;
 
242
 
 
243
size_t my_thread_stack_size= 65536;
267
244
 
268
245
/*
269
 
  Legacy global handlerton. These will be removed (please do not add more).
 
246
  Legacy global plugin::StorageEngine. These will be removed (please do not add more).
270
247
*/
271
 
handlerton *heap_hton;
272
 
handlerton *myisam_hton;
 
248
plugin::StorageEngine *heap_engine;
 
249
plugin::StorageEngine *myisam_engine;
273
250
 
274
 
bool opt_readonly;
275
 
bool use_temp_pool;
276
 
bool relay_log_purge;
277
 
bool opt_secure_auth= false;
278
251
char* opt_secure_file_priv= 0;
279
 
bool opt_log_slow_admin_statements= 0;
280
 
bool opt_log_slow_slave_statements= 0;
281
 
bool opt_old_style_user_limits= 0;
282
 
bool trust_function_creators= 0;
283
 
/*
284
 
  True if there is at least one per-hour limit for some user, so we should
285
 
  check them before each query (and possibly reset counters when hour is
286
 
  changed). False otherwise.
287
 
*/
288
 
bool opt_noacl;
289
252
 
290
 
ulong opt_binlog_rows_event_max_size;
291
 
const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NULL};
292
 
TYPELIB binlog_format_typelib=
293
 
  { array_elements(binlog_format_names) - 1, "",
294
 
    binlog_format_names, NULL };
295
 
uint32_t opt_binlog_format_id= (uint32_t) BINLOG_FORMAT_UNSPEC;
296
 
const char *opt_binlog_format= binlog_format_names[opt_binlog_format_id];
297
253
#ifdef HAVE_INITGROUPS
298
254
static bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
299
255
#endif
300
 
uint32_t mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options;
301
 
uint32_t mysqld_port_timeout;
302
 
uint32_t delay_key_write_options, protocol_version;
303
 
uint32_t lower_case_table_names= 1;
 
256
 
 
257
/*
 
258
  This needs to be a uint32_t and not a in_port_t because the config system
 
259
  requires a 4-byte integer.
 
260
*/
 
261
uint32_t drizzled_tcp_port;
 
262
char *drizzled_bind_host;
 
263
uint32_t drizzled_bind_timeout;
 
264
std::bitset<12> test_flags;
 
265
uint32_t dropping_tables, ha_open_options;
304
266
uint32_t tc_heuristic_recover= 0;
305
 
uint32_t volatile thread_count, thread_running;
306
 
uint64_t thd_startup_options;
307
 
ulong back_log, connect_timeout, server_id;
308
 
ulong table_cache_size, table_def_size;
309
 
ulong what_to_log;
310
 
ulong slow_launch_time, slave_open_temp_tables;
311
 
ulong open_files_limit;
312
 
ulong max_binlog_size;
313
 
ulong max_relay_log_size;
314
 
ulong slave_net_timeout;
315
 
ulong slave_trans_retries;
316
 
bool slave_allow_batching;
317
 
ulong slave_exec_mode_options;
318
 
const char *slave_exec_mode_str= "STRICT";
319
 
ulong thread_cache_size= 0;
320
 
ulong thread_pool_size= 0;
321
 
ulong binlog_cache_size= 0;
322
 
ulong max_binlog_cache_size= 0;
323
 
uint32_t refresh_version;  /* Increments on each reload */
324
 
query_id_t global_query_id;
325
 
ulong aborted_threads;
326
 
ulong aborted_connects;
327
 
ulong specialflag= 0;
328
 
ulong binlog_cache_use= 0;
329
 
ulong binlog_cache_disk_use= 0;
330
 
ulong max_connections;
331
 
ulong max_connect_errors;
332
 
uint32_t  max_user_connections= 0;
333
 
ulong thread_id=1L;
334
 
ulong current_pid;
335
 
ulong slow_launch_threads = 0;
336
 
ulong sync_binlog_period;
337
 
ulong expire_logs_days = 0;
338
 
ulong rpl_recovery_rank=0;
339
 
const char *log_output_str= "FILE";
 
267
uint64_t session_startup_options;
 
268
uint32_t back_log;
 
269
uint32_t server_id;
 
270
uint64_t table_cache_size;
 
271
uint64_t table_def_size;
 
272
uint64_t aborted_threads;
 
273
uint64_t aborted_connects;
 
274
uint64_t max_connect_errors;
 
275
uint32_t global_thread_id= 1UL;
 
276
pid_t current_pid;
340
277
 
341
278
const double log_10[] = {
342
279
  1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,
372
309
  1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308
373
310
};
374
311
 
375
 
time_t server_start_time, flush_status_time;
 
312
time_t server_start_time;
 
313
time_t flush_status_time;
376
314
 
377
 
char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
 
315
char drizzle_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
378
316
char *default_tz_name;
379
 
char log_error_file[FN_REFLEN], glob_hostname[FN_REFLEN];
380
 
char mysql_real_data_home[FN_REFLEN],
381
 
     language[FN_REFLEN], reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN],
382
 
     *opt_init_file, *opt_tc_log_file;
383
 
char mysql_unpacked_real_data_home[FN_REFLEN];
384
 
uint32_t reg_ext_length;
 
317
char glob_hostname[FN_REFLEN];
 
318
char drizzle_real_data_home[FN_REFLEN],
 
319
     language[FN_REFLEN], 
 
320
     *opt_tc_log_file;
 
321
char drizzle_unpacked_real_data_home[FN_REFLEN];
385
322
const key_map key_map_empty(0);
386
323
key_map key_map_full(0);                        // Will be initialized later
387
324
 
388
 
const char *opt_date_time_formats[3];
389
 
 
390
 
uint32_t mysql_data_home_len;
391
 
char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home;
392
 
char server_version[SERVER_VERSION_LENGTH];
393
 
char *opt_mysql_tmpdir;
394
 
const char *myisam_recover_options_str="OFF";
395
 
const char *myisam_stats_method_str="nulls_unequal";
 
325
uint32_t drizzle_data_home_len;
 
326
char drizzle_data_home_buff[2], *drizzle_data_home=drizzle_real_data_home;
 
327
char *drizzle_tmpdir= NULL;
 
328
char *opt_drizzle_tmpdir= NULL;
396
329
 
397
330
/** name of reference on left espression in rewritten IN subquery */
398
331
const char *in_left_expr_name= "<left expr>";
402
335
 
403
336
my_decimal decimal_zero;
404
337
/* classes for comparation parsing/processing */
405
 
Eq_creator eq_creator;
406
 
Ne_creator ne_creator;
407
 
Gt_creator gt_creator;
408
 
Lt_creator lt_creator;
409
 
Ge_creator ge_creator;
410
 
Le_creator le_creator;
411
338
 
412
339
FILE *stderror_file=0;
413
340
 
414
 
I_List<THD> threads;
415
 
I_List<NAMED_LIST> key_caches;
416
 
Rpl_filter* rpl_filter;
417
 
Rpl_filter* binlog_filter;
 
341
vector<Session*> session_list;
418
342
 
419
343
struct system_variables global_system_variables;
420
344
struct system_variables max_system_variables;
421
345
struct system_status_var global_status_var;
422
346
 
423
 
MY_TMPDIR mysql_tmpdir_list;
424
 
MY_BITMAP temp_pool;
425
 
 
426
347
const CHARSET_INFO *system_charset_info, *files_charset_info ;
427
 
const CHARSET_INFO *national_charset_info, *table_alias_charset;
 
348
const CHARSET_INFO *table_alias_charset;
428
349
const CHARSET_INFO *character_set_filesystem;
429
350
 
430
351
MY_LOCALE *my_default_lc_time_names;
431
352
 
432
353
SHOW_COMP_OPTION have_symlink;
433
 
SHOW_COMP_OPTION have_compress;
434
354
 
435
355
/* Thread specific variables */
436
356
 
437
 
pthread_key(MEM_ROOT**,THR_MALLOC);
438
 
pthread_key(THD*, THR_THD);
439
 
pthread_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_thread_count,
440
 
                LOCK_status, LOCK_global_read_lock,
441
 
                LOCK_error_log, LOCK_uuid_generator,
442
 
                LOCK_global_system_variables,
443
 
                LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
444
 
                LOCK_connection_count;
 
357
pthread_key_t THR_Mem_root;
 
358
pthread_key_t THR_Session;
 
359
pthread_mutex_t LOCK_create_db;
 
360
pthread_mutex_t LOCK_open;
 
361
pthread_mutex_t LOCK_thread_count;
 
362
pthread_mutex_t LOCK_status;
 
363
pthread_mutex_t LOCK_global_read_lock;
 
364
pthread_mutex_t LOCK_global_system_variables;
445
365
 
446
 
rw_lock_t       LOCK_sys_init_connect, LOCK_sys_init_slave;
447
 
rw_lock_t       LOCK_system_variables_hash;
 
366
pthread_rwlock_t        LOCK_system_variables_hash;
448
367
pthread_cond_t COND_refresh, COND_thread_count, COND_global_read_lock;
449
368
pthread_t signal_thread;
450
 
pthread_attr_t connection_attrib;
451
 
pthread_cond_t  COND_server_started;
452
 
 
453
 
/* replication parameters, if master_host is not NULL, we are a slave */
454
 
uint32_t report_port= DRIZZLE_PORT;
455
 
uint32_t master_retry_count= 0;
456
 
char *master_info_file;
457
 
char *relay_log_info_file, *report_user, *report_password, *report_host;
458
 
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
459
 
char *opt_logname;
 
369
pthread_cond_t  COND_server_end;
460
370
 
461
371
/* Static variables */
462
372
 
463
 
static bool kill_in_progress, segfaulted;
 
373
static bool segfaulted;
464
374
#ifdef HAVE_STACK_TRACE_ON_SEGV
465
375
static bool opt_do_pstack;
466
376
#endif /* HAVE_STACK_TRACE_ON_SEGV */
467
 
static int cleanup_done;
468
 
static uint32_t opt_myisam_block_size;
469
 
static char *opt_binlog_index_name;
470
 
static char *opt_tc_heuristic_recover;
471
 
static char *mysql_home_ptr, *pidfile_name_ptr;
 
377
int cleanup_done;
 
378
static char *drizzle_home_ptr, *pidfile_name_ptr;
472
379
static int defaults_argc;
473
380
static char **defaults_argv;
474
 
static char *opt_bin_logname;
475
 
 
476
 
struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD()
477
381
 
478
382
struct passwd *user_info;
479
383
static pthread_t select_thread;
480
384
static uint32_t thr_kill_signal;
481
385
 
482
 
/* OS specific variables */
483
 
 
484
 
bool mysqld_embedded=0;
485
 
 
486
 
scheduler_functions thread_scheduler;
487
 
 
488
386
/**
489
387
  Number of currently active user connections. The variable is protected by
490
 
  LOCK_connection_count.
491
 
*/
492
 
uint32_t connection_count= 0;
 
388
  LOCK_thread_count.
 
389
*/
 
390
drizzled::atomic<uint32_t> connection_count;
 
391
 
 
392
/** 
 
393
  Refresh value. We use to test this to find out if a refresh even has happened recently.
 
394
*/
 
395
drizzled::atomic<uint32_t> refresh_version;  /* Increments on each reload */
493
396
 
494
397
/* Function declarations */
 
398
bool drizzle_rm_tmp_tables();
495
399
 
496
 
pthread_handler_t signal_hand(void *arg);
497
 
static void mysql_init_variables(void);
 
400
extern "C" pthread_handler_t signal_hand(void *arg);
 
401
static void drizzle_init_variables(void);
498
402
static void get_options(int *argc,char **argv);
499
 
extern "C" bool mysqld_get_one_option(int, const struct my_option *, char *);
500
 
static void set_server_version(void);
 
403
extern "C" bool drizzled_get_one_option(int, const struct my_option *, char *);
501
404
static int init_thread_environment();
502
 
static char *get_relative_path(const char *path);
 
405
static const char *get_relative_path(const char *path);
503
406
static void fix_paths(void);
504
 
void handle_connections_sockets();
505
 
pthread_handler_t kill_server_thread(void *arg);
506
 
pthread_handler_t handle_slave(void *arg);
507
 
static uint32_t find_bit_type(const char *x, TYPELIB *bit_lib);
508
 
static uint32_t find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
509
 
                                   const char *option);
 
407
extern "C" pthread_handler_t handle_slave(void *arg);
510
408
static void clean_up(bool print_message);
511
409
 
512
410
static void usage(void);
513
 
static void start_signal_handler(void);
514
 
static void close_server_sock();
515
411
static void clean_up_mutexes(void);
516
 
static void wait_for_signal_thread_to_end(void);
517
 
static void create_pid_file();
518
 
static void mysqld_exit(int exit_code) __attribute__((noreturn));
519
 
 
 
412
extern "C" void end_thread_signal(int );
 
413
void close_connections(void);
 
414
extern "C" void print_signal_warning(int sig);
 
415
 
520
416
/****************************************************************************
521
 
** Code to end mysqld
 
417
** Code to end drizzled
522
418
****************************************************************************/
523
419
 
524
 
static void close_connections(void)
 
420
void close_connections(void)
525
421
{
526
 
#ifdef EXTRA_DEBUG
527
 
  int count=0;
528
 
#endif
529
 
 
530
 
  /* Clear thread cache */
531
 
  kill_cached_threads++;
532
 
  flush_thread_cache();
 
422
  /* Abort listening to new connections */
 
423
  plugin::Listen::shutdown();
533
424
 
534
425
  /* kill connection thread */
535
426
  (void) pthread_mutex_lock(&LOCK_thread_count);
539
430
    struct timespec abstime;
540
431
    int error;
541
432
 
542
 
#ifndef DONT_USE_THR_ALARM
543
 
    if (pthread_kill(select_thread, thr_client_alarm))
544
 
      break;                                    // allready dead
545
 
#endif
546
433
    set_timespec(abstime, 2);
547
434
    for (uint32_t tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
548
435
    {
549
 
      error=pthread_cond_timedwait(&COND_thread_count,&LOCK_thread_count,
550
 
                                   &abstime);
 
436
      error=pthread_cond_timedwait(&COND_thread_count,&LOCK_thread_count, &abstime);
551
437
      if (error != EINTR)
552
 
        break;
 
438
        break;
553
439
    }
554
 
#ifdef EXTRA_DEBUG
555
 
    if (error != 0 && !count++)
556
 
      sql_print_error(_("Got error %d from pthread_cond_timedwait"),error);
557
 
#endif
558
 
    close_server_sock();
559
440
  }
560
441
  (void) pthread_mutex_unlock(&LOCK_thread_count);
561
442
 
562
443
 
563
 
  /* Abort listening to new connections */
564
 
  {
565
 
    int x;
566
 
 
567
 
    for (x= 0; x < pollfd_count; x++)
568
 
    {
569
 
      if (fds[x].fd != -1)
570
 
      {
571
 
        (void) shutdown(fds[x].fd, SHUT_RDWR);
572
 
        (void) close(fds[x].fd);
573
 
        fds[x].fd= -1;
574
 
      }
575
 
    }
576
 
  }
577
 
 
578
 
  end_thr_alarm(0);                      // Abort old alarms.
579
 
 
580
444
  /*
581
445
    First signal all threads that it's time to die
582
446
    This will give the threads some time to gracefully abort their
583
447
    statements and inform their clients that the server is about to die.
584
448
  */
585
449
 
586
 
  THD *tmp;
 
450
  Session *tmp;
 
451
 
587
452
  (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
588
453
 
589
 
  I_List_iterator<THD> it(threads);
590
 
  while ((tmp=it++))
 
454
  for( vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it )
591
455
  {
592
 
    /* We skip slave threads & scheduler on this first loop through. */
593
 
    if (tmp->slave_thread)
594
 
      continue;
595
 
 
596
 
    tmp->killed= THD::KILL_CONNECTION;
597
 
    thread_scheduler.post_kill_notification(tmp);
 
456
    tmp= *it;
 
457
    tmp->killed= Session::KILL_CONNECTION;
 
458
    tmp->scheduler->killSession(tmp);
 
459
    DRIZZLE_CONNECTION_DONE(tmp->thread_id);
598
460
    if (tmp->mysys_var)
599
461
    {
600
462
      tmp->mysys_var->abort=1;
601
463
      pthread_mutex_lock(&tmp->mysys_var->mutex);
602
464
      if (tmp->mysys_var->current_cond)
603
465
      {
604
 
        pthread_mutex_lock(tmp->mysys_var->current_mutex);
605
 
        pthread_cond_broadcast(tmp->mysys_var->current_cond);
606
 
        pthread_mutex_unlock(tmp->mysys_var->current_mutex);
 
466
        pthread_mutex_lock(tmp->mysys_var->current_mutex);
 
467
        pthread_cond_broadcast(tmp->mysys_var->current_cond);
 
468
        pthread_mutex_unlock(tmp->mysys_var->current_mutex);
607
469
      }
608
470
      pthread_mutex_unlock(&tmp->mysys_var->mutex);
609
471
    }
610
472
  }
611
473
  (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
612
474
 
613
 
  end_slave();
614
 
 
615
 
  if (thread_count)
616
 
    sleep(2);                                   // Give threads time to die
 
475
  if (connection_count)
 
476
    sleep(2);                                   // Give threads time to die
617
477
 
618
478
  /*
619
479
    Force remaining threads to die by closing the connection to the client
620
480
    This will ensure that threads that are waiting for a command from the
621
481
    client on a blocking read call are aborted.
622
482
  */
623
 
 
624
483
  for (;;)
625
484
  {
626
485
    (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
627
 
    if (!(tmp=threads.get()))
 
486
    if (session_list.empty())
628
487
    {
629
488
      (void) pthread_mutex_unlock(&LOCK_thread_count);
630
489
      break;
631
490
    }
632
 
    if (tmp->vio_ok())
633
 
    {
634
 
      if (global_system_variables.log_warnings)
635
 
        sql_print_warning(ER(ER_FORCING_CLOSE),my_progname,
636
 
                          tmp->thread_id,
637
 
                          (tmp->main_security_ctx.user ?
638
 
                           tmp->main_security_ctx.user : ""));
639
 
      close_connection(tmp,0,0);
640
 
    }
 
491
    tmp= session_list.front();
641
492
    (void) pthread_mutex_unlock(&LOCK_thread_count);
642
 
  }
643
 
  /* All threads has now been aborted */
644
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
645
 
  while (thread_count)
646
 
  {
647
 
    (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
648
 
  }
649
 
  (void) pthread_mutex_unlock(&LOCK_thread_count);
650
 
 
651
 
  return;;
652
 
}
653
 
 
654
 
 
655
 
static void close_server_sock()
656
 
{
657
 
#ifdef HAVE_CLOSE_SERVER_SOCK
658
 
  {
659
 
    int x;
660
 
 
661
 
    for (x= 0; x < pollfd_count; x++)
662
 
    {
663
 
      if (fds[x].fd != -1)
664
 
      {
665
 
        (void) shutdown(fds[x].fd, SHUT_RDWR);
666
 
        (void) close(fds[x].fd);
667
 
        fds[x].fd= -1;
668
 
      }
669
 
    }
670
 
  }
671
 
#endif
672
 
}
673
 
 
674
 
 
675
 
void kill_mysql(void)
676
 
{
677
 
 
678
 
#if defined(SIGNALS_DONT_BREAK_READ)
679
 
  abort_loop=1;                                 // Break connection loops
680
 
  close_server_sock();                          // Force accept to wake up
681
 
#endif
682
 
 
683
 
#if defined(HAVE_PTHREAD_KILL)
684
 
  pthread_kill(signal_thread, DRIZZLE_KILL_SIGNAL);
685
 
#elif !defined(SIGNALS_DONT_BREAK_READ)
686
 
  kill(current_pid, DRIZZLE_KILL_SIGNAL);
687
 
#endif
688
 
  shutdown_in_progress=1;                       // Safety if kill didn't work
689
 
#ifdef SIGNALS_DONT_BREAK_READ
690
 
  if (!kill_in_progress)
691
 
  {
692
 
    pthread_t tmp;
693
 
    abort_loop=1;
694
 
    if (pthread_create(&tmp,&connection_attrib, kill_server_thread,
695
 
                           (void*) 0))
696
 
      sql_print_error(_("Can't create thread to kill server"));
697
 
  }
698
 
#endif
699
 
  return;;
700
 
}
701
 
 
702
 
/**
703
 
  Force server down. Kill all connections and threads and exit.
704
 
 
705
 
  @param  sig_ptr       Signal number that caused kill_server to be called.
706
 
 
707
 
  @note
708
 
    A signal number of 0 mean that the function was not called
709
 
    from a signal handler and there is thus no signal to block
710
 
    or stop, we just want to kill the server.
711
 
*/
712
 
 
713
 
static void *kill_server(void *sig_ptr)
714
 
#define RETURN_FROM_KILL_SERVER return(0)
715
 
{
716
 
  int sig=(int) (long) sig_ptr;                 // This is passed a int
717
 
  // if there is a signal during the kill in progress, ignore the other
718
 
  if (kill_in_progress)                         // Safety
719
 
    RETURN_FROM_KILL_SERVER;
720
 
  kill_in_progress=true;
721
 
  abort_loop=1;                                 // This should be set
722
 
  if (sig != 0) // 0 is not a valid signal number
723
 
    my_sigset(sig, SIG_IGN);                    /* purify inspected */
724
 
  if (sig == DRIZZLE_KILL_SIGNAL || sig == 0)
725
 
    sql_print_information(_(ER(ER_NORMAL_SHUTDOWN)),my_progname);
726
 
  else
727
 
    sql_print_error(_(ER(ER_GOT_SIGNAL)),my_progname,sig); /* purecov: inspected */
728
 
 
729
 
  close_connections();
730
 
  if (sig != DRIZZLE_KILL_SIGNAL &&
731
 
      sig != 0)
732
 
    unireg_abort(1);                            /* purecov: inspected */
733
 
  else
734
 
    unireg_end();
735
 
 
736
 
  /* purecov: begin deadcode */
737
 
 
738
 
  my_thread_end();
739
 
  pthread_exit(0);
740
 
  /* purecov: end */
741
 
 
742
 
  RETURN_FROM_KILL_SERVER;
743
 
}
744
 
 
745
 
 
746
 
#if defined(USE_ONE_SIGNAL_HAND)
747
 
pthread_handler_t kill_server_thread(void *arg __attribute__((unused)))
748
 
{
749
 
  my_thread_init();                             // Initialize new thread
750
 
  kill_server(0);
751
 
  /* purecov: begin deadcode */
752
 
  my_thread_end();
753
 
  pthread_exit(0);
754
 
  return 0;
755
 
  /* purecov: end */
756
 
}
757
 
#endif
758
 
 
759
 
 
760
 
extern "C" RETSIGTYPE print_signal_warning(int sig)
 
493
    tmp->client->close();
 
494
  }
 
495
}
 
496
 
 
497
 
 
498
void print_signal_warning(int sig)
761
499
{
762
500
  if (global_system_variables.log_warnings)
763
 
    sql_print_warning(_("Got signal %d from thread %lud"), sig,my_thread_id());
 
501
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64), sig,my_thread_id());
764
502
#ifndef HAVE_BSD_SIGNALS
765
503
  my_sigset(sig,print_signal_warning);          /* int. thread system calls */
766
504
#endif
772
510
  cleanup all memory and end program nicely.
773
511
 
774
512
    If SIGNALS_DONT_BREAK_READ is defined, this function is called
775
 
    by the main thread. To get MySQL to shut down nicely in this case
 
513
    by the main thread. To get Drizzle to shut down nicely in this case
776
514
    (Mac OS X) we have to call exit() instead if pthread_exit().
777
515
 
778
516
  @note
790
528
}
791
529
 
792
530
 
793
 
extern "C" void unireg_abort(int exit_code)
 
531
void unireg_abort(int exit_code)
794
532
{
795
533
 
796
534
  if (exit_code)
797
 
    sql_print_error(_("Aborting\n"));
798
 
  else if (opt_help)
 
535
    errmsg_printf(ERRMSG_LVL_ERROR, _("Aborting\n"));
 
536
  else if (opt_help || opt_help_extended)
799
537
    usage();
800
 
  clean_up(!opt_help && (exit_code)); /* purecov: inspected */
801
 
  mysqld_exit(exit_code);
802
 
}
803
 
 
804
 
 
805
 
static void mysqld_exit(int exit_code)
806
 
{
807
 
  wait_for_signal_thread_to_end();
 
538
  clean_up(!opt_help && (exit_code));
808
539
  clean_up_mutexes();
809
540
  my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
810
 
  exit(exit_code); /* purecov: inspected */
 
541
  exit(exit_code);
811
542
}
812
543
 
813
544
 
814
 
void clean_up(bool print_message)
 
545
static void clean_up(bool print_message)
815
546
{
 
547
  plugin::Registry &plugins= plugin::Registry::singleton();
816
548
  if (cleanup_done++)
817
 
    return; /* purecov: inspected */
818
 
 
819
 
  logger.cleanup_base();
820
 
 
821
 
  mysql_bin_log.cleanup();
822
 
 
823
 
  if (use_slave_mask)
824
 
    bitmap_free(&slave_error_mask);
825
 
  my_database_names_free();
 
549
    return;
 
550
 
826
551
  table_cache_free();
827
 
  table_def_free();
828
 
  lex_free();                           /* Free some memory */
829
 
  item_create_cleanup();
 
552
  TableShare::cacheStop();
830
553
  set_var_free();
831
554
  free_charsets();
832
 
  udf_free();
833
 
  plugin_shutdown();
 
555
  plugin_shutdown(plugins);
834
556
  ha_end();
835
 
  if (tc_log)
836
 
    tc_log->close();
837
557
  xid_cache_free();
838
 
  delete_elements(&key_caches, (void (*)(const char*, unsigned char*)) free_key_cache);
839
 
  multi_keycache_free();
840
558
  free_status_vars();
841
 
  end_thr_alarm(1);                     /* Free allocated memory */
842
 
  my_free_open_file_info();
843
 
  free((char*) global_system_variables.date_format);
844
 
  free((char*) global_system_variables.time_format);
845
 
  free((char*) global_system_variables.datetime_format);
846
559
  if (defaults_argv)
847
560
    free_defaults(defaults_argv);
848
 
  free(sys_init_connect.value);
849
 
  free(sys_init_slave.value);
850
 
  free_tmpdir(&mysql_tmpdir_list);
851
 
  free(slave_load_tmpdir);
852
 
  if (opt_bin_logname)
853
 
    free(opt_bin_logname);
854
 
  if (opt_relay_logname)
855
 
    free(opt_relay_logname);
 
561
  free(drizzle_tmpdir);
856
562
  if (opt_secure_file_priv)
857
563
    free(opt_secure_file_priv);
858
 
  bitmap_free(&temp_pool);
859
 
  end_slave_list();
860
 
  delete binlog_filter;
861
 
  delete rpl_filter;
862
 
 
863
 
  (void) my_delete(pidfile_name,MYF(0));        // This may not always exist
 
564
 
 
565
  deinit_temporal_formats();
 
566
 
 
567
#if GOOGLE_PROTOBUF_VERSION >= 2001000
 
568
  google::protobuf::ShutdownProtobufLibrary();
 
569
#endif
 
570
 
 
571
  (void) unlink(pidfile_name);  // This may not always exist
864
572
 
865
573
  if (print_message && server_start_time)
866
 
    sql_print_information(_(ER(ER_SHUTDOWN_COMPLETE)),my_progname);
867
 
  thread_scheduler.end();
 
574
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),my_progname);
868
575
  /* Returns NULL on globerrs, we don't want to try to free that */
869
576
  //void *freeme=
870
577
  (void *)my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST);
871
578
  // TODO!!!! EPIC FAIL!!!! This sefaults if uncommented.
872
579
/*  if (freeme != NULL)
873
580
    free(freeme);  */
874
 
  /* Tell main we are ready */
875
 
  logger.cleanup_end();
876
581
  (void) pthread_mutex_lock(&LOCK_thread_count);
877
582
  ready_to_exit=1;
878
583
  /* do the broadcast inside the lock to ensure that my_end() is not called */
879
 
  (void) pthread_cond_broadcast(&COND_thread_count);
 
584
  (void) pthread_cond_broadcast(&COND_server_end);
880
585
  (void) pthread_mutex_unlock(&LOCK_thread_count);
881
586
 
882
587
  /*
886
591
} /* clean_up */
887
592
 
888
593
 
889
 
/**
890
 
  This is mainly needed when running with purify, but it's still nice to
891
 
  know that all child threads have died when mysqld exits.
892
 
*/
893
 
static void wait_for_signal_thread_to_end()
894
 
{
895
 
  uint32_t i;
896
 
  /*
897
 
    Wait up to 10 seconds for signal thread to die. We use this mainly to
898
 
    avoid getting warnings that my_thread_end has not been called
899
 
  */
900
 
  for (i= 0 ; i < 100 && signal_thread_in_use; i++)
901
 
  {
902
 
    if (pthread_kill(signal_thread, DRIZZLE_KILL_SIGNAL) != ESRCH)
903
 
      break;
904
 
    my_sleep(100);                              // Give it time to die
905
 
  }
906
 
}
907
 
 
908
 
 
909
594
static void clean_up_mutexes()
910
595
{
911
 
  (void) pthread_mutex_destroy(&LOCK_mysql_create_db);
912
 
  (void) pthread_mutex_destroy(&LOCK_lock_db);
 
596
  (void) pthread_mutex_destroy(&LOCK_create_db);
913
597
  (void) pthread_mutex_destroy(&LOCK_open);
914
598
  (void) pthread_mutex_destroy(&LOCK_thread_count);
915
599
  (void) pthread_mutex_destroy(&LOCK_status);
916
 
  (void) pthread_mutex_destroy(&LOCK_error_log);
917
 
  (void) pthread_mutex_destroy(&LOCK_user_conn);
918
 
  (void) pthread_mutex_destroy(&LOCK_connection_count);
919
 
  (void) pthread_mutex_destroy(&LOCK_rpl_status);
920
 
  (void) pthread_cond_destroy(&COND_rpl_status);
921
 
  (void) pthread_mutex_destroy(&LOCK_active_mi);
922
 
  (void) rwlock_destroy(&LOCK_sys_init_connect);
923
 
  (void) rwlock_destroy(&LOCK_sys_init_slave);
924
600
  (void) pthread_mutex_destroy(&LOCK_global_system_variables);
925
 
  (void) rwlock_destroy(&LOCK_system_variables_hash);
 
601
  (void) pthread_rwlock_destroy(&LOCK_system_variables_hash);
926
602
  (void) pthread_mutex_destroy(&LOCK_global_read_lock);
927
 
  (void) pthread_mutex_destroy(&LOCK_uuid_generator);
928
603
  (void) pthread_cond_destroy(&COND_thread_count);
 
604
  (void) pthread_cond_destroy(&COND_server_end);
929
605
  (void) pthread_cond_destroy(&COND_refresh);
930
606
  (void) pthread_cond_destroy(&COND_global_read_lock);
931
 
  (void) pthread_cond_destroy(&COND_thread_cache);
932
 
  (void) pthread_cond_destroy(&COND_flush_thread_cache);
933
607
}
934
608
 
935
609
 
936
 
/****************************************************************************
937
 
** Init IP and UNIX socket
938
 
****************************************************************************/
939
 
 
940
 
static void set_ports()
 
610
/**
 
611
 * Setup default port value from (in order or precedence):
 
612
 * - Command line option
 
613
 * - DRIZZLE_TCP_PORT environment variable
 
614
 * - Compile options
 
615
 * - Lookup in /etc/services
 
616
 * - Default value
 
617
 */
 
618
static void set_default_port()
941
619
{
942
 
  char  *env;
943
 
  if (!mysqld_port)
944
 
  {                                     // Get port if not from commandline
945
 
    mysqld_port= DRIZZLE_PORT;
946
 
 
947
 
    /*
948
 
      if builder specifically requested a default port, use that
949
 
      (even if it coincides with our factory default).
950
 
      only if they didn't do we check /etc/services (and, failing
951
 
      on that, fall back to the factory default of 4427).
952
 
      either default can be overridden by the environment variable
953
 
      DRIZZLE_TCP_PORT, which in turn can be overridden with command
954
 
      line options.
955
 
    */
956
 
 
957
 
    struct  servent *serv_ptr;
958
 
    if ((serv_ptr= getservbyname("drizzle", "tcp")))
959
 
      mysqld_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
 
620
  struct servent *serv_ptr;
 
621
  char *env;
 
622
 
 
623
  if (drizzled_tcp_port == 0)
 
624
  {
 
625
    drizzled_tcp_port= DRIZZLE_TCP_PORT;
 
626
 
 
627
    if (DRIZZLE_TCP_PORT_DEFAULT == 0)
 
628
    {
 
629
      if ((serv_ptr= getservbyname("drizzle", "tcp")))
 
630
        drizzled_tcp_port= ntohs((u_short) serv_ptr->s_port);
 
631
    }
960
632
 
961
633
    if ((env = getenv("DRIZZLE_TCP_PORT")))
962
 
      mysqld_port= (uint) atoi(env);            /* purecov: inspected */
 
634
      drizzled_tcp_port= (uint32_t) atoi(env);
963
635
 
964
 
    assert(mysqld_port);
 
636
    assert(drizzled_tcp_port != 0);
965
637
  }
966
638
}
967
639
 
978
650
    if (user)
979
651
    {
980
652
      /* Don't give a warning, if real user is same as given with --user */
981
 
      /* purecov: begin tested */
982
653
      tmp_user_info= getpwnam(user);
983
654
      if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
984
655
          global_system_variables.log_warnings)
985
 
        sql_print_warning(_("One can only use the --user switch "
 
656
            errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
986
657
                            "if running as root\n"));
987
 
      /* purecov: end */
988
658
    }
989
659
    return NULL;
990
660
  }
991
661
  if (!user)
992
662
  {
993
 
    sql_print_error(_("Fatal error: Please read \"Security\" section of "
994
 
                      "the manual to find out how to run mysqld as root!\n"));
 
663
      errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
 
664
                      "the manual to find out how to run drizzled as root!\n"));
995
665
    unireg_abort(1);
996
 
 
997
 
    return NULL;
998
666
  }
999
 
  /* purecov: begin tested */
1000
667
  if (!strcmp(user,"root"))
1001
668
    return NULL;                        // Avoid problem with dynamic libraries
1002
669
 
1011
678
      goto err;
1012
679
  }
1013
680
  return tmp_user_info;
1014
 
  /* purecov: end */
1015
681
 
1016
682
err:
1017
 
  sql_print_error(_("Fatal error: Can't change to run as user '%s' ;  "
 
683
  errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Can't change to run as user '%s' ;  "
1018
684
                    "Please check that the user exists!\n"),user);
1019
685
  unireg_abort(1);
1020
686
 
1021
687
#ifdef PR_SET_DUMPABLE
1022
 
  if (test_flags & TEST_CORE_ON_SIGNAL)
 
688
  if (test_flags.test(TEST_CORE_ON_SIGNAL))
1023
689
  {
1024
690
    /* inform kernel that process is dumpable */
1025
691
    (void) prctl(PR_SET_DUMPABLE, 1);
1026
692
  }
1027
693
#endif
1028
694
 
 
695
/* Sun Studio 5.10 doesn't like this line.  5.9 requires it */
 
696
#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x590)
1029
697
  return NULL;
 
698
#endif
 
699
 
1030
700
}
1031
701
 
1032
702
static void set_user(const char *user, struct passwd *user_info_arg)
1033
703
{
1034
 
  /* purecov: begin tested */
1035
704
  assert(user_info_arg != 0);
1036
705
#ifdef HAVE_INITGROUPS
1037
706
  /*
1054
723
    sql_perror("setuid");
1055
724
    unireg_abort(1);
1056
725
  }
1057
 
  /* purecov: end */
1058
726
}
1059
727
 
1060
728
 
1077
745
/** Change root user if started with @c --chroot . */
1078
746
static void set_root(const char *path)
1079
747
{
1080
 
  if (chroot(path) == -1)
 
748
  if ((chroot(path) == -1) || !chdir("/"))
1081
749
  {
1082
750
    sql_perror("chroot");
1083
751
    unireg_abort(1);
1084
752
  }
1085
 
  my_setwd("/", MYF(0));
1086
 
}
1087
 
 
1088
 
 
1089
 
static void network_init(void)
1090
 
{
1091
 
  int   ret;
1092
 
  uint32_t  waited;
1093
 
  uint32_t  this_wait;
1094
 
  uint32_t  retry;
1095
 
  char port_buf[NI_MAXSERV];
1096
 
  struct addrinfo *ai;
1097
 
  struct addrinfo *next;
1098
 
  struct addrinfo hints;
1099
 
  int error;
1100
 
 
1101
 
  if (thread_scheduler.init())
1102
 
    unireg_abort(1);                    /* purecov: inspected */
1103
 
 
1104
 
  set_ports();
1105
 
 
1106
 
  memset(fds, 0, sizeof(struct pollfd) * UINT8_MAX);
1107
 
  memset(&hints, 0, sizeof (hints));
1108
 
  hints.ai_flags= AI_PASSIVE;
1109
 
  hints.ai_socktype= SOCK_STREAM;
1110
 
 
1111
 
  snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1112
 
  error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1113
 
  if (error != 0)
1114
 
  {
1115
 
    sql_perror(ER(ER_IPSOCK_ERROR));            /* purecov: tested */
1116
 
    unireg_abort(1);                            /* purecov: tested */
1117
 
  }
1118
 
 
1119
 
  for (next= ai, pollfd_count= 0; next; next= next->ai_next, pollfd_count++)
1120
 
  {
1121
 
    int ip_sock;
1122
 
 
1123
 
    ip_sock= socket(next->ai_family, next->ai_socktype, next->ai_protocol);
1124
 
 
1125
 
    if (ip_sock == -1)
1126
 
    {
1127
 
      sql_perror(ER(ER_IPSOCK_ERROR));          /* purecov: tested */
1128
 
      unireg_abort(1);                          /* purecov: tested */
1129
 
    }
1130
 
 
1131
 
    fds[pollfd_count].fd= ip_sock;
1132
 
    fds[pollfd_count].events= POLLIN | POLLERR;
1133
 
 
1134
 
    /* Add options for our listening socket */
1135
 
    {
1136
 
      int error;
1137
 
      struct linger ling = {0, 0};
1138
 
      int flags =1;
1139
 
 
1140
 
#ifdef IPV6_V6ONLY
1141
 
      if (next->ai_family == AF_INET6) 
1142
 
      {
1143
 
        error= setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &flags, sizeof(flags));
1144
 
        if (error != 0)
1145
 
        {
1146
 
          perror("setsockopt");
1147
 
          assert(error == 0);
1148
 
        }
1149
 
      }
1150
 
#endif   
1151
 
      error= setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&flags, sizeof(flags));
1152
 
      if (error != 0)
1153
 
      {
1154
 
        perror("setsockopt");
1155
 
        assert(error == 0);
1156
 
      }
1157
 
      error= setsockopt(ip_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
1158
 
      if (error != 0)
1159
 
      {
1160
 
        perror("setsockopt");
1161
 
        assert(error == 0);
1162
 
      }
1163
 
      error= setsockopt(ip_sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling));
1164
 
      if (error != 0)
1165
 
      {
1166
 
        perror("setsockopt");
1167
 
        assert(error == 0);
1168
 
      }
1169
 
      error= setsockopt(ip_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
1170
 
      if (error != 0)
1171
 
      {
1172
 
        perror("setsockopt");
1173
 
        assert(error == 0);
1174
 
      }
1175
 
    }
1176
 
 
1177
 
 
1178
 
    /*
1179
 
      Sometimes the port is not released fast enough when stopping and
1180
 
      restarting the server. This happens quite often with the test suite
1181
 
      on busy Linux systems. Retry to bind the address at these intervals:
1182
 
      Sleep intervals: 1, 2, 4,  6,  9, 13, 17, 22, ...
1183
 
      Retry at second: 1, 3, 7, 13, 22, 35, 52, 74, ...
1184
 
      Limit the sequence by mysqld_port_timeout (set --port-open-timeout=#).
1185
 
    */
1186
 
    for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
1187
 
    {
1188
 
      if (((ret= bind(ip_sock, next->ai_addr, next->ai_addrlen)) >= 0 ) ||
1189
 
          (errno != EADDRINUSE) ||
1190
 
          (waited >= mysqld_port_timeout))
1191
 
        break;
1192
 
      sql_print_information(_("Retrying bind on TCP/IP port %u"), mysqld_port);
1193
 
      this_wait= retry * retry / 3 + 1;
1194
 
      sleep(this_wait);
1195
 
    }
1196
 
    if (ret < 0)
1197
 
    {
1198
 
      sql_perror(_("Can't start server: Bind on TCP/IP port"));
1199
 
      sql_print_error(_("Do you already have another drizzled server running "
1200
 
                        "on port: %d ?"),mysqld_port);
1201
 
      unireg_abort(1);
1202
 
    }
1203
 
    if (listen(ip_sock,(int) back_log) < 0)
1204
 
    {
1205
 
      sql_perror(_("Can't start server: listen() on TCP/IP port"));
1206
 
      sql_print_error(_("listen() on TCP/IP failed with error %d"),
1207
 
                      errno);
1208
 
      unireg_abort(1);
1209
 
    }
1210
 
  }
1211
 
 
1212
 
  freeaddrinfo(ai);
1213
 
  return;
1214
 
}
1215
 
 
1216
 
/**
1217
 
  Close a connection.
1218
 
 
1219
 
  @param thd            Thread handle
1220
 
  @param errcode        Error code to print to console
1221
 
  @param lock           1 if we have have to lock LOCK_thread_count
1222
 
 
1223
 
  @note
1224
 
    For the connection that is doing shutdown, this is called twice
1225
 
*/
1226
 
void close_connection(THD *thd, uint32_t errcode, bool lock)
1227
 
{
1228
 
  st_vio *vio;
1229
 
  if (lock)
1230
 
    (void) pthread_mutex_lock(&LOCK_thread_count);
1231
 
  thd->killed= THD::KILL_CONNECTION;
1232
 
  if ((vio= thd->net.vio) != 0)
1233
 
  {
1234
 
    if (errcode)
1235
 
      net_send_error(thd, errcode, ER(errcode)); /* purecov: inspected */
1236
 
    net_close(&(thd->net));             /* vio is freed in delete thd */
1237
 
  }
1238
 
  if (lock)
1239
 
    (void) pthread_mutex_unlock(&LOCK_thread_count);
1240
 
  return;;
1241
753
}
1242
754
 
1243
755
 
1244
756
/** Called when a thread is aborted. */
1245
 
/* ARGSUSED */
1246
 
extern "C" RETSIGTYPE end_thread_signal(int sig __attribute__((unused)))
 
757
void end_thread_signal(int )
1247
758
{
1248
 
  THD *thd=current_thd;
1249
 
  if (thd && ! thd->bootstrap)
 
759
  Session *session=current_session;
 
760
  if (session)
1250
761
  {
1251
762
    statistic_increment(killed_threads, &LOCK_status);
1252
 
    thread_scheduler.end_thread(thd,0);         /* purecov: inspected */
 
763
    session->scheduler->killSessionNow(session);
 
764
    DRIZZLE_CONNECTION_DONE(session->thread_id);
1253
765
  }
1254
 
  return;;                              /* purecov: deadcode */
 
766
  return;
1255
767
}
1256
768
 
1257
769
 
1258
770
/*
1259
 
  Unlink thd from global list of available connections and free thd
 
771
  Unlink session from global list of available connections and free session
1260
772
 
1261
773
  SYNOPSIS
1262
 
    unlink_thd()
1263
 
    thd          Thread handler
 
774
    unlink_session()
 
775
    session              Thread handler
1264
776
 
1265
777
  NOTES
1266
778
    LOCK_thread_count is locked and left locked
1267
779
*/
1268
780
 
1269
 
void unlink_thd(THD *thd)
1270
 
{
1271
 
  thd->cleanup();
1272
 
 
1273
 
  pthread_mutex_lock(&LOCK_connection_count);
1274
 
  --connection_count;
1275
 
  pthread_mutex_unlock(&LOCK_connection_count);
1276
 
 
1277
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
1278
 
  thread_count--;
1279
 
  delete thd;
1280
 
  return;;
1281
 
}
1282
 
 
1283
 
 
1284
 
/*
1285
 
  Store thread in cache for reuse by new connections
1286
 
 
1287
 
  SYNOPSIS
1288
 
    cache_thread()
1289
 
 
1290
 
  NOTES
1291
 
    LOCK_thread_count has to be locked
1292
 
 
1293
 
  RETURN
1294
 
    0  Thread was not put in cache
1295
 
    1  Thread is to be reused by new connection.
1296
 
       (ie, caller should return, not abort with pthread_exit())
1297
 
*/
1298
 
 
1299
 
 
1300
 
static bool cache_thread()
1301
 
{
1302
 
  safe_mutex_assert_owner(&LOCK_thread_count);
1303
 
  if (cached_thread_count < thread_cache_size &&
1304
 
      ! abort_loop && !kill_cached_threads)
1305
 
  {
1306
 
    /* Don't kill the thread, just put it in cache for reuse */
1307
 
    cached_thread_count++;
1308
 
    while (!abort_loop && ! wake_thread && ! kill_cached_threads)
1309
 
      (void) pthread_cond_wait(&COND_thread_cache, &LOCK_thread_count);
1310
 
    cached_thread_count--;
1311
 
    if (kill_cached_threads)
1312
 
      pthread_cond_signal(&COND_flush_thread_cache);
1313
 
    if (wake_thread)
1314
 
    {
1315
 
      THD *thd;
1316
 
      wake_thread--;
1317
 
      thd= thread_cache.get();
1318
 
      thd->thread_stack= (char*) &thd;          // For store_globals
1319
 
      (void) thd->store_globals();
1320
 
      /*
1321
 
        THD::mysys_var::abort is associated with physical thread rather
1322
 
        than with THD object. So we need to reset this flag before using
1323
 
        this thread for handling of new THD object/connection.
1324
 
      */
1325
 
      thd->mysys_var->abort= 0;
1326
 
      thd->thr_create_utime= my_micro_time();
1327
 
      threads.append(thd);
1328
 
      return(1);
1329
 
    }
1330
 
  }
1331
 
  return(0);
1332
 
}
1333
 
 
1334
 
 
1335
 
/*
1336
 
  End thread for the current connection
1337
 
 
1338
 
  SYNOPSIS
1339
 
    one_thread_per_connection_end()
1340
 
    thd           Thread handler
1341
 
    put_in_cache  Store thread in cache, if there is room in it
1342
 
                  Normally this is true in all cases except when we got
1343
 
                  out of resources initializing the current thread
1344
 
 
1345
 
  NOTES
1346
 
    If thread is cached, we will wait until thread is scheduled to be
1347
 
    reused and then we will return.
1348
 
    If thread is not cached, we end the thread.
1349
 
 
1350
 
  RETURN
1351
 
    0    Signal to handle_one_connection to reuse connection
1352
 
*/
1353
 
 
1354
 
bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
1355
 
{
1356
 
  unlink_thd(thd);
1357
 
  if (put_in_cache)
1358
 
    put_in_cache= cache_thread();
1359
 
  pthread_mutex_unlock(&LOCK_thread_count);
1360
 
  if (put_in_cache)
1361
 
    return(0);                             // Thread is reused
1362
 
 
1363
 
  /* It's safe to broadcast outside a lock (COND... is not deleted here) */
1364
 
  my_thread_end();
1365
 
  (void) pthread_cond_broadcast(&COND_thread_count);
1366
 
 
1367
 
  pthread_exit(0);
1368
 
  return(0);                               // Impossible
1369
 
}
1370
 
 
1371
 
 
1372
 
void flush_thread_cache()
1373
 
{
1374
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
1375
 
  kill_cached_threads++;
1376
 
  while (cached_thread_count)
1377
 
  {
1378
 
    pthread_cond_broadcast(&COND_thread_cache);
1379
 
    pthread_cond_wait(&COND_flush_thread_cache,&LOCK_thread_count);
1380
 
  }
1381
 
  kill_cached_threads--;
 
781
void unlink_session(Session *session)
 
782
{
 
783
  connection_count--;
 
784
 
 
785
  session->cleanup();
 
786
 
 
787
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
788
  pthread_mutex_lock(&session->LOCK_delete);
 
789
 
 
790
  session_list.erase(remove(session_list.begin(),
 
791
                     session_list.end(),
 
792
                     session));
 
793
 
 
794
  delete session;
1382
795
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
796
 
 
797
  return;
1383
798
}
1384
799
 
1385
800
 
1390
805
  @todo
1391
806
    One should have to fix that thr_alarm know about this thread too.
1392
807
*/
1393
 
extern "C" RETSIGTYPE abort_thread(int sig __attribute__((unused)))
 
808
extern "C" void abort_thread(int )
1394
809
{
1395
 
  THD *thd=current_thd;
1396
 
  if (thd)
1397
 
    thd->killed= THD::KILL_CONNECTION;
 
810
  Session *session=current_session;
 
811
  if (session)
 
812
    session->killed= Session::KILL_CONNECTION;
1398
813
  return;;
1399
814
}
1400
815
#endif
1401
816
 
1402
 
#if BACKTRACE_DEMANGLE
 
817
#if defined(BACKTRACE_DEMANGLE)
1403
818
#include <cxxabi.h>
1404
819
extern "C" char *my_demangle(const char *mangled_name, int *status)
1405
820
{
1408
823
#endif
1409
824
 
1410
825
 
1411
 
extern "C" RETSIGTYPE handle_segfault(int sig)
 
826
extern "C" void handle_segfault(int sig)
1412
827
{
1413
828
  time_t curr_time;
1414
829
  struct tm tm;
1421
836
  */
1422
837
  if (segfaulted)
1423
838
  {
1424
 
    fprintf(stderr, _("Fatal " SIGNAL_FMT " while backtracing\n"), sig);
 
839
    fprintf(stderr, _("Fatal signal %d while backtracing\n"), sig);
1425
840
    exit(1);
1426
841
  }
1427
842
 
1428
843
  segfaulted = 1;
1429
844
 
1430
 
  curr_time= my_time(0);
 
845
  curr_time= time(NULL);
 
846
  if(curr_time == (time_t)-1)
 
847
  {
 
848
    fprintf(stderr, "Fetal: time() call failed\n");
 
849
    exit(1);
 
850
  }
 
851
 
1431
852
  localtime_r(&curr_time, &tm);
1432
 
 
1433
 
  fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d - mysqld got "
1434
 
          SIGNAL_FMT " ;\n"
 
853
  
 
854
  fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d - drizzled got signal %d;\n"
1435
855
          "This could be because you hit a bug. It is also possible that "
1436
856
          "this binary\n or one of the libraries it was linked against is "
1437
857
          "corrupt, improperly built,\n or misconfigured. This error can "
1447
867
          (uint32_t) dflt_key_cache->key_cache_mem_size);
1448
868
  fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
1449
869
  fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
1450
 
  fprintf(stderr, "max_threads=%u\n", thread_scheduler.max_threads);
1451
 
  fprintf(stderr, "thread_count=%u\n", thread_count);
1452
 
  fprintf(stderr, "connection_count=%u\n", connection_count);
1453
 
  fprintf(stderr, _("It is possible that mysqld could use up to \n"
 
870
  fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
 
871
  fprintf(stderr, _("It is possible that drizzled could use up to \n"
1454
872
                    "key_buffer_size + (read_buffer_size + "
1455
 
                    "sort_buffer_size)*max_threads = %lu K\n"
 
873
                    "sort_buffer_size)*thread_count\n"
1456
874
                    "bytes of memory\n"
1457
875
                    "Hope that's ok; if not, decrease some variables in the "
1458
 
                    "equation.\n\n"),
1459
 
                    ((uint32_t) dflt_key_cache->key_cache_mem_size +
1460
 
                     (global_system_variables.read_buff_size +
1461
 
                      global_system_variables.sortbuff_size) *
1462
 
                     thread_scheduler.max_threads +
1463
 
                     max_connections * sizeof(THD)) / 1024);
 
876
                    "equation.\n\n"));
1464
877
 
1465
878
#ifdef HAVE_STACKTRACE
1466
 
  THD *thd= current_thd;
 
879
  Session *session= current_session;
1467
880
 
1468
 
  if (!(test_flags & TEST_NO_STACKTRACE))
 
881
  if (! (test_flags.test(TEST_NO_STACKTRACE)))
1469
882
  {
1470
 
    fprintf(stderr,"thd: 0x%lx\n",(long) thd);
 
883
    fprintf(stderr,"session: 0x%lx\n",(long) session);
1471
884
    fprintf(stderr,_("Attempting backtrace. You can use the following "
1472
885
                     "information to find out\n"
1473
 
                     "where mysqld died. If you see no messages after this, "
 
886
                     "where drizzled died. If you see no messages after this, "
1474
887
                     "something went\n"
1475
888
                     "terribly wrong...\n"));
1476
 
    print_stacktrace(thd ? (unsigned char*) thd->thread_stack : (unsigned char*) 0,
 
889
    print_stacktrace(session ? (unsigned char*) session->thread_stack : (unsigned char*) 0,
1477
890
                     my_thread_stack_size);
1478
891
  }
1479
 
  if (thd)
 
892
  if (session)
1480
893
  {
1481
894
    const char *kreason= "UNKNOWN";
1482
 
    switch (thd->killed) {
1483
 
    case THD::NOT_KILLED:
 
895
    switch (session->killed) {
 
896
    case Session::NOT_KILLED:
1484
897
      kreason= "NOT_KILLED";
1485
898
      break;
1486
 
    case THD::KILL_BAD_DATA:
 
899
    case Session::KILL_BAD_DATA:
1487
900
      kreason= "KILL_BAD_DATA";
1488
901
      break;
1489
 
    case THD::KILL_CONNECTION:
 
902
    case Session::KILL_CONNECTION:
1490
903
      kreason= "KILL_CONNECTION";
1491
904
      break;
1492
 
    case THD::KILL_QUERY:
 
905
    case Session::KILL_QUERY:
1493
906
      kreason= "KILL_QUERY";
1494
907
      break;
1495
 
    case THD::KILLED_NO_VALUE:
 
908
    case Session::KILLED_NO_VALUE:
1496
909
      kreason= "KILLED_NO_VALUE";
1497
910
      break;
1498
911
    }
1499
912
    fprintf(stderr, _("Trying to get some variables.\n"
1500
913
                      "Some pointers may be invalid and cause the "
1501
914
                      "dump to abort...\n"));
1502
 
    safe_print_str("thd->query", thd->query, 1024);
1503
 
    fprintf(stderr, "thd->thread_id=%"PRIu32"\n", (uint32_t) thd->thread_id);
1504
 
    fprintf(stderr, "thd->killed=%s\n", kreason);
 
915
    safe_print_str("session->query", session->query, 1024);
 
916
    fprintf(stderr, "session->thread_id=%"PRIu32"\n", (uint32_t) session->thread_id);
 
917
    fprintf(stderr, "session->killed=%s\n", kreason);
1505
918
  }
1506
919
  fflush(stderr);
1507
920
#endif /* HAVE_STACKTRACE */
1508
921
 
1509
922
#ifdef HAVE_INITGROUPS
1510
923
  if (calling_initgroups)
1511
 
    fprintf(stderr, _("\nThis crash occured while the server was calling "
 
924
    fprintf(stderr, _("\nThis crash occurred while the server was calling "
1512
925
                      "initgroups(). This is\n"
1513
926
                      "often due to the use of a drizzled that is statically "
1514
927
                      "linked against glibc\n"
1549
962
  }
1550
963
 
1551
964
#ifdef HAVE_WRITE_CORE
1552
 
  if (test_flags & TEST_CORE_ON_SIGNAL)
 
965
  if (test_flags.test(TEST_CORE_ON_SIGNAL))
1553
966
  {
1554
967
    fprintf(stderr, _("Writing a core file\n"));
1555
968
    fflush(stderr);
1572
985
  sigset_t set;
1573
986
  struct sigaction sa;
1574
987
 
1575
 
  my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called!
1576
 
 
1577
 
  if (!(test_flags & TEST_NO_STACKTRACE) || (test_flags & TEST_CORE_ON_SIGNAL))
 
988
  if (!(test_flags.test(TEST_NO_STACKTRACE) || 
 
989
        test_flags.test(TEST_CORE_ON_SIGNAL)))
1578
990
  {
1579
991
    sa.sa_flags = SA_RESETHAND | SA_NODEFER;
1580
992
    sigemptyset(&sa.sa_mask);
1592
1004
  }
1593
1005
 
1594
1006
#ifdef HAVE_GETRLIMIT
1595
 
  if (test_flags & TEST_CORE_ON_SIGNAL)
 
1007
  if (test_flags.test(TEST_CORE_ON_SIGNAL))
1596
1008
  {
1597
1009
    /* Change limits so that we will get a core file */
1598
 
    STRUCT_RLIMIT rl;
 
1010
    struct rlimit rl;
1599
1011
    rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
1600
1012
    if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
1601
 
      sql_print_warning(_("setrlimit could not change the size of core files "
 
1013
        errmsg_printf(ERRMSG_LVL_WARN, _("setrlimit could not change the size of core files "
1602
1014
                          "to 'infinity';  We may not be able to generate a "
1603
1015
                          "core file on signals"));
1604
1016
  }
1623
1035
#ifdef SIGTSTP
1624
1036
  sigaddset(&set,SIGTSTP);
1625
1037
#endif
1626
 
  if (thd_lib_detected != THD_LIB_LT)
1627
 
    sigaddset(&set,THR_SERVER_ALARM);
1628
 
  if (test_flags & TEST_SIGINT)
 
1038
  if (test_flags.test(TEST_SIGINT))
1629
1039
  {
1630
1040
    my_sigset(thr_kill_signal, end_thread_signal);
1631
1041
    // May be SIGINT
1638
1048
  return;;
1639
1049
}
1640
1050
 
1641
 
 
1642
 
static void start_signal_handler(void)
1643
 
{
1644
 
  int error;
1645
 
  pthread_attr_t thr_attr;
1646
 
 
1647
 
  (void) pthread_attr_init(&thr_attr);
1648
 
  pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
1649
 
  (void) pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
1650
 
  {
1651
 
    struct sched_param tmp_sched_param;
1652
 
 
1653
 
    memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
1654
 
    tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
1655
 
    (void)pthread_attr_setschedparam(&thr_attr, &tmp_sched_param);
1656
 
  }
1657
 
#if defined(__ia64__) || defined(__ia64)
1658
 
  /*
1659
 
    Peculiar things with ia64 platforms - it seems we only have half the
1660
 
    stack size in reality, so we have to double it here
1661
 
  */
1662
 
  pthread_attr_setstacksize(&thr_attr,my_thread_stack_size*2);
1663
 
#else
1664
 
  pthread_attr_setstacksize(&thr_attr,my_thread_stack_size);
1665
 
 
1666
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
1667
 
  if ((error=pthread_create(&signal_thread,&thr_attr,signal_hand,0)))
1668
 
  {
1669
 
    sql_print_error(_("Can't create interrupt-thread (error %d, errno: %d)"),
1670
 
                    error,errno);
1671
 
    exit(1);
1672
 
  }
1673
 
  (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
1674
 
  pthread_mutex_unlock(&LOCK_thread_count);
1675
 
 
1676
 
  (void) pthread_attr_destroy(&thr_attr);
1677
 
  return;;
1678
 
}
1679
 
 
1680
 
 
1681
 
/** This threads handles all signals and alarms. */
1682
 
/* ARGSUSED */
1683
 
pthread_handler_t signal_hand(void *arg __attribute__((unused)))
1684
 
{
1685
 
  sigset_t set;
1686
 
  int sig;
1687
 
  my_thread_init();                             // Init new thread
1688
 
  signal_thread_in_use= 1;
1689
 
 
1690
 
  /*
1691
 
    Setup alarm handler
1692
 
    This should actually be '+ max_number_of_slaves' instead of +10,
1693
 
    but the +10 should be quite safe.
1694
 
  */
1695
 
  init_thr_alarm(thread_scheduler.max_threads + 10);
1696
 
  if (thd_lib_detected != THD_LIB_LT && (test_flags & TEST_SIGINT))
1697
 
  {
1698
 
    (void) sigemptyset(&set);                   // Setup up SIGINT for debug
1699
 
    (void) sigaddset(&set,SIGINT);              // For debugging
1700
 
    (void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
1701
 
  }
1702
 
  (void) sigemptyset(&set);                     // Setup up SIGINT for debug
1703
 
#ifdef USE_ONE_SIGNAL_HAND
1704
 
  (void) sigaddset(&set,THR_SERVER_ALARM);      // For alarms
1705
 
#endif
1706
 
#ifndef IGNORE_SIGHUP_SIGQUIT
1707
 
  (void) sigaddset(&set,SIGQUIT);
1708
 
  (void) sigaddset(&set,SIGHUP);
1709
 
#endif
1710
 
  (void) sigaddset(&set,SIGTERM);
1711
 
  (void) sigaddset(&set,SIGTSTP);
1712
 
 
1713
 
  /* Save pid to this process (or thread on Linux) */
1714
 
  create_pid_file();
1715
 
 
1716
 
#ifdef HAVE_STACK_TRACE_ON_SEGV
1717
 
  if (opt_do_pstack)
1718
 
  {
1719
 
    sprintf(pstack_file_name,"mysqld-%lu-%%d-%%d.backtrace", (uint32_t)getpid());
1720
 
    pstack_install_segv_action(pstack_file_name);
1721
 
  }
1722
 
#endif /* HAVE_STACK_TRACE_ON_SEGV */
1723
 
 
1724
 
  /*
1725
 
    signal to start_signal_handler that we are ready
1726
 
    This works by waiting for start_signal_handler to free mutex,
1727
 
    after which we signal it that we are ready.
1728
 
    At this pointer there is no other threads running, so there
1729
 
    should not be any other pthread_cond_signal() calls.
1730
 
  */
1731
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
1732
 
  (void) pthread_mutex_unlock(&LOCK_thread_count);
1733
 
  (void) pthread_cond_broadcast(&COND_thread_count);
1734
 
 
1735
 
  (void) pthread_sigmask(SIG_BLOCK,&set,NULL);
1736
 
  for (;;)
1737
 
  {
1738
 
    int error;                                  // Used when debugging
1739
 
    if (shutdown_in_progress && !abort_loop)
1740
 
    {
1741
 
      sig= SIGTERM;
1742
 
      error=0;
1743
 
    }
1744
 
    else
1745
 
      while ((error=my_sigwait(&set,&sig)) == EINTR) ;
1746
 
    if (cleanup_done)
1747
 
    {
1748
 
      my_thread_end();
1749
 
      signal_thread_in_use= 0;
1750
 
      pthread_exit(0);                          // Safety
1751
 
    }
1752
 
    switch (sig) {
1753
 
    case SIGTERM:
1754
 
    case SIGQUIT:
1755
 
    case SIGKILL:
1756
 
#ifdef EXTRA_DEBUG
1757
 
      sql_print_information(_("Got signal %d to shutdown mysqld"),sig);
1758
 
#endif
1759
 
      /* switch to the old log message processing */
1760
 
      if (!abort_loop)
1761
 
      {
1762
 
        abort_loop=1;                           // mark abort for threads
1763
 
#ifdef USE_ONE_SIGNAL_HAND
1764
 
        pthread_t tmp;
1765
 
        {
1766
 
          struct sched_param tmp_sched_param;
1767
 
 
1768
 
          memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
1769
 
          tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
1770
 
          (void)pthread_attr_setschedparam(&connection_attrib, &tmp_sched_param);
1771
 
        }
1772
 
        if (pthread_create(&tmp,&connection_attrib, kill_server_thread,
1773
 
                           (void*) &sig))
1774
 
          sql_print_error(_("Can't create thread to kill server"));
1775
 
#else
1776
 
        kill_server((void*) sig);       // MIT THREAD has a alarm thread
1777
 
#endif
1778
 
      }
1779
 
      break;
1780
 
    case SIGHUP:
1781
 
      if (!abort_loop)
1782
 
      {
1783
 
        bool not_used;
1784
 
        reload_cache((THD*) 0,
1785
 
                     (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST |
1786
 
                      REFRESH_GRANT |
1787
 
                      REFRESH_THREADS | REFRESH_HOSTS),
1788
 
                     (TableList*) 0, &not_used); // Flush logs
1789
 
      }
1790
 
      break;
1791
 
#ifdef USE_ONE_SIGNAL_HAND
1792
 
    case THR_SERVER_ALARM:
1793
 
      process_alarm(sig);                       // Trigger alarms.
1794
 
      break;
1795
 
#endif
1796
 
    default:
1797
 
#ifdef EXTRA_DEBUG
1798
 
      sql_print_warning(_("Got signal: %d  error: %d"),sig,error); /* purecov: tested */
1799
 
#endif
1800
 
      break;                                    /* purecov: tested */
1801
 
    }
1802
 
  }
1803
 
  return(0);                                    /* purecov: deadcode */
1804
 
}
1805
 
 
1806
 
static void check_data_home(const char *path __attribute__((unused)))
 
1051
static void check_data_home(const char *)
1807
1052
{}
1808
1053
 
1809
 
#endif  /* __WIN__*/
1810
 
 
1811
1054
 
1812
1055
/**
1813
1056
  All global error messages are sent here where the first one is stored
1818
1061
 
1819
1062
void my_message_sql(uint32_t error, const char *str, myf MyFlags)
1820
1063
{
1821
 
  THD *thd;
 
1064
  Session *session;
1822
1065
  /*
1823
1066
    Put here following assertion when situation with EE_* error codes
1824
1067
    will be fixed
1825
1068
  */
1826
 
  if ((thd= current_thd))
 
1069
  if ((session= current_session))
1827
1070
  {
1828
1071
    if (MyFlags & ME_FATALERROR)
1829
 
      thd->is_fatal_error= 1;
 
1072
      session->is_fatal_error= 1;
1830
1073
 
1831
1074
    /*
1832
 
      TODO: There are two exceptions mechanism (THD and sp_rcontext),
 
1075
      TODO: There are two exceptions mechanism (Session and sp_rcontext),
1833
1076
      this could be improved by having a common stack of handlers.
1834
1077
    */
1835
 
    if (thd->handle_error(error, str,
 
1078
    if (session->handle_error(error, str,
1836
1079
                          DRIZZLE_ERROR::WARN_LEVEL_ERROR))
1837
1080
      return;;
1838
1081
 
1839
 
    thd->is_slave_error=  1; // needed to catch query errors during replication
1840
 
 
1841
1082
    /*
1842
 
      thd->lex->current_select == 0 if lex structure is not inited
 
1083
      session->lex->current_select == 0 if lex structure is not inited
1843
1084
      (not query command (COM_QUERY))
1844
1085
    */
1845
 
    if (! (thd->lex->current_select &&
1846
 
        thd->lex->current_select->no_error && !thd->is_fatal_error))
 
1086
    if (! (session->lex->current_select &&
 
1087
        session->lex->current_select->no_error && !session->is_fatal_error))
1847
1088
    {
1848
 
      if (! thd->main_da.is_error())            // Return only first message
 
1089
      if (! session->main_da.is_error())            // Return only first message
1849
1090
      {
1850
1091
        if (error == 0)
1851
1092
          error= ER_UNKNOWN_ERROR;
1852
1093
        if (str == NULL)
1853
1094
          str= ER(error);
1854
 
        thd->main_da.set_error_status(thd, error, str);
 
1095
        session->main_da.set_error_status(error, str);
1855
1096
      }
1856
1097
    }
1857
1098
 
1858
 
    if (!thd->no_warnings_for_error && !thd->is_fatal_error)
 
1099
    if (!session->no_warnings_for_error && !session->is_fatal_error)
1859
1100
    {
1860
1101
      /*
1861
1102
        Suppress infinite recursion if there a memory allocation error
1862
1103
        inside push_warning.
1863
1104
      */
1864
 
      thd->no_warnings_for_error= true;
1865
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
1866
 
      thd->no_warnings_for_error= false;
 
1105
      session->no_warnings_for_error= true;
 
1106
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
 
1107
      session->no_warnings_for_error= false;
1867
1108
    }
1868
1109
  }
1869
 
  if (!thd || MyFlags & ME_NOREFRESH)
1870
 
    sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */
1871
 
  return;;
1872
 
}
1873
 
 
1874
 
 
1875
 
extern "C" void *my_str_malloc_mysqld(size_t size);
1876
 
extern "C" void my_str_free_mysqld(void *ptr);
1877
 
 
1878
 
void *my_str_malloc_mysqld(size_t size)
1879
 
{
1880
 
  return my_malloc(size, MYF(MY_FAE));
1881
 
}
1882
 
 
1883
 
 
1884
 
void my_str_free_mysqld(void *ptr)
1885
 
{
1886
 
  free((unsigned char*)ptr);
 
1110
  if (!session || MyFlags & ME_NOREFRESH)
 
1111
    errmsg_printf(ERRMSG_LVL_ERROR, "%s: %s",my_progname,str);
1887
1112
}
1888
1113
 
1889
1114
 
1890
1115
static const char *load_default_groups[]= {
1891
 
"mysqld","server", DRIZZLE_BASE_VERSION, 0, 0};
1892
 
 
1893
 
 
1894
 
/**
1895
 
  Initialize one of the global date/time format variables.
1896
 
 
1897
 
  @param format_type            What kind of format should be supported
1898
 
  @param var_ptr                Pointer to variable that should be updated
1899
 
 
1900
 
  @note
1901
 
    The default value is taken from either opt_date_time_formats[] or
1902
 
    the ISO format (ANSI SQL)
1903
 
 
1904
 
  @retval
1905
 
    0 ok
1906
 
  @retval
1907
 
    1 error
1908
 
*/
1909
 
 
1910
 
static bool init_global_datetime_format(enum enum_drizzle_timestamp_type format_type,
1911
 
                                        DATE_TIME_FORMAT **var_ptr)
1912
 
{
1913
 
  /* Get command line option */
1914
 
  const char *str= opt_date_time_formats[format_type];
1915
 
 
1916
 
  if (!str)                                     // No specified format
1917
 
  {
1918
 
    str= get_date_time_format_str(&known_date_time_formats[ISO_FORMAT],
1919
 
                                  format_type);
1920
 
    /*
1921
 
      Set the "command line" option to point to the generated string so
1922
 
      that we can set global formats back to default
1923
 
    */
1924
 
    opt_date_time_formats[format_type]= str;
1925
 
  }
1926
 
  if (!(*var_ptr= date_time_format_make(format_type, str, strlen(str))))
1927
 
  {
1928
 
    fprintf(stderr, _("Wrong date/time format specifier: %s\n"), str);
1929
 
    return 1;
1930
 
  }
1931
 
  return 0;
1932
 
}
 
1116
DRIZZLE_CONFIG_NAME, "server", 0, 0};
1933
1117
 
1934
1118
SHOW_VAR com_status_vars[]= {
1935
1119
  {"admin_commands",       (char*) offsetof(STATUS_VAR, com_other), SHOW_LONG_STATUS},
1936
 
  {"assign_to_keycache",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ASSIGN_TO_KEYCACHE]), SHOW_LONG_STATUS},
1937
 
  {"alter_db",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_DB]), SHOW_LONG_STATUS},
1938
 
  {"alter_table",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ALTER_TABLE]), SHOW_LONG_STATUS},
1939
 
  {"analyze",              (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ANALYZE]), SHOW_LONG_STATUS},
1940
 
  {"begin",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BEGIN]), SHOW_LONG_STATUS},
1941
 
  {"binlog",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BINLOG_BASE64_EVENT]), SHOW_LONG_STATUS},
1942
 
  {"change_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_DB]), SHOW_LONG_STATUS},
1943
 
  {"change_master",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_MASTER]), SHOW_LONG_STATUS},
1944
 
  {"check",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHECK]), SHOW_LONG_STATUS},
1945
 
  {"checksum",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHECKSUM]), SHOW_LONG_STATUS},
1946
 
  {"commit",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_COMMIT]), SHOW_LONG_STATUS},
1947
 
  {"create_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_DB]), SHOW_LONG_STATUS},
1948
 
  {"create_index",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_INDEX]), SHOW_LONG_STATUS},
1949
 
  {"create_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CREATE_TABLE]), SHOW_LONG_STATUS},
1950
 
  {"delete",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DELETE]), SHOW_LONG_STATUS},
1951
 
  {"delete_multi",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DELETE_MULTI]), SHOW_LONG_STATUS},
1952
 
  {"drop_db",              (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_DB]), SHOW_LONG_STATUS},
1953
 
  {"drop_index",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_INDEX]), SHOW_LONG_STATUS},
1954
 
  {"drop_table",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_TABLE]), SHOW_LONG_STATUS},
1955
 
  {"empty_query",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_EMPTY_QUERY]), SHOW_LONG_STATUS},
1956
 
  {"flush",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_FLUSH]), SHOW_LONG_STATUS},
1957
 
  {"insert",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_INSERT]), SHOW_LONG_STATUS},
1958
 
  {"insert_select",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_INSERT_SELECT]), SHOW_LONG_STATUS},
1959
 
  {"kill",                 (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_KILL]), SHOW_LONG_STATUS},
1960
 
  {"load",                 (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_LOAD]), SHOW_LONG_STATUS},
1961
 
  {"lock_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_LOCK_TABLES]), SHOW_LONG_STATUS},
1962
 
  {"optimize",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_OPTIMIZE]), SHOW_LONG_STATUS},
1963
 
  {"purge",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_PURGE]), SHOW_LONG_STATUS},
1964
 
  {"purge_before_date",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_PURGE_BEFORE]), SHOW_LONG_STATUS},
1965
 
  {"release_savepoint",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_RELEASE_SAVEPOINT]), SHOW_LONG_STATUS},
1966
 
  {"rename_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_RENAME_TABLE]), SHOW_LONG_STATUS},
1967
 
  {"repair",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REPAIR]), SHOW_LONG_STATUS},
1968
 
  {"replace",              (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REPLACE]), SHOW_LONG_STATUS},
1969
 
  {"replace_select",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_REPLACE_SELECT]), SHOW_LONG_STATUS},
1970
 
  {"reset",                (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_RESET]), SHOW_LONG_STATUS},
1971
 
  {"rollback",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK]), SHOW_LONG_STATUS},
1972
 
  {"rollback_to_savepoint",(char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ROLLBACK_TO_SAVEPOINT]), SHOW_LONG_STATUS},
1973
 
  {"savepoint",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
1974
 
  {"select",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SELECT]), SHOW_LONG_STATUS},
1975
 
  {"set_option",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SET_OPTION]), SHOW_LONG_STATUS},
1976
 
  {"show_binlog_events",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOG_EVENTS]), SHOW_LONG_STATUS},
1977
 
  {"show_binlogs",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOGS]), SHOW_LONG_STATUS},
1978
 
  {"show_charsets",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CHARSETS]), SHOW_LONG_STATUS},
1979
 
  {"show_collations",      (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_COLLATIONS]), SHOW_LONG_STATUS},
1980
 
  {"show_create_db",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_DB]), SHOW_LONG_STATUS},
1981
 
  {"show_create_table",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE]), SHOW_LONG_STATUS},
1982
 
  {"show_databases",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_DATABASES]), SHOW_LONG_STATUS},
1983
 
  {"show_engine_status",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ENGINE_STATUS]), SHOW_LONG_STATUS},
1984
 
  {"show_errors",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_ERRORS]), SHOW_LONG_STATUS},
1985
 
  {"show_fields",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_FIELDS]), SHOW_LONG_STATUS},
1986
 
  {"show_keys",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_KEYS]), SHOW_LONG_STATUS},
1987
 
  {"show_master_status",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_MASTER_STAT]), SHOW_LONG_STATUS},
1988
 
  {"show_open_tables",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS},
1989
 
  {"show_plugins",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PLUGINS]), SHOW_LONG_STATUS},
1990
 
  {"show_processlist",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS},
1991
 
  {"show_slave_hosts",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS},
1992
 
  {"show_slave_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
1993
 
  {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
1994
 
  {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
1995
 
  {"show_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
1996
 
  {"show_variables",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
1997
 
  {"show_warnings",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
1998
 
  {"slave_start",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SLAVE_START]), SHOW_LONG_STATUS},
1999
 
  {"slave_stop",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SLAVE_STOP]), SHOW_LONG_STATUS},
2000
 
  {"truncate",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_TRUNCATE]), SHOW_LONG_STATUS},
2001
 
  {"unlock_tables",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UNLOCK_TABLES]), SHOW_LONG_STATUS},
2002
 
  {"update",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE]), SHOW_LONG_STATUS},
2003
 
  {"update_multi",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE_MULTI]), SHOW_LONG_STATUS},
2004
 
  {NULL, NULL, SHOW_LONG}
 
1120
  {"alter_db",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ALTER_DB]), SHOW_LONG_STATUS},
 
1121
  {"alter_table",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ALTER_TABLE]), SHOW_LONG_STATUS},
 
1122
  {"analyze",              (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ANALYZE]), SHOW_LONG_STATUS},
 
1123
  {"begin",                (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_BEGIN]), SHOW_LONG_STATUS},
 
1124
  {"change_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CHANGE_DB]), SHOW_LONG_STATUS},
 
1125
  {"check",                (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CHECK]), SHOW_LONG_STATUS},
 
1126
  {"checksum",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CHECKSUM]), SHOW_LONG_STATUS},
 
1127
  {"commit",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_COMMIT]), SHOW_LONG_STATUS},
 
1128
  {"create_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CREATE_DB]), SHOW_LONG_STATUS},
 
1129
  {"create_index",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CREATE_INDEX]), SHOW_LONG_STATUS},
 
1130
  {"create_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CREATE_TABLE]), SHOW_LONG_STATUS},
 
1131
  {"delete",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DELETE]), SHOW_LONG_STATUS},
 
1132
  {"drop_db",              (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DROP_DB]), SHOW_LONG_STATUS},
 
1133
  {"drop_index",           (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DROP_INDEX]), SHOW_LONG_STATUS},
 
1134
  {"drop_table",           (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DROP_TABLE]), SHOW_LONG_STATUS},
 
1135
  {"empty_query",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_EMPTY_QUERY]), SHOW_LONG_STATUS},
 
1136
  {"flush",                (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_FLUSH]), SHOW_LONG_STATUS},
 
1137
  {"insert",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_INSERT]), SHOW_LONG_STATUS},
 
1138
  {"insert_select",        (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_INSERT_SELECT]), SHOW_LONG_STATUS},
 
1139
  {"kill",                 (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_KILL]), SHOW_LONG_STATUS},
 
1140
  {"load",                 (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_LOAD]), SHOW_LONG_STATUS},
 
1141
  {"optimize",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_OPTIMIZE]), SHOW_LONG_STATUS},
 
1142
  {"release_savepoint",    (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_RELEASE_SAVEPOINT]), SHOW_LONG_STATUS},
 
1143
  {"rename_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_RENAME_TABLE]), SHOW_LONG_STATUS},
 
1144
  {"replace",              (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_REPLACE]), SHOW_LONG_STATUS},
 
1145
  {"replace_select",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_REPLACE_SELECT]), SHOW_LONG_STATUS},
 
1146
  {"rollback",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ROLLBACK]), SHOW_LONG_STATUS},
 
1147
  {"rollback_to_savepoint",(char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ROLLBACK_TO_SAVEPOINT]), SHOW_LONG_STATUS},
 
1148
  {"savepoint",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
 
1149
  {"select",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SELECT]), SHOW_LONG_STATUS},
 
1150
  {"set_option",           (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SET_OPTION]), SHOW_LONG_STATUS},
 
1151
  {"show_create_db",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_CREATE_DB]), SHOW_LONG_STATUS},
 
1152
  {"show_create_table",    (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_CREATE]), SHOW_LONG_STATUS},
 
1153
  {"show_databases",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_DATABASES]), SHOW_LONG_STATUS},
 
1154
  {"show_engine_status",   (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_ENGINE_STATUS]), SHOW_LONG_STATUS},
 
1155
  {"show_errors",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_ERRORS]), SHOW_LONG_STATUS},
 
1156
  {"show_fields",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_FIELDS]), SHOW_LONG_STATUS},
 
1157
  {"show_keys",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_KEYS]), SHOW_LONG_STATUS},
 
1158
  {"show_open_tables",     (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS},
 
1159
  {"show_processlist",     (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS},
 
1160
  {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
 
1161
  {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
 
1162
  {"show_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
 
1163
  {"show_variables",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
 
1164
  {"show_warnings",        (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
 
1165
  {"truncate",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_TRUNCATE]), SHOW_LONG_STATUS},
 
1166
  {"unlock_tables",        (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_UNLOCK_TABLES]), SHOW_LONG_STATUS},
 
1167
  {"update",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_UPDATE]), SHOW_LONG_STATUS},
 
1168
  {NULL, NULL, SHOW_LONGLONG}
2005
1169
};
2006
1170
 
2007
1171
static int init_common_variables(const char *conf_file_name, int argc,
2008
 
                                 char **argv, const char **groups)
 
1172
                                 char **argv, const char **groups)
2009
1173
{
 
1174
  time_t curr_time;
2010
1175
  umask(((~my_umask) & 0666));
2011
1176
  my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
2012
1177
  tzset();                      // Set tzname
2013
1178
 
 
1179
  curr_time= time(NULL);
 
1180
  if (curr_time == (time_t)-1)
 
1181
    return 1;
 
1182
 
2014
1183
  max_system_variables.pseudo_thread_id= UINT32_MAX;
2015
 
  server_start_time= flush_status_time= my_time(0);
2016
 
  rpl_filter= new Rpl_filter;
2017
 
  binlog_filter= new Rpl_filter;
2018
 
  if (!rpl_filter || !binlog_filter)
2019
 
  {
2020
 
    sql_perror("Could not allocate replication and binlog filters");
2021
 
    exit(1);
2022
 
  }
 
1184
  server_start_time= flush_status_time= curr_time;
2023
1185
 
2024
1186
  if (init_thread_environment())
2025
1187
    return 1;
2026
 
  mysql_init_variables();
 
1188
  drizzle_init_variables();
2027
1189
 
2028
 
#ifdef HAVE_TZNAME
2029
1190
  {
2030
1191
    struct tm tm_tmp;
2031
1192
    localtime_r(&server_start_time,&tm_tmp);
2032
 
    strmake(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
 
1193
    strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
2033
1194
            sizeof(system_time_zone)-1);
2034
1195
 
2035
1196
 }
2036
 
#endif
2037
1197
  /*
2038
1198
    We set SYSTEM time zone as reasonable default and
2039
1199
    also for failure of my_tz_init() and bootstrap mode.
2042
1202
  */
2043
1203
  global_system_variables.time_zone= my_tz_SYSTEM;
2044
1204
 
2045
 
  /*
2046
 
    Init mutexes for the global DRIZZLE_BIN_LOG objects.
2047
 
    As safe_mutex depends on what MY_INIT() does, we can't init the mutexes of
2048
 
    global DRIZZLE_BIN_LOGs in their constructors, because then they would be
2049
 
    inited before MY_INIT(). So we do it here.
2050
 
  */
2051
 
  mysql_bin_log.init_pthread_objects();
2052
 
 
2053
1205
  if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
2054
1206
  {
2055
 
    strmake(glob_hostname, STRING_WITH_LEN("localhost"));
2056
 
    sql_print_warning(_("gethostname failed, using '%s' as hostname"),
 
1207
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
 
1208
      errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
2057
1209
                      glob_hostname);
2058
 
    strmake(pidfile_name, STRING_WITH_LEN("mysql"));
 
1210
    strncpy(pidfile_name, STRING_WITH_LEN("drizzle"));
2059
1211
  }
2060
1212
  else
2061
 
  strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
2062
 
  my_stpcpy(fn_ext(pidfile_name),".pid");               // Add proper extension
 
1213
    strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
 
1214
  strcpy(fn_ext(pidfile_name),".pid");          // Add proper extension
2063
1215
 
2064
1216
  /*
2065
1217
    Add server status variables to the dynamic list of
2074
1226
  defaults_argv=argv;
2075
1227
  defaults_argc=argc;
2076
1228
  get_options(&defaults_argc, defaults_argv);
2077
 
  set_server_version();
2078
 
 
2079
 
 
2080
 
  /* connections and databases needs lots of files */
2081
 
  {
2082
 
    uint32_t files, wanted_files, max_open_files;
2083
 
 
2084
 
    /* MyISAM requires two file handles per table. */
2085
 
    wanted_files= 10+max_connections+table_cache_size*2;
2086
 
    /*
2087
 
      We are trying to allocate no less than max_connections*5 file
2088
 
      handles (i.e. we are trying to set the limit so that they will
2089
 
      be available).  In addition, we allocate no less than how much
2090
 
      was already allocated.  However below we report a warning and
2091
 
      recompute values only if we got less file handles than were
2092
 
      explicitly requested.  No warning and re-computation occur if we
2093
 
      can't get max_connections*5 but still got no less than was
2094
 
      requested (value of wanted_files).
2095
 
    */
2096
 
    max_open_files= cmax(cmax((uint32_t)wanted_files, max_connections*5),
2097
 
                         open_files_limit);
2098
 
    files= my_set_max_open_files(max_open_files);
2099
 
 
2100
 
    if (files < wanted_files)
2101
 
    {
2102
 
      if (!open_files_limit)
2103
 
      {
2104
 
        /*
2105
 
          If we have requested too much file handles than we bring
2106
 
          max_connections in supported bounds.
2107
 
        */
2108
 
        max_connections= (uint32_t) cmin((uint32_t)files-10-TABLE_OPEN_CACHE_MIN*2,
2109
 
                                     max_connections);
2110
 
        /*
2111
 
          Decrease table_cache_size according to max_connections, but
2112
 
          not below TABLE_OPEN_CACHE_MIN.  Outer cmin() ensures that we
2113
 
          never increase table_cache_size automatically (that could
2114
 
          happen if max_connections is decreased above).
2115
 
        */
2116
 
        table_cache_size= (uint32_t) cmin(cmax((files-10-max_connections)/2,
2117
 
                                          (uint32_t)TABLE_OPEN_CACHE_MIN),
2118
 
                                      table_cache_size);
2119
 
        if (global_system_variables.log_warnings)
2120
 
          sql_print_warning(_("Changed limits: max_open_files: %u  "
2121
 
                              "max_connections: %ld  table_cache: %ld"),
2122
 
                            files, max_connections, table_cache_size);
2123
 
      }
2124
 
      else if (global_system_variables.log_warnings)
2125
 
        sql_print_warning(_("Could not increase number of max_open_files "
2126
 
                            "to more than %u (request: %u)"),
2127
 
                          files, wanted_files);
2128
 
    }
2129
 
    open_files_limit= files;
2130
 
  }
2131
 
  unireg_init(0); /* Set up extern variabels */
 
1229
 
 
1230
  current_pid=(ulong) getpid();         /* Save for later ref */
 
1231
  init_time();                          /* Init time-functions (read zone) */
 
1232
 
2132
1233
  if (init_errmessage())        /* Read error messages from file */
2133
1234
    return 1;
2134
 
  lex_init();
2135
1235
  if (item_create_init())
2136
1236
    return 1;
2137
 
  item_init();
2138
1237
  if (set_var_init())
2139
1238
    return 1;
2140
 
  if (init_replication_sys_vars())
 
1239
  /* Creates static regex matching for temporal values */
 
1240
  if (! init_temporal_formats())
2141
1241
    return 1;
2142
 
  /*
2143
 
    Process a comma-separated character set list and choose
2144
 
    the first available character set. This is mostly for
2145
 
    test purposes, to be able to start "mysqld" even if
2146
 
    the requested character set is not available (see bug#18743).
2147
 
  */
2148
 
  for (;;)
 
1242
 
 
1243
  if (!(default_charset_info=
 
1244
        get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
2149
1245
  {
2150
 
    char *next_character_set_name= strchr(default_character_set_name, ',');
2151
 
    if (next_character_set_name)
2152
 
      *next_character_set_name++= '\0';
2153
 
    if (!(default_charset_info=
2154
 
          get_charset_by_csname(default_character_set_name,
2155
 
                                MY_CS_PRIMARY, MYF(MY_WME))))
2156
 
    {
2157
 
      if (next_character_set_name)
2158
 
      {
2159
 
        default_character_set_name= next_character_set_name;
2160
 
        default_collation_name= 0;          // Ignore collation
2161
 
      }
2162
 
      else
2163
 
        return 1;                           // Eof of the list
2164
 
    }
2165
 
    else
2166
 
      break;
 
1246
    return 1;                           // Eof of the list
2167
1247
  }
2168
1248
 
2169
1249
  if (default_collation_name)
2170
1250
  {
2171
 
    const CHARSET_INFO * const default_collation=
2172
 
      get_charset_by_name(default_collation_name, MYF(0));
 
1251
    const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
2173
1252
    if (!default_collation)
2174
1253
    {
2175
 
      sql_print_error(_(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
 
1254
          errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
2176
1255
      return 1;
2177
1256
    }
2178
1257
    if (!my_charset_same(default_charset_info, default_collation))
2179
1258
    {
2180
 
      sql_print_error(_(ER(ER_COLLATION_CHARSET_MISMATCH)),
 
1259
          errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
2181
1260
                      default_collation_name,
2182
1261
                      default_charset_info->csname);
2183
1262
      return 1;
2186
1265
  }
2187
1266
  /* Set collactions that depends on the default collation */
2188
1267
  global_system_variables.collation_server=      default_charset_info;
2189
 
  global_system_variables.collation_database=    default_charset_info;
2190
 
  global_system_variables.collation_connection=  default_charset_info;
2191
 
  global_system_variables.character_set_results= default_charset_info;
2192
 
  global_system_variables.character_set_client= default_charset_info;
2193
1268
 
2194
 
  global_system_variables.optimizer_use_mrr= 1;
2195
1269
  global_system_variables.optimizer_switch= 0;
2196
1270
 
2197
1271
  if (!(character_set_filesystem=
2198
 
        get_charset_by_csname(character_set_filesystem_name,
2199
 
                              MY_CS_PRIMARY, MYF(MY_WME))))
 
1272
        get_charset_by_csname(character_set_filesystem_name, MY_CS_PRIMARY)))
2200
1273
    return 1;
2201
1274
  global_system_variables.character_set_filesystem= character_set_filesystem;
2202
1275
 
2203
1276
  if (!(my_default_lc_time_names=
2204
1277
        my_locale_by_name(lc_time_names_name)))
2205
1278
  {
2206
 
    sql_print_error(_("Unknown locale: '%s'"), lc_time_names_name);
 
1279
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
2207
1280
    return 1;
2208
1281
  }
2209
1282
  global_system_variables.lc_time_names= my_default_lc_time_names;
2210
1283
 
2211
 
  sys_init_connect.value_length= 0;
2212
 
  if ((sys_init_connect.value= opt_init_connect))
2213
 
    sys_init_connect.value_length= strlen(opt_init_connect);
2214
 
  else
2215
 
    sys_init_connect.value=my_strdup("",MYF(0));
2216
 
 
2217
 
  sys_init_slave.value_length= 0;
2218
 
  if ((sys_init_slave.value= opt_init_slave))
2219
 
    sys_init_slave.value_length= strlen(opt_init_slave);
2220
 
  else
2221
 
    sys_init_slave.value=my_strdup("",MYF(0));
2222
 
 
2223
 
  if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
2224
 
    return 1;
2225
 
  if (my_database_names_init())
2226
 
    return 1;
2227
 
 
2228
 
 
2229
 
  /* Reset table_alias_charset, now that lower_case_table_names is set. */
2230
 
  lower_case_table_names= 1; /* This we need to look at */
 
1284
  /* Reset table_alias_charset */
2231
1285
  table_alias_charset= files_charset_info;
2232
1286
 
2233
1287
  return 0;
2236
1290
 
2237
1291
static int init_thread_environment()
2238
1292
{
2239
 
  (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW);
2240
 
  (void) pthread_mutex_init(&LOCK_lock_db,MY_MUTEX_INIT_SLOW);
 
1293
  (void) pthread_mutex_init(&LOCK_create_db, NULL);
2241
1294
  (void) pthread_mutex_init(&LOCK_open, NULL);
2242
1295
  (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
2243
1296
  (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST);
2244
 
  (void) pthread_mutex_init(&LOCK_error_log,MY_MUTEX_INIT_FAST);
2245
 
  (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
2246
 
  (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
2247
1297
  (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
2248
 
  (void) my_rwlock_init(&LOCK_system_variables_hash, NULL);
 
1298
  (void) pthread_rwlock_init(&LOCK_system_variables_hash, NULL);
2249
1299
  (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST);
2250
 
  (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST);
2251
 
  (void) pthread_mutex_init(&LOCK_connection_count, MY_MUTEX_INIT_FAST);
2252
 
  (void) my_rwlock_init(&LOCK_sys_init_connect, NULL);
2253
 
  (void) my_rwlock_init(&LOCK_sys_init_slave, NULL);
2254
1300
  (void) pthread_cond_init(&COND_thread_count,NULL);
 
1301
  (void) pthread_cond_init(&COND_server_end,NULL);
2255
1302
  (void) pthread_cond_init(&COND_refresh,NULL);
2256
1303
  (void) pthread_cond_init(&COND_global_read_lock,NULL);
2257
 
  (void) pthread_cond_init(&COND_thread_cache,NULL);
2258
 
  (void) pthread_cond_init(&COND_flush_thread_cache,NULL);
2259
 
  (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
2260
 
  (void) pthread_cond_init(&COND_rpl_status, NULL);
2261
 
 
2262
 
  /* Parameter for threads created for connections */
2263
 
  (void) pthread_attr_init(&connection_attrib);
2264
 
  (void) pthread_attr_setdetachstate(&connection_attrib,
2265
 
                                     PTHREAD_CREATE_DETACHED);
2266
 
  pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
2267
 
  {
2268
 
    struct sched_param tmp_sched_param;
2269
 
 
2270
 
    memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
2271
 
    tmp_sched_param.sched_priority= WAIT_PRIOR;
2272
 
    (void)pthread_attr_setschedparam(&connection_attrib, &tmp_sched_param);
2273
 
  }
2274
 
 
2275
 
  if (pthread_key_create(&THR_THD,NULL) ||
2276
 
      pthread_key_create(&THR_MALLOC,NULL))
2277
 
  {
2278
 
    sql_print_error(_("Can't create thread-keys"));
 
1304
 
 
1305
  if (pthread_key_create(&THR_Session,NULL) ||
 
1306
      pthread_key_create(&THR_Mem_root,NULL))
 
1307
  {
 
1308
      errmsg_printf(ERRMSG_LVL_ERROR, _("Can't create thread-keys"));
2279
1309
    return 1;
2280
1310
  }
2281
1311
  return 0;
2282
1312
}
2283
1313
 
2284
1314
 
2285
 
static int init_server_components()
 
1315
static int init_server_components(plugin::Registry &plugins)
2286
1316
{
2287
1317
  /*
2288
1318
    We need to call each of these following functions to ensure that
2289
1319
    all things are initialized so that unireg_abort() doesn't fail
2290
1320
  */
2291
 
  if (table_cache_init() | table_def_init())
 
1321
  if (table_cache_init())
 
1322
    unireg_abort(1);
 
1323
  if (TableShare::cacheStart())
2292
1324
    unireg_abort(1);
2293
1325
 
2294
 
  randominit(&sql_rand,(uint32_t) server_start_time,(uint32_t) server_start_time/2);
2295
1326
  setup_fpu();
2296
1327
  init_thr_lock();
2297
 
  init_slave_list();
2298
1328
 
2299
1329
  /* Setup logs */
2300
1330
 
2301
 
  /*
2302
 
    Enable old-fashioned error log, except when the user has requested
2303
 
    help information. Since the implementation of plugin server
2304
 
    variables the help output is now written much later.
2305
 
  */
2306
 
  if (opt_error_log && !opt_help)
2307
 
  {
2308
 
    if (!log_error_file_ptr[0])
2309
 
      fn_format(log_error_file, pidfile_name, mysql_data_home, ".err",
2310
 
                MY_REPLACE_EXT); /* replace '.<domain>' by '.err', bug#4997 */
2311
 
    else
2312
 
      fn_format(log_error_file, log_error_file_ptr, mysql_data_home, ".err",
2313
 
                MY_UNPACK_FILENAME | MY_SAFE_PATH);
2314
 
    if (!log_error_file[0])
2315
 
      opt_error_log= 1;                         // Too long file name
2316
 
    else
2317
 
    {
2318
 
      if (freopen(log_error_file, "a+", stdout))
2319
 
        freopen(log_error_file, "a+", stderr);
2320
 
    }
2321
 
  }
2322
 
 
2323
1331
  if (xid_cache_init())
2324
1332
  {
2325
 
    sql_print_error(_("Out of memory"));
2326
 
    unireg_abort(1);
2327
 
  }
2328
 
 
2329
 
  if (!opt_bin_log)
2330
 
    if (opt_binlog_format_id != BINLOG_FORMAT_UNSPEC)
2331
 
    {
2332
 
      sql_print_error(_("You need to use --log-bin to make "
2333
 
                        "--binlog-format work."));
2334
 
      unireg_abort(1);
2335
 
    }
2336
 
    else
2337
 
    {
2338
 
      global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
2339
 
    }
2340
 
  else
2341
 
    if (opt_binlog_format_id == BINLOG_FORMAT_UNSPEC)
2342
 
      global_system_variables.binlog_format= BINLOG_FORMAT_MIXED;
2343
 
    else
2344
 
    {
2345
 
      assert(global_system_variables.binlog_format != BINLOG_FORMAT_UNSPEC);
2346
 
    }
2347
 
 
2348
 
  /* Check that we have not let the format to unspecified at this point */
2349
 
  assert((uint)global_system_variables.binlog_format <=
2350
 
              array_elements(binlog_format_names)-1);
2351
 
 
2352
 
  if (opt_log_slave_updates && replicate_same_server_id)
2353
 
  {
2354
 
    sql_print_error(_("using --replicate-same-server-id in conjunction with "
2355
 
                      "--log-slave-updates is impossible, it would lead to "
2356
 
                      "infinite loops in this server."));
2357
 
    unireg_abort(1);
2358
 
  }
2359
 
 
2360
 
  if (opt_bin_log)
2361
 
  {
2362
 
    char buf[FN_REFLEN];
2363
 
    const char *ln;
2364
 
    ln= mysql_bin_log.generate_name(opt_bin_logname, "-bin", 1, buf);
2365
 
    if (!opt_bin_logname && !opt_binlog_index_name)
2366
 
    {
2367
 
      /*
2368
 
        User didn't give us info to name the binlog index file.
2369
 
        Picking `hostname`-bin.index like did in 4.x, causes replication to
2370
 
        fail if the hostname is changed later. So, we would like to instead
2371
 
        require a name. But as we don't want to break many existing setups, we
2372
 
        only give warning, not error.
2373
 
      */
2374
 
      sql_print_warning(_("No argument was provided to --log-bin, and "
2375
 
                          "--log-bin-index was not used; so replication "
2376
 
                          "may break when this Drizzle server acts as a "
2377
 
                          "master and has his hostname changed!! Please "
2378
 
                          "use '--log-bin=%s' to avoid this problem."), ln);
2379
 
    }
2380
 
    if (ln == buf)
2381
 
    {
2382
 
      free(opt_bin_logname);
2383
 
      opt_bin_logname=my_strdup(buf, MYF(0));
2384
 
    }
2385
 
    if (mysql_bin_log.open_index_file(opt_binlog_index_name, ln))
2386
 
    {
2387
 
      unireg_abort(1);
2388
 
    }
2389
 
 
2390
 
    /*
2391
 
      Used to specify which type of lock we need to use for queries of type
2392
 
      INSERT ... SELECT. This will change when we have row level logging.
2393
 
    */
2394
 
    using_update_log=1;
2395
 
  }
2396
 
 
2397
 
  /* call ha_init_key_cache() on all key caches to init them */
2398
 
  process_key_caches(&ha_init_key_cache);
 
1333
      errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory"));
 
1334
    unireg_abort(1);
 
1335
  }
2399
1336
 
2400
1337
  /* Allow storage engine to give real error messages */
2401
1338
  if (ha_init_errors())
2402
1339
    return(1);
2403
1340
 
2404
 
  if (plugin_init(&defaults_argc, defaults_argv,
2405
 
                  (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
2406
 
                  (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
 
1341
  if (plugin_init(plugins, &defaults_argc, defaults_argv,
 
1342
                  ((opt_help) ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
2407
1343
  {
2408
 
    sql_print_error(_("Failed to initialize plugins."));
 
1344
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins."));
2409
1345
    unireg_abort(1);
2410
1346
  }
2411
1347
 
2412
 
  if (opt_help)
 
1348
  if (opt_help || opt_help_extended)
2413
1349
    unireg_abort(0);
2414
1350
 
2415
1351
  /* we do want to exit if there are any other unknown options */
2430
1366
    my_getopt_skip_unknown= 0;
2431
1367
 
2432
1368
    if ((ho_error= handle_options(&defaults_argc, &tmp_argv, no_opts,
2433
 
                                  mysqld_get_one_option)))
 
1369
                                  drizzled_get_one_option)))
2434
1370
      unireg_abort(ho_error);
2435
1371
 
2436
1372
    if (defaults_argc)
2443
1379
    }
2444
1380
  }
2445
1381
 
 
1382
  string scheduler_name;
 
1383
  if (opt_scheduler)
 
1384
  {
 
1385
    scheduler_name= opt_scheduler;
 
1386
  }
 
1387
  else
 
1388
  {
 
1389
    scheduler_name= opt_scheduler_default;
 
1390
  }
 
1391
 
 
1392
  if (plugin::SchedulerFactory::setFactory(scheduler_name))
 
1393
  {
 
1394
      errmsg_printf(ERRMSG_LVL_ERROR,
 
1395
                   _("No scheduler found, cannot continue!\n"));
 
1396
      unireg_abort(1);
 
1397
  }
 
1398
 
2446
1399
  /* We have to initialize the storage engines before CSV logging */
2447
1400
  if (ha_init())
2448
1401
  {
2449
 
    sql_print_error(_("Can't init databases"));
 
1402
      errmsg_printf(ERRMSG_LVL_ERROR, _("Can't init databases"));
2450
1403
    unireg_abort(1);
2451
1404
  }
2452
1405
 
2453
1406
  /*
 
1407
    This is entirely for legacy. We will create a new "disk based" engine and a
 
1408
    "memory" engine which will be configurable longterm.
 
1409
  */
 
1410
  const std::string myisam_engine_name("MyISAM");
 
1411
  const std::string heap_engine_name("MEMORY");
 
1412
  myisam_engine= plugin::StorageEngine::findByName(NULL, myisam_engine_name);
 
1413
  heap_engine= plugin::StorageEngine::findByName(NULL, heap_engine_name);
 
1414
 
 
1415
  /*
2454
1416
    Check that the default storage engine is actually available.
2455
1417
  */
2456
1418
  if (default_storage_engine_str)
2457
1419
  {
2458
 
    LEX_STRING name= { default_storage_engine_str,
2459
 
                       strlen(default_storage_engine_str) };
2460
 
    plugin_ref plugin;
2461
 
    handlerton *hton;
 
1420
    const std::string name(default_storage_engine_str);
 
1421
    plugin::StorageEngine *engine;
2462
1422
 
2463
 
    if ((plugin= ha_resolve_by_name(0, &name)))
2464
 
    {
2465
 
      hton= plugin_data(plugin,handlerton *);
2466
 
    }
2467
 
    else
2468
 
    {
2469
 
      sql_print_error(_("Unknown/unsupported table type: %s"),
2470
 
                      default_storage_engine_str);
2471
 
      unireg_abort(1);
2472
 
    }
2473
 
    if (!ha_storage_engine_is_enabled(hton))
2474
 
    {
2475
 
      sql_print_error(_("Default storage engine (%s) is not available"),
2476
 
                      default_storage_engine_str);
2477
 
      unireg_abort(1);
2478
 
      assert(global_system_variables.table_plugin);
 
1423
    engine= plugin::StorageEngine::findByName(0, name);
 
1424
    if (engine == NULL)
 
1425
    {
 
1426
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown/unsupported table type: %s"),
 
1427
                    default_storage_engine_str);
 
1428
      unireg_abort(1);
 
1429
    }
 
1430
    if (!engine->is_enabled())
 
1431
    {
 
1432
      errmsg_printf(ERRMSG_LVL_ERROR, _("Default storage engine (%s) is not available"),
 
1433
                    default_storage_engine_str);
 
1434
      unireg_abort(1);
 
1435
      //assert(global_system_variables.storage_engine);
2479
1436
    }
2480
1437
    else
2481
1438
    {
2482
1439
      /*
2483
 
        Need to unlock as global_system_variables.table_plugin
 
1440
        Need to unlock as global_system_variables.storage_engine
2484
1441
        was acquired during plugin_init()
2485
1442
      */
2486
 
      plugin_unlock(0, global_system_variables.table_plugin);
2487
 
      global_system_variables.table_plugin= plugin;
 
1443
      global_system_variables.storage_engine= engine;
2488
1444
    }
2489
1445
  }
2490
1446
 
2491
 
  tc_log= (total_ha_2pc > 1 ? (opt_bin_log  ?
2492
 
                               (TC_LOG *) &mysql_bin_log :
2493
 
                               (TC_LOG *) &tc_log_mmap) :
2494
 
           (TC_LOG *) &tc_log_dummy);
2495
 
 
2496
 
  if (tc_log->open(opt_bin_log ? opt_bin_logname : opt_tc_log_file))
2497
 
  {
2498
 
    sql_print_error(_("Can't initialize tc_log"));
2499
 
    unireg_abort(1);
2500
 
  }
2501
 
 
2502
1447
  if (ha_recover(0))
2503
1448
  {
2504
1449
    unireg_abort(1);
2505
1450
  }
2506
1451
 
2507
 
  if (opt_bin_log && mysql_bin_log.open(opt_bin_logname, LOG_BIN, 0,
2508
 
                                        WRITE_CACHE, 0, max_binlog_size, 0))
2509
 
    unireg_abort(1);
2510
 
 
2511
 
  if (opt_bin_log && expire_logs_days)
2512
 
  {
2513
 
    time_t purge_time= server_start_time - expire_logs_days*24*60*60;
2514
 
    if (purge_time >= 0)
2515
 
      mysql_bin_log.purge_logs_before_date(purge_time);
2516
 
  }
2517
 
 
2518
1452
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
2519
1453
  if (locked_in_memory && !getuid())
2520
1454
  {
2526
1460
    if (mlockall(MCL_CURRENT))
2527
1461
    {
2528
1462
      if (global_system_variables.log_warnings)
2529
 
        sql_print_warning(_("Failed to lock memory. Errno: %d\n"),errno);
 
1463
            errmsg_printf(ERRMSG_LVL_WARN, _("Failed to lock memory. Errno: %d\n"),errno);
2530
1464
      locked_in_memory= 0;
2531
1465
    }
2532
1466
    if (user_info)
2533
 
      set_user(mysqld_user, user_info);
 
1467
      set_user(drizzled_user, user_info);
2534
1468
  }
2535
1469
  else
2536
1470
#endif
2551
1485
  textdomain("drizzle");
2552
1486
#endif
2553
1487
 
 
1488
  plugin::Registry &plugins= plugin::Registry::singleton();
 
1489
  plugin::Client *client;
 
1490
  Session *session;
 
1491
 
2554
1492
  MY_INIT(argv[0]);             // init my_sys library & pthreads
2555
1493
  /* nothing should come before this line ^^^ */
2556
1494
 
2557
 
  /* Set signal used to kill MySQL */
 
1495
  /* Set signal used to kill Drizzle */
2558
1496
#if defined(SIGUSR2)
2559
1497
  thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
2560
1498
#else
2561
1499
  thr_kill_signal= SIGINT;
2562
1500
#endif
2563
1501
 
2564
 
  /*
2565
 
    Perform basic logger initialization logger. Should be called after
2566
 
    MY_INIT, as it initializes mutexes. Log tables are inited later.
2567
 
  */
2568
 
  logger.init_base();
2569
 
 
2570
 
#ifdef _CUSTOMSTARTUPCONFIG_
2571
 
  if (_cust_check_startup())
2572
 
  {
2573
 
    / * _cust_check_startup will report startup failure error * /
2574
 
    exit(1);
2575
 
  }
2576
 
#endif
2577
 
 
2578
1502
  if (init_common_variables(DRIZZLE_CONFIG_NAME,
2579
1503
                            argc, argv, load_default_groups))
2580
1504
    unireg_abort(1);                            // Will do exit
2581
1505
 
2582
1506
  init_signals();
2583
1507
 
2584
 
  pthread_attr_setstacksize(&connection_attrib,my_thread_stack_size);
2585
 
 
2586
 
#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
2587
 
  {
2588
 
    /* Retrieve used stack size;  Needed for checking stack overflows */
2589
 
    size_t stack_size= 0;
2590
 
    pthread_attr_getstacksize(&connection_attrib, &stack_size);
2591
 
    /* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
2592
 
    if (stack_size && stack_size < my_thread_stack_size)
2593
 
    {
2594
 
      if (global_system_variables.log_warnings)
2595
 
      {
2596
 
        /* %zu is not yet in C++ */
2597
 
        uint64_t size_tmp= (uint64_t)stack_size;
2598
 
        sql_print_warning(_("Asked for %u thread stack, but got %"PRIu64),
2599
 
                          my_thread_stack_size, size_tmp);
2600
 
      }
2601
 
      my_thread_stack_size= stack_size;
2602
 
    }
2603
 
  }
2604
 
#endif
2605
1508
 
2606
1509
  select_thread=pthread_self();
2607
1510
  select_thread_in_use=1;
2608
1511
 
2609
 
  /*
2610
 
    We have enough space for fiddling with the argv, continue
2611
 
  */
2612
 
  check_data_home(mysql_real_data_home);
2613
 
  if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
2614
 
    unireg_abort(1);                            /* purecov: inspected */
2615
 
  mysql_data_home= mysql_data_home_buff;
2616
 
  mysql_data_home[0]=FN_CURLIB;         // all paths are relative from here
2617
 
  mysql_data_home[1]=0;
2618
 
  mysql_data_home_len= 2;
 
1512
  check_data_home(drizzle_real_data_home);
 
1513
  if (chdir(drizzle_real_data_home) && !opt_help)
 
1514
    unireg_abort(1);
 
1515
  drizzle_data_home= drizzle_data_home_buff;
 
1516
  drizzle_data_home[0]=FN_CURLIB;               // all paths are relative from here
 
1517
  drizzle_data_home[1]=0;
 
1518
  drizzle_data_home_len= 2;
2619
1519
 
2620
 
  if ((user_info= check_user(mysqld_user)))
 
1520
  if ((user_info= check_user(drizzled_user)))
2621
1521
  {
2622
1522
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
2623
1523
    if (locked_in_memory) // getuid() == 0 here
2624
1524
      set_effective_user(user_info);
2625
1525
    else
2626
1526
#endif
2627
 
      set_user(mysqld_user, user_info);
 
1527
      set_user(drizzled_user, user_info);
2628
1528
  }
2629
1529
 
2630
 
  if (opt_bin_log && !server_id)
 
1530
  if (server_id == 0)
2631
1531
  {
2632
1532
    server_id= 1;
2633
 
#ifdef EXTRA_DEBUG
2634
 
    sql_print_warning(_("You have enabled the binary log, but you haven't set "
2635
 
                        "server-id to a non-zero value: we force server id to "
2636
 
                        "1; updates will be logged to the binary log, but "
2637
 
                        "connections from slaves will not be accepted."));
2638
 
#endif
2639
1533
  }
2640
1534
 
2641
 
  if (init_server_components())
2642
 
    unireg_abort(1);
2643
 
 
2644
 
  network_init();
2645
 
 
2646
 
  /*
2647
 
   Initialize my_str_malloc() and my_str_free()
2648
 
  */
2649
 
  my_str_malloc= &my_str_malloc_mysqld;
2650
 
  my_str_free= &my_str_free_mysqld;
 
1535
  if (init_server_components(plugins))
 
1536
    unireg_abort(1);
 
1537
 
 
1538
  set_default_port();
 
1539
 
 
1540
  if (plugin::Listen::setup())
 
1541
    unireg_abort(1);
2651
1542
 
2652
1543
  /*
2653
1544
    init signals & alarm
2654
1545
    After this we can't quit by a simple unireg_abort
2655
1546
  */
2656
1547
  error_handler_hook= my_message_sql;
2657
 
  start_signal_handler();                               // Creates pidfile
2658
1548
 
2659
 
  if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, false))
 
1549
  if (drizzle_rm_tmp_tables() ||
 
1550
      my_tz_init((Session *)0, default_tz_name))
2660
1551
  {
2661
 
    abort_loop=1;
 
1552
    abort_loop= true;
2662
1553
    select_thread_in_use=0;
2663
 
    (void) pthread_kill(signal_thread, DRIZZLE_KILL_SIGNAL);
 
1554
    (void) pthread_kill(signal_thread, SIGTERM);
2664
1555
 
2665
 
    (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
 
1556
    (void) unlink(pidfile_name);        // Not needed anymore
2666
1557
 
2667
1558
    exit(1);
2668
1559
  }
2669
1560
 
2670
1561
  init_status_vars();
2671
 
  /*
2672
 
    init_slave() must be called after the thread keys are created.
2673
 
    Some parts of the code (e.g. SHOW STATUS LIKE 'slave_running' and other
2674
 
    places) assume that active_mi != 0, so let's fail if it's 0 (out of
2675
 
    memory); a message has already been printed.
2676
 
  */
2677
 
  if (init_slave() && !active_mi)
 
1562
 
 
1563
  errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)), my_progname, VERSION,
 
1564
                COMPILATION_COMMENT);
 
1565
 
 
1566
 
 
1567
  /* Listen for new connections and start new session for each connection
 
1568
     accepted. The listen.getClient() method will return NULL when the server
 
1569
     should be shutdown. */
 
1570
  while ((client= plugin::Listen::getClient()) != NULL)
2678
1571
  {
2679
 
    unireg_abort(1);
 
1572
    if (!(session= new Session(client)))
 
1573
    {
 
1574
      delete client;
 
1575
      continue;
 
1576
    }
 
1577
 
 
1578
    /* If we error on creation we drop the connection and delete the session. */
 
1579
    if (session->schedule())
 
1580
      unlink_session(session);
2680
1581
  }
2681
1582
 
2682
 
  sql_print_information(_(ER(ER_STARTUP)),my_progname,server_version,
2683
 
                        "", mysqld_port, DRIZZLE_COMPILATION_COMMENT);
2684
 
 
2685
 
 
2686
 
  handle_connections_sockets();
2687
 
 
2688
1583
  /* (void) pthread_attr_destroy(&connection_attrib); */
2689
1584
 
2690
1585
 
2691
 
#ifdef EXTRA_DEBUG2
2692
 
  sql_print_error(_("Before Lock_thread_count"));
2693
 
#endif
2694
1586
  (void) pthread_mutex_lock(&LOCK_thread_count);
2695
1587
  select_thread_in_use=0;                       // For close_connections
2696
1588
  (void) pthread_mutex_unlock(&LOCK_thread_count);
2697
1589
  (void) pthread_cond_broadcast(&COND_thread_count);
2698
 
#ifdef EXTRA_DEBUG2
2699
 
  sql_print_error(_("After lock_thread_count"));
2700
 
#endif
2701
1590
 
2702
1591
  /* Wait until cleanup is done */
2703
1592
  (void) pthread_mutex_lock(&LOCK_thread_count);
2704
1593
  while (!ready_to_exit)
2705
 
    pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
 
1594
    pthread_cond_wait(&COND_server_end,&LOCK_thread_count);
2706
1595
  (void) pthread_mutex_unlock(&LOCK_thread_count);
2707
1596
 
2708
1597
  clean_up(1);
2709
 
  mysqld_exit(0);
2710
 
}
2711
 
 
2712
 
 
2713
 
/**
2714
 
  Create new thread to handle incoming connection.
2715
 
 
2716
 
    This function will create new thread to handle the incoming
2717
 
    connection.  If there are idle cached threads one will be used.
2718
 
    'thd' will be pushed into 'threads'.
2719
 
 
2720
 
    In single-threaded mode (\#define ONE_THREAD) connection will be
2721
 
    handled inside this function.
2722
 
 
2723
 
  @param[in,out] thd    Thread handle of future thread.
2724
 
*/
2725
 
 
2726
 
static void create_new_thread(THD *thd)
2727
 
{
2728
 
 
2729
 
  /*
2730
 
    Don't allow too many connections. We roughly check here that we allow
2731
 
    only (max_connections + 1) connections.
2732
 
  */
2733
 
 
2734
 
  pthread_mutex_lock(&LOCK_connection_count);
2735
 
 
2736
 
  if (connection_count >= max_connections + 1 || abort_loop)
2737
 
  {
2738
 
    pthread_mutex_unlock(&LOCK_connection_count);
2739
 
 
2740
 
    close_connection(thd, ER_CON_COUNT_ERROR, 1);
2741
 
    delete thd;
2742
 
    return;;
2743
 
  }
2744
 
 
2745
 
  ++connection_count;
2746
 
 
2747
 
  if (connection_count > max_used_connections)
2748
 
    max_used_connections= connection_count;
2749
 
 
2750
 
  pthread_mutex_unlock(&LOCK_connection_count);
2751
 
 
2752
 
  /* Start a new thread to handle connection. */
2753
 
 
2754
 
  pthread_mutex_lock(&LOCK_thread_count);
2755
 
 
2756
 
  /*
2757
 
    The initialization of thread_id is done in create_embedded_thd() for
2758
 
    the embedded library.
2759
 
    TODO: refactor this to avoid code duplication there
2760
 
  */
2761
 
  thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
2762
 
 
2763
 
  thread_count++;
2764
 
 
2765
 
  thread_scheduler.add_connection(thd);
2766
 
 
2767
 
  return;;
2768
 
}
2769
 
 
2770
 
 
2771
 
#ifdef SIGNALS_DONT_BREAK_READ
2772
 
inline void kill_broken_server()
2773
 
{
2774
 
  /* hack to get around signals ignored in syscalls for problem OS's */
2775
 
  if ((ip_sock == -1))
2776
 
  {
2777
 
    select_thread_in_use = 0;
2778
 
    /* The following call will never return */
2779
 
    kill_server((void*) DRIZZLE_KILL_SIGNAL);
2780
 
  }
2781
 
}
2782
 
#define MAYBE_BROKEN_SYSCALL kill_broken_server();
2783
 
#else
2784
 
#define MAYBE_BROKEN_SYSCALL
2785
 
#endif
2786
 
 
2787
 
        /* Handle new connections and spawn new process to handle them */
2788
 
 
2789
 
void handle_connections_sockets()
2790
 
{
2791
 
  int x;
2792
 
  int sock,new_sock;
2793
 
  uint32_t error_count=0;
2794
 
  THD *thd;
2795
 
  struct sockaddr_storage cAddr;
2796
 
 
2797
 
  MAYBE_BROKEN_SYSCALL;
2798
 
  while (!abort_loop)
2799
 
  {
2800
 
    int number_of;
2801
 
 
2802
 
    if ((number_of= poll(fds, pollfd_count, -1)) == -1)
2803
 
    {
2804
 
      if (errno != EINTR)
2805
 
      {
2806
 
        if (!select_errors++ && !abort_loop)    /* purecov: inspected */
2807
 
          sql_print_error(_("drizzled: Got error %d from select"),
2808
 
                          errno); /* purecov: inspected */
2809
 
      }
2810
 
      MAYBE_BROKEN_SYSCALL
2811
 
      continue;
2812
 
    }
2813
 
    if (number_of == 0)
2814
 
      continue;
2815
 
 
2816
 
#ifdef FIXME_IF_WE_WERE_KEEPING_THIS
2817
 
    assert(number_of > 1); /* Not handling this at the moment */
2818
 
#endif
2819
 
 
2820
 
    if (abort_loop)
2821
 
    {
2822
 
      MAYBE_BROKEN_SYSCALL;
2823
 
      break;
2824
 
    }
2825
 
 
2826
 
    for (x= 0, sock= -1; x < pollfd_count; x++)
2827
 
    {
2828
 
      if (fds[x].revents == POLLIN)
2829
 
      {
2830
 
        sock= fds[x].fd;
2831
 
        break;
2832
 
      }
2833
 
    }
2834
 
    assert(sock != -1);
2835
 
 
2836
 
    for (uint32_t retry=0; retry < MAX_ACCEPT_RETRY; retry++)
2837
 
    {
2838
 
      SOCKET_SIZE_TYPE length= sizeof(struct sockaddr_storage);
2839
 
      new_sock= accept(sock, (struct sockaddr *)(&cAddr),
2840
 
                       &length);
2841
 
      if (new_sock != -1 || (errno != EINTR && errno != EAGAIN))
2842
 
        break;
2843
 
    }
2844
 
 
2845
 
 
2846
 
    if (new_sock == -1)
2847
 
    {
2848
 
      if ((error_count++ & 255) == 0)           // This can happen often
2849
 
        sql_perror("Error in accept");
2850
 
      MAYBE_BROKEN_SYSCALL;
2851
 
      if (errno == ENFILE || errno == EMFILE)
2852
 
        sleep(1);                               // Give other threads some time
2853
 
      continue;
2854
 
    }
2855
 
 
2856
 
    {
2857
 
      SOCKET_SIZE_TYPE dummyLen;
2858
 
      struct sockaddr_storage dummy;
2859
 
      dummyLen = sizeof(dummy);
2860
 
      if (  getsockname(new_sock,(struct sockaddr *)&dummy,
2861
 
                        (socklen_t *)&dummyLen) < 0  )
2862
 
      {
2863
 
        sql_perror("Error on new connection socket");
2864
 
        (void) shutdown(new_sock, SHUT_RDWR);
2865
 
        (void) close(new_sock);
2866
 
        continue;
2867
 
      }
2868
 
      dummyLen = sizeof(dummy);
2869
 
      if ( getpeername(new_sock, (struct sockaddr *)&dummy,
2870
 
                       (socklen_t *)&dummyLen) < 0)
2871
 
      {
2872
 
        sql_perror("Error on new connection socket");
2873
 
        (void) shutdown(new_sock, SHUT_RDWR);
2874
 
        (void) close(new_sock);
2875
 
         continue;
2876
 
      }
2877
 
    }
2878
 
 
2879
 
    /*
2880
 
    ** Don't allow too many connections
2881
 
    */
2882
 
 
2883
 
    if (!(thd= new THD))
2884
 
    {
2885
 
      (void) shutdown(new_sock, SHUT_RDWR);
2886
 
      close(new_sock);
2887
 
      continue;
2888
 
    }
2889
 
    if (net_init_sock(&thd->net, new_sock, sock == 0))
2890
 
    {
2891
 
      delete thd;
2892
 
      continue;
2893
 
    }
2894
 
 
2895
 
    create_new_thread(thd);
2896
 
  }
 
1598
  clean_up_mutexes();
 
1599
  my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
 
1600
  return 0;
2897
1601
}
2898
1602
 
2899
1603
 
2901
1605
  Handle start options
2902
1606
******************************************************************************/
2903
1607
 
2904
 
enum options_mysqld
 
1608
enum options_drizzled
2905
1609
{
2906
 
  OPT_ISAM_LOG=256,            OPT_SKIP_NEW,
2907
 
  OPT_SKIP_GRANT,
2908
 
  OPT_ENABLE_LOCK,             OPT_USE_LOCKING,
2909
 
  OPT_SOCKET,                  OPT_UPDATE_LOG,
2910
 
  OPT_BIN_LOG,
2911
 
  OPT_BIN_LOG_INDEX,
2912
 
  OPT_BIND_ADDRESS,            OPT_PID_FILE,
2913
 
  OPT_SKIP_PRIOR,
2914
 
  OPT_STANDALONE,
2915
 
  OPT_CONSOLE,                 OPT_LOW_PRIORITY_UPDATES,
2916
 
  OPT_SHORT_LOG_FORMAT,
2917
 
  OPT_FLUSH,                   OPT_SAFE,
2918
 
  OPT_STORAGE_ENGINE,          OPT_INIT_FILE,
2919
 
  OPT_DELAY_KEY_WRITE_ALL,
2920
 
  OPT_DELAY_KEY_WRITE,         OPT_CHARSETS_DIR,
2921
 
  OPT_MASTER_INFO_FILE,
2922
 
  OPT_MASTER_RETRY_COUNT,      OPT_LOG_TC, OPT_LOG_TC_SIZE,
2923
 
  OPT_SQL_BIN_UPDATE_SAME,     OPT_REPLICATE_DO_DB,
2924
 
  OPT_REPLICATE_IGNORE_DB,     OPT_LOG_SLAVE_UPDATES,
2925
 
  OPT_BINLOG_DO_DB,            OPT_BINLOG_IGNORE_DB,
2926
 
  OPT_BINLOG_FORMAT,
2927
 
  OPT_BINLOG_ROWS_EVENT_MAX_SIZE,
 
1610
  OPT_SOCKET=256,
 
1611
  OPT_BIND_ADDRESS,            
 
1612
  OPT_PID_FILE,
 
1613
  OPT_STORAGE_ENGINE,          
 
1614
  OPT_INIT_FILE,
2928
1615
  OPT_WANT_CORE,
2929
 
  OPT_MEMLOCK,                 OPT_MYISAM_RECOVER,
2930
 
  OPT_REPLICATE_REWRITE_DB,    OPT_SERVER_ID,
2931
 
  OPT_SKIP_SLAVE_START,
2932
 
  OPT_REPLICATE_DO_TABLE,
2933
 
  OPT_REPLICATE_IGNORE_TABLE,  OPT_REPLICATE_WILD_DO_TABLE,
2934
 
  OPT_REPLICATE_WILD_IGNORE_TABLE, OPT_REPLICATE_SAME_SERVER_ID,
2935
 
  OPT_DISCONNECT_SLAVE_EVENT_COUNT, OPT_TC_HEURISTIC_RECOVER,
2936
 
  OPT_ABORT_SLAVE_EVENT_COUNT,
2937
 
  OPT_ENGINE_CONDITION_PUSHDOWN,
 
1616
  OPT_MEMLOCK,
 
1617
  OPT_SERVER_ID,
 
1618
  OPT_TC_HEURISTIC_RECOVER,
2938
1619
  OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_COMPLETION_TYPE,
2939
1620
  OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS,
2940
 
  OPT_MAX_BINLOG_DUMP_EVENTS, OPT_SPORADIC_BINLOG_DUMP_FAIL,
2941
 
  OPT_SAFE_USER_CREATE,
2942
 
  OPT_DO_PSTACK, OPT_REPORT_HOST,
2943
 
  OPT_REPORT_USER, OPT_REPORT_PASSWORD, OPT_REPORT_PORT,
2944
 
  OPT_SHOW_SLAVE_AUTH_INFO,
2945
 
  OPT_SLAVE_LOAD_TMPDIR, OPT_NO_MIX_TYPE,
2946
 
  OPT_RPL_RECOVERY_RANK,
2947
 
  OPT_RELAY_LOG, OPT_RELAY_LOG_INDEX, OPT_RELAY_LOG_INFO_FILE,
2948
 
  OPT_SLAVE_SKIP_ERRORS, OPT_SLAVE_ALLOW_BATCHING, OPT_DES_KEY_FILE, OPT_LOCAL_INFILE,
2949
 
  OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA,
2950
 
  OPT_SSL_CAPATH, OPT_SSL_CIPHER,
2951
 
  OPT_BACK_LOG, OPT_BINLOG_CACHE_SIZE,
2952
 
  OPT_CONNECT_TIMEOUT,
2953
 
  OPT_FLUSH_TIME,
2954
 
  OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE,
 
1621
  OPT_DO_PSTACK,
 
1622
  OPT_LOCAL_INFILE,
 
1623
  OPT_BACK_LOG,
 
1624
  OPT_JOIN_BUFF_SIZE,
2955
1625
  OPT_KEY_BUFFER_SIZE, OPT_KEY_CACHE_BLOCK_SIZE,
2956
1626
  OPT_KEY_CACHE_DIVISION_LIMIT, OPT_KEY_CACHE_AGE_THRESHOLD,
2957
 
  OPT_LONG_QUERY_TIME,
2958
 
  OPT_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET,
2959
 
  OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE,
2960
 
  OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS,
 
1627
  OPT_MAX_ALLOWED_PACKET,
 
1628
  OPT_MAX_CONNECT_ERRORS,
2961
1629
  OPT_MAX_HEP_TABLE_SIZE,
2962
1630
  OPT_MAX_JOIN_SIZE,
2963
 
  OPT_MAX_RELAY_LOG_SIZE, OPT_MAX_SORT_LENGTH,
 
1631
  OPT_MAX_SORT_LENGTH,
2964
1632
  OPT_MAX_SEEKS_FOR_KEY, OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS,
2965
1633
  OPT_MAX_LENGTH_FOR_SORT_DATA,
2966
1634
  OPT_MAX_WRITE_LOCK_COUNT, OPT_BULK_INSERT_BUFFER_SIZE,
2968
1636
  OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
2969
1637
  OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE,
2970
1638
  OPT_MYISAM_USE_MMAP, OPT_MYISAM_REPAIR_THREADS,
2971
 
  OPT_MYISAM_STATS_METHOD,
2972
 
  OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT,
2973
 
  OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT,
2974
 
  OPT_OPEN_FILES_LIMIT,
 
1639
  OPT_NET_BUFFER_LENGTH,
2975
1640
  OPT_PRELOAD_BUFFER_SIZE,
2976
1641
  OPT_RECORD_BUFFER,
2977
 
  OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT, OPT_RELAY_LOG_SPACE_LIMIT,
2978
 
  OPT_RELAY_LOG_PURGE,
2979
 
  OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
2980
 
  OPT_SLAVE_TRANS_RETRIES, OPT_READONLY, OPT_DEBUGGING,
 
1642
  OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT,
 
1643
  OPT_DEBUGGING,
2981
1644
  OPT_SORT_BUFFER, OPT_TABLE_OPEN_CACHE, OPT_TABLE_DEF_CACHE,
2982
 
  OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE,
2983
1645
  OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK,
2984
1646
  OPT_WAIT_TIMEOUT,
2985
 
  OPT_ERROR_LOG_FILE,
2986
 
  OPT_DEFAULT_WEEK_FORMAT,
2987
1647
  OPT_RANGE_ALLOC_BLOCK_SIZE,
2988
1648
  OPT_QUERY_ALLOC_BLOCK_SIZE, OPT_QUERY_PREALLOC_SIZE,
2989
1649
  OPT_TRANS_ALLOC_BLOCK_SIZE, OPT_TRANS_PREALLOC_SIZE,
2990
 
  OPT_SYNC_FRM, OPT_SYNC_BINLOG,
2991
 
  OPT_SYNC_REPLICATION,
2992
 
  OPT_SYNC_REPLICATION_SLAVE_ID,
2993
 
  OPT_SYNC_REPLICATION_TIMEOUT,
2994
 
  OPT_ENABLE_SHARED_MEMORY,
2995
 
  OPT_SHARED_MEMORY_BASE_NAME,
2996
1650
  OPT_OLD_ALTER_TABLE,
2997
 
  OPT_EXPIRE_LOGS_DAYS,
2998
1651
  OPT_GROUP_CONCAT_MAX_LEN,
2999
1652
  OPT_DEFAULT_COLLATION,
3000
 
  OPT_CHARACTER_SET_CLIENT_HANDSHAKE,
3001
1653
  OPT_CHARACTER_SET_FILESYSTEM,
3002
1654
  OPT_LC_TIME_NAMES,
3003
1655
  OPT_INIT_CONNECT,
3004
 
  OPT_INIT_SLAVE,
3005
 
  OPT_SECURE_AUTH,
3006
 
  OPT_DATE_FORMAT,
3007
 
  OPT_TIME_FORMAT,
3008
 
  OPT_DATETIME_FORMAT,
3009
1656
  OPT_DEFAULT_TIME_ZONE,
3010
 
  OPT_SYSDATE_IS_NOW,
3011
1657
  OPT_OPTIMIZER_SEARCH_DEPTH,
 
1658
  OPT_SCHEDULER,
 
1659
  OPT_PROTOCOL,
3012
1660
  OPT_OPTIMIZER_PRUNE_LEVEL,
3013
 
  OPT_UPDATABLE_VIEWS_WITH_LIMIT,
3014
1661
  OPT_AUTO_INCREMENT, OPT_AUTO_INCREMENT_OFFSET,
3015
1662
  OPT_ENABLE_LARGE_PAGES,
3016
1663
  OPT_TIMED_MUTEXES,
3017
 
  OPT_OLD_STYLE_USER_LIMITS,
3018
1664
  OPT_TABLE_LOCK_WAIT_TIMEOUT,
3019
1665
  OPT_PLUGIN_LOAD,
3020
1666
  OPT_PLUGIN_DIR,
3021
1667
  OPT_PORT_OPEN_TIMEOUT,
3022
 
  OPT_PROFILING,
3023
 
  OPT_KEEP_FILES_ON_CREATE,
3024
 
  OPT_GENERAL_LOG,
3025
 
  OPT_THREAD_HANDLING,
3026
 
  OPT_INNODB_ROLLBACK_ON_TIMEOUT,
3027
1668
  OPT_SECURE_FILE_PRIV,
3028
 
  OPT_MIN_EXAMINED_ROW_LIMIT,
3029
 
  OPT_OLD_MODE,
3030
 
  OPT_POOL_OF_THREADS,
3031
 
  OPT_SLAVE_EXEC_MODE
 
1669
  OPT_MIN_EXAMINED_ROW_LIMIT
3032
1670
};
3033
1671
 
3034
1672
 
3035
 
#define LONG_TIMEOUT ((uint32_t) 3600L*24L*365L)
3036
 
 
3037
1673
struct my_option my_long_options[] =
3038
1674
{
3039
1675
  {"help", '?', N_("Display this help and exit."),
3040
1676
   (char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
3041
1677
   0, 0},
3042
 
  {"abort-slave-event-count", OPT_ABORT_SLAVE_EVENT_COUNT,
3043
 
   N_("Option used by mysql-test for debugging and testing of replication."),
3044
 
   (char**) &abort_slave_event_count,  (char**) &abort_slave_event_count,
3045
 
   0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1678
  {"help-extended", '?',
 
1679
   N_("Display this help and exit after initializing plugins."),
 
1680
   (char**) &opt_help_extended, (char**) &opt_help_extended,
 
1681
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3046
1682
  {"auto-increment-increment", OPT_AUTO_INCREMENT,
3047
1683
   N_("Auto-increment columns are incremented by this"),
3048
1684
   (char**) &global_system_variables.auto_increment_increment,
3049
 
   (char**) &max_system_variables.auto_increment_increment, 0, GET_ULONG,
3050
 
   OPT_ARG, 1, 1, 65535, 0, 1, 0 },
 
1685
   (char**) &max_system_variables.auto_increment_increment, 0, GET_ULL,
 
1686
   OPT_ARG, 1, 1, UINT64_MAX, 0, 1, 0 },
3051
1687
  {"auto-increment-offset", OPT_AUTO_INCREMENT_OFFSET,
3052
1688
   N_("Offset added to Auto-increment columns. Used when "
3053
1689
      "auto-increment-increment != 1"),
3054
1690
   (char**) &global_system_variables.auto_increment_offset,
3055
 
   (char**) &max_system_variables.auto_increment_offset, 0, GET_ULONG, OPT_ARG,
3056
 
   1, 1, 65535, 0, 1, 0 },
 
1691
   (char**) &max_system_variables.auto_increment_offset, 0, GET_ULL, OPT_ARG,
 
1692
   1, 1, UINT64_MAX, 0, 1, 0 },
3057
1693
  {"basedir", 'b',
3058
1694
   N_("Path to installation directory. All paths are usually resolved "
3059
1695
      "relative to this."),
3060
 
   (char**) &mysql_home_ptr, (char**) &mysql_home_ptr, 0, GET_STR, REQUIRED_ARG,
 
1696
   (char**) &drizzle_home_ptr, (char**) &drizzle_home_ptr, 0, GET_STR, REQUIRED_ARG,
3061
1697
   0, 0, 0, 0, 0, 0},
3062
1698
  {"bind-address", OPT_BIND_ADDRESS, N_("IP address to bind to."),
3063
 
   (char**) &my_bind_addr_str, (char**) &my_bind_addr_str, 0, GET_STR,
 
1699
   (char**) &drizzled_bind_host, (char**) &drizzled_bind_host, 0, GET_STR,
3064
1700
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3065
 
  {"binlog_format", OPT_BINLOG_FORMAT,
3066
 
   N_("Does not have any effect without '--log-bin'. "
3067
 
      "Tell the master the form of binary logging to use: either 'row' for "
3068
 
      "row-based binary logging, or 'statement' for statement-based binary "
3069
 
      "logging, or 'mixed'. 'mixed' is statement-based binary logging except "
3070
 
      "for those statements where only row-based is correct: those which "
3071
 
      "involve user-defined functions (i.e. UDFs) or the UUID() function; for "
3072
 
      "those, row-based binary logging is automatically used. ")
3073
 
   ,(char**) &opt_binlog_format, (char**) &opt_binlog_format,
3074
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3075
 
  {"binlog-do-db", OPT_BINLOG_DO_DB,
3076
 
   N_("Tells the master it should log updates for the specified database, and "
3077
 
      "exclude all others not explicitly mentioned."),
3078
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3079
 
  {"binlog-ignore-db", OPT_BINLOG_IGNORE_DB,
3080
 
   N_("Tells the master that updates to the given database should not "
3081
 
      "be logged tothe binary log."),
3082
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3083
 
  {"binlog-row-event-max-size", OPT_BINLOG_ROWS_EVENT_MAX_SIZE,
3084
 
   N_("The maximum size of a row-based binary log event in bytes. Rows will "
3085
 
      "be grouped into events smaller than this size if possible. "
3086
 
      "The value has to be a multiple of 256."),
3087
 
   (char**) &opt_binlog_rows_event_max_size,
3088
 
   (char**) &opt_binlog_rows_event_max_size, 0,
3089
 
   GET_ULONG, REQUIRED_ARG,
3090
 
   /* def_value */ 1024, /* min_value */  256, /* max_value */ ULONG_MAX,
3091
 
   /* sub_size */     0, /* block_size */ 256,
3092
 
   /* app_type */ 0
3093
 
  },
3094
 
  {"character-set-client-handshake", OPT_CHARACTER_SET_CLIENT_HANDSHAKE,
3095
 
   N_("Don't ignore client side character set value sent during handshake."),
3096
 
   (char**) &opt_character_set_client_handshake,
3097
 
   (char**) &opt_character_set_client_handshake,
3098
 
    0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
3099
 
  {"character-set-filesystem", OPT_CHARACTER_SET_FILESYSTEM,
3100
 
   N_("Set the filesystem character set."),
3101
 
   (char**) &character_set_filesystem_name,
3102
 
   (char**) &character_set_filesystem_name,
3103
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
3104
 
  {"character-set-server", 'C',
3105
 
   N_("Set the default character set."),
3106
 
   (char**) &default_character_set_name, (char**) &default_character_set_name,
3107
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
3108
 
  {"character-sets-dir", OPT_CHARSETS_DIR,
3109
 
   N_("Directory where character sets are."), (char**) &charsets_dir,
3110
 
   (char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3111
1701
  {"chroot", 'r',
3112
 
   N_("Chroot mysqld daemon during startup."),
3113
 
   (char**) &mysqld_chroot, (char**) &mysqld_chroot, 0, GET_STR, REQUIRED_ARG,
 
1702
   N_("Chroot drizzled daemon during startup."),
 
1703
   (char**) &drizzled_chroot, (char**) &drizzled_chroot, 0, GET_STR, REQUIRED_ARG,
3114
1704
   0, 0, 0, 0, 0, 0},
3115
1705
  {"collation-server", OPT_DEFAULT_COLLATION,
3116
1706
   N_("Set the default collation."),
3119
1709
  {"completion-type", OPT_COMPLETION_TYPE,
3120
1710
   N_("Default completion type."),
3121
1711
   (char**) &global_system_variables.completion_type,
3122
 
   (char**) &max_system_variables.completion_type, 0, GET_ULONG,
 
1712
   (char**) &max_system_variables.completion_type, 0, GET_UINT,
3123
1713
   REQUIRED_ARG, 0, 0, 2, 0, 1, 0},
3124
 
  {"console", OPT_CONSOLE,
3125
 
   N_("Write error output on screen."),
3126
 
   (char**) &opt_console, (char**) &opt_console, 0, GET_BOOL, NO_ARG, 0, 0, 0,
3127
 
   0, 0, 0},
3128
1714
  {"core-file", OPT_WANT_CORE,
3129
1715
   N_("Write core on errors."),
3130
1716
   0, 0, 0, GET_NO_ARG,
3131
1717
   NO_ARG, 0, 0, 0, 0, 0, 0},
3132
1718
  {"datadir", 'h',
3133
1719
   N_("Path to the database root."),
3134
 
   (char**) &mysql_data_home,
3135
 
   (char**) &mysql_data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1720
   (char**) &drizzle_data_home,
 
1721
   (char**) &drizzle_data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3136
1722
  {"default-storage-engine", OPT_STORAGE_ENGINE,
3137
1723
   N_("Set the default storage engine (table type) for tables."),
3138
1724
   (char**)&default_storage_engine_str, (char**)&default_storage_engine_str,
3141
1727
   N_("Set the default time zone."),
3142
1728
   (char**) &default_tz_name, (char**) &default_tz_name,
3143
1729
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
3144
 
  {"delay-key-write", OPT_DELAY_KEY_WRITE,
3145
 
   N_("Type of DELAY_KEY_WRITE."),
3146
 
   0,0,0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
3147
 
  {"disconnect-slave-event-count", OPT_DISCONNECT_SLAVE_EVENT_COUNT,
3148
 
   N_("Option used by mysql-test for debugging and testing of replication."),
3149
 
   (char**) &disconnect_slave_event_count,
3150
 
   (char**) &disconnect_slave_event_count, 0, GET_INT, REQUIRED_ARG, 0, 0, 0,
3151
 
   0, 0, 0},
3152
1730
#ifdef HAVE_STACK_TRACE_ON_SEGV
3153
1731
  {"enable-pstack", OPT_DO_PSTACK,
3154
1732
   N_("Print a symbolic stack trace on failure."),
3155
1733
   (char**) &opt_do_pstack, (char**) &opt_do_pstack, 0, GET_BOOL, NO_ARG, 0, 0,
3156
1734
   0, 0, 0, 0},
3157
1735
#endif /* HAVE_STACK_TRACE_ON_SEGV */
3158
 
  {"engine-condition-pushdown",
3159
 
   OPT_ENGINE_CONDITION_PUSHDOWN,
3160
 
   N_("Push supported query conditions to the storage engine."),
3161
 
   (char**) &global_system_variables.engine_condition_pushdown,
3162
 
   (char**) &global_system_variables.engine_condition_pushdown,
3163
 
   0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
3164
1736
  /* See how it's handled in get_one_option() */
3165
1737
  {"exit-info", 'T',
3166
1738
   N_("Used for debugging;  Use at your own risk!"),
3167
1739
   0, 0, 0, GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
3168
 
  {"flush", OPT_FLUSH,
3169
 
   N_("Flush tables to disk between SQL commands."),
3170
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
3171
1740
  /* We must always support the next option to make scripts like mysqltest
3172
1741
     easier to do */
3173
1742
  {"gdb", OPT_DEBUGGING,
3174
1743
   N_("Set up signals usable for debugging"),
3175
1744
   (char**) &opt_debugging, (char**) &opt_debugging,
3176
1745
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3177
 
  {"init-connect", OPT_INIT_CONNECT,
3178
 
   N_("Command(s) that are executed for each new connection"),
3179
 
   (char**) &opt_init_connect, (char**) &opt_init_connect, 0, GET_STR_ALLOC,
3180
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3181
 
  {"init-file", OPT_INIT_FILE,
3182
 
   N_("Read SQL commands from this file at startup."),
3183
 
   (char**) &opt_init_file, (char**) &opt_init_file, 0, GET_STR, REQUIRED_ARG,
3184
 
   0, 0, 0, 0, 0, 0},
3185
 
  {"init-slave", OPT_INIT_SLAVE,
3186
 
   N_("Command(s) that are executed when a slave connects to this master"),
3187
 
   (char**) &opt_init_slave, (char**) &opt_init_slave, 0, GET_STR_ALLOC,
3188
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3189
1746
  {"language", 'L',
3190
1747
   N_("(IGNORED)"),
3191
1748
   (char**) &language_ptr, (char**) &language_ptr, 0, GET_STR, REQUIRED_ARG,
3195
1752
   (char**) &lc_time_names_name,
3196
1753
   (char**) &lc_time_names_name,
3197
1754
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
3198
 
  {"local-infile", OPT_LOCAL_INFILE,
3199
 
   N_("Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0)."),
3200
 
   (char**) &opt_local_infile,
3201
 
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG,
3202
 
   1, 0, 0, 0, 0, 0},
3203
 
  {"log", 'l',
3204
 
   N_("Log connections and queries to file."),
3205
 
   (char**) &opt_logname,
3206
 
   (char**) &opt_logname, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
3207
 
  {"log-bin", OPT_BIN_LOG,
3208
 
   N_("Log update queries in binary format. Optional argument is the "
3209
 
      "location for the binary log files.(Strongly "
3210
 
      "recommended to avoid replication problems if server's hostname "
3211
 
      "changes)"),
3212
 
   (char**) &opt_bin_logname, (char**) &opt_bin_logname, 0, GET_STR_ALLOC,
3213
 
   OPT_ARG, 0, 0, 0, 0, 0, 0},
3214
 
  {"log-bin-index", OPT_BIN_LOG_INDEX,
3215
 
   N_("File that holds the names for last binary log files."),
3216
 
   (char**) &opt_binlog_index_name, (char**) &opt_binlog_index_name, 0, GET_STR,
3217
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3218
 
  {"log-error", OPT_ERROR_LOG_FILE,
3219
 
   N_("Error log file."),
3220
 
   (char**) &log_error_file_ptr, (char**) &log_error_file_ptr, 0, GET_STR,
3221
 
   OPT_ARG, 0, 0, 0, 0, 0, 0},
3222
 
  {"log-isam", OPT_ISAM_LOG,
3223
 
   N_("Log all MyISAM changes to file."),
3224
 
   (char**) &myisam_log_filename, (char**) &myisam_log_filename, 0, GET_STR,
3225
 
   OPT_ARG, 0, 0, 0, 0, 0, 0},
3226
 
  {"log-slave-updates", OPT_LOG_SLAVE_UPDATES,
3227
 
   N_("Tells the slave to log the updates from the slave thread to the binary "
3228
 
      "log. You will need to turn it on if you plan to "
3229
 
      "daisy-chain the slaves."),
3230
 
   (char**) &opt_log_slave_updates, (char**) &opt_log_slave_updates,
3231
 
   0, GET_BOOL,
3232
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
3233
 
  {"log-tc", OPT_LOG_TC,
3234
 
   N_("Path to transaction coordinator log (used for transactions that affect "
3235
 
      "more than one storage engine, when binary log is disabled)"),
3236
 
   (char**) &opt_tc_log_file, (char**) &opt_tc_log_file, 0, GET_STR,
3237
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3238
 
#ifdef HAVE_MMAP
3239
 
  {"log-tc-size", OPT_LOG_TC_SIZE,
3240
 
   N_("Size of transaction coordinator log."),
3241
 
   (char**) &opt_tc_log_size, (char**) &opt_tc_log_size, 0, GET_ULONG,
3242
 
   REQUIRED_ARG, TC_LOG_MIN_SIZE, TC_LOG_MIN_SIZE, ULONG_MAX, 0,
3243
 
   TC_LOG_PAGE_SIZE, 0},
3244
 
#endif
3245
1755
  {"log-warnings", 'W',
3246
1756
   N_("Log some not critical warnings to the log file."),
3247
1757
   (char**) &global_system_variables.log_warnings,
3248
 
   (char**) &max_system_variables.log_warnings, 0, GET_ULONG, OPT_ARG, 1, 0, 0,
 
1758
   (char**) &max_system_variables.log_warnings, 0, GET_BOOL, OPT_ARG, 1, 0, 0,
3249
1759
   0, 0, 0},
3250
 
  {"low-priority-updates", OPT_LOW_PRIORITY_UPDATES,
3251
 
   N_("INSERT/DELETE/UPDATE has lower priority than selects."),
3252
 
   (char**) &global_system_variables.low_priority_updates,
3253
 
   (char**) &max_system_variables.low_priority_updates,
3254
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3255
 
  {"master-info-file", OPT_MASTER_INFO_FILE,
3256
 
   N_("The location and name of the file that remembers the master and "
3257
 
      "where the I/O replication thread is in the master's binlogs."),
3258
 
   (char**) &master_info_file, (char**) &master_info_file, 0, GET_STR,
3259
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3260
 
  {"master-retry-count", OPT_MASTER_RETRY_COUNT,
3261
 
   N_("The number of tries the slave will make to connect to the master "
3262
 
      "before giving up."),
3263
 
   (char**) &master_retry_count, (char**) &master_retry_count, 0, GET_ULONG,
3264
 
   REQUIRED_ARG, 3600*24, 0, 0, 0, 0, 0},
3265
 
  {"max-binlog-dump-events", OPT_MAX_BINLOG_DUMP_EVENTS,
3266
 
   N_("Option used by mysql-test for debugging and testing of replication."),
3267
 
   (char**) &max_binlog_dump_events, (char**) &max_binlog_dump_events, 0,
3268
 
   GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3269
1760
  {"memlock", OPT_MEMLOCK,
3270
 
   N_("Lock mysqld in memory."),
 
1761
   N_("Lock drizzled in memory."),
3271
1762
   (char**) &locked_in_memory,
3272
1763
   (char**) &locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3273
 
  {"myisam-recover", OPT_MYISAM_RECOVER,
3274
 
   N_("Syntax: myisam-recover[=option[,option...]], where option can be "
3275
 
      "DEFAULT, BACKUP, FORCE or QUICK."),
3276
 
   (char**) &myisam_recover_options_str, (char**) &myisam_recover_options_str, 0,
3277
 
   GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
3278
 
  {"new", 'n',
3279
 
   N_("Use very new possible 'unsafe' functions."),
3280
 
   (char**) &global_system_variables.new_mode,
3281
 
   (char**) &max_system_variables.new_mode,
3282
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3283
 
  {"old-alter-table", OPT_OLD_ALTER_TABLE,
3284
 
   N_("Use old, non-optimized alter table."),
3285
 
   (char**) &global_system_variables.old_alter_table,
3286
 
   (char**) &max_system_variables.old_alter_table, 0, GET_BOOL, NO_ARG,
3287
 
   0, 0, 0, 0, 0, 0},
3288
 
  {"old-style-user-limits", OPT_OLD_STYLE_USER_LIMITS,
3289
 
   N_("Enable old-style user limits (before 5.0.3 user resources were counted "
3290
 
      "per each user+host vs. per account)"),
3291
 
   (char**) &opt_old_style_user_limits, (char**) &opt_old_style_user_limits,
3292
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3293
1764
  {"pid-file", OPT_PID_FILE,
3294
1765
   N_("Pid file used by safe_mysqld."),
3295
1766
   (char**) &pidfile_name_ptr, (char**) &pidfile_name_ptr, 0, GET_STR,
3296
1767
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3297
1768
  {"port", 'P',
3298
1769
   N_("Port number to use for connection or 0 for default to, in "
3299
 
      "order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
3300
 
      "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ")."),
3301
 
   (char**) &mysqld_port,
3302
 
   (char**) &mysqld_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1770
      "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
 
1771
      "built-in default (" STRINGIFY_ARG(DRIZZLE_TCP_PORT) ")."),
 
1772
   (char**) &drizzled_tcp_port,
 
1773
   (char**) &drizzled_tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3303
1774
  {"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
3304
1775
   N_("Maximum time in seconds to wait for the port to become free. "
3305
1776
      "(Default: no wait)"),
3306
 
   (char**) &mysqld_port_timeout,
3307
 
   (char**) &mysqld_port_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3308
 
  {"relay-log", OPT_RELAY_LOG,
3309
 
   N_("The location and name to use for relay logs."),
3310
 
   (char**) &opt_relay_logname, (char**) &opt_relay_logname, 0,
3311
 
   GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3312
 
  {"relay-log-index", OPT_RELAY_LOG_INDEX,
3313
 
   N_("The location and name to use for the file that keeps a list of the "
3314
 
      "last relay logs."),
3315
 
   (char**) &opt_relaylog_index_name, (char**) &opt_relaylog_index_name, 0,
3316
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3317
 
  {"relay-log-info-file", OPT_RELAY_LOG_INFO_FILE,
3318
 
   N_("The location and name of the file that remembers where the SQL "
3319
 
      "replication thread is in the relay logs."),
3320
 
   (char**) &relay_log_info_file, (char**) &relay_log_info_file, 0, GET_STR,
3321
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3322
 
  {"replicate-do-db", OPT_REPLICATE_DO_DB,
3323
 
   N_("Tells the slave thread to restrict replication to the specified "
3324
 
      "database. To specify more than one database, use the directive "
3325
 
      "multiple times, once for each database. Note that this will only work "
3326
 
      "if you do not use cross-database queries such as UPDATE "
3327
 
      "some_db.some_table SET foo='bar' while having selected a different or "
3328
 
      "no database. If you need cross database updates to work, use "
3329
 
      "replicate-wild-do-table=db_name.%."),
3330
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3331
 
  {"replicate-do-table", OPT_REPLICATE_DO_TABLE,
3332
 
   N_("Tells the slave thread to restrict replication to the specified table. "
3333
 
      "To specify more than one table, use the directive multiple times, once "
3334
 
      "for each table. This will work for cross-database updates, in contrast "
3335
 
      "to replicate-do-db."),
3336
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3337
 
  {"replicate-ignore-db", OPT_REPLICATE_IGNORE_DB,
3338
 
   N_("Tells the slave thread to not replicate to the specified database. To "
3339
 
      "specify more than one database to ignore, use the directive multiple "
3340
 
      "times, once for each database. This option will not work if you use "
3341
 
      "cross database updates. If you need cross database updates to work, "
3342
 
      "use replicate-wild-ignore-table=db_name.%. "),
3343
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3344
 
  {"replicate-ignore-table", OPT_REPLICATE_IGNORE_TABLE,
3345
 
   N_("Tells the slave thread to not replicate to the specified table. To "
3346
 
      "specify more than one table to ignore, use the directive multiple "
3347
 
      "times, once for each table. This will work for cross-datbase updates, "
3348
 
      "in contrast to replicate-ignore-db."),
3349
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3350
 
  {"replicate-rewrite-db", OPT_REPLICATE_REWRITE_DB,
3351
 
   N_("Updates to a database with a different name than the original. "
3352
 
      "Example: replicate-rewrite-db=master_db_name->slave_db_name."),
3353
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3354
 
  {"replicate-same-server-id", OPT_REPLICATE_SAME_SERVER_ID,
3355
 
   N_("In replication, if set to 1, do not skip events having our server id. "
3356
 
      "Default value is 0 (to break infinite loops in circular replication). "
3357
 
      "Can't be set to 1 if --log-slave-updates is used."),
3358
 
   (char**) &replicate_same_server_id,
3359
 
   (char**) &replicate_same_server_id,
3360
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3361
 
  {"replicate-wild-do-table", OPT_REPLICATE_WILD_DO_TABLE,
3362
 
   N_("Tells the slave thread to restrict replication to the tables that "
3363
 
      "match the specified wildcard pattern. To specify more than one table, "
3364
 
      "use the directive multiple times, once for each table. This will work "
3365
 
      "for cross-database updates. Example: replicate-wild-do-table=foo%.bar% "
3366
 
      "will replicate only updates to tables in all databases that start with "
3367
 
      "foo and whose table names start with bar."),
3368
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3369
 
  {"replicate-wild-ignore-table", OPT_REPLICATE_WILD_IGNORE_TABLE,
3370
 
   N_("Tells the slave thread to not replicate to the tables that match the "
3371
 
      "given wildcard pattern. To specify more than one table to ignore, use "
3372
 
      "the directive multiple times, once for each table. This will work for "
3373
 
      "cross-database updates. Example: replicate-wild-ignore-table=foo%.bar% "
3374
 
      "will not do updates to tables in databases that start with foo and "
3375
 
      "whose table names start with bar."),
3376
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3377
 
  // In replication, we may need to tell the other servers how to connect
3378
 
  {"report-host", OPT_REPORT_HOST,
3379
 
   N_("Hostname or IP of the slave to be reported to to the master during "
3380
 
      "slave registration. Will appear in the output of SHOW SLAVE HOSTS. "
3381
 
      "Leave unset if you do not want the slave to register itself with the "
3382
 
      "master. Note that it is not sufficient for the master to simply read "
3383
 
      "the IP of the slave off the socket once the slave connects. Due to NAT "
3384
 
      "and other routing issues, that IP may not be valid for connecting to "
3385
 
      "the slave from the master or other hosts."),
3386
 
   (char**) &report_host, (char**) &report_host, 0, GET_STR, REQUIRED_ARG, 0, 0,
3387
 
   0, 0, 0, 0},
3388
 
  {"report-password", OPT_REPORT_PASSWORD, "Undocumented.",
3389
 
   (char**) &report_password, (char**) &report_password, 0, GET_STR,
3390
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3391
 
  {"report-port", OPT_REPORT_PORT,
3392
 
   N_("Port for connecting to slave reported to the master during slave "
3393
 
      "registration. Set it only if the slave is listening on a non-default "
3394
 
      "port or if you have a special tunnel from the master or other clients "
3395
 
      "to the slave. If not sure, leave this option unset."),
3396
 
   (char**) &report_port, (char**) &report_port, 0, GET_UINT, REQUIRED_ARG,
3397
 
   DRIZZLE_PORT, 0, 0, 0, 0, 0},
3398
 
  {"safe-mode", OPT_SAFE,
3399
 
   N_("Skip some optimize stages (for testing)."),
3400
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1777
   (char**) &drizzled_bind_timeout,
 
1778
   (char**) &drizzled_bind_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3401
1779
  {"secure-file-priv", OPT_SECURE_FILE_PRIV,
3402
1780
   N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
3403
1781
      "within specified directory"),
3406
1784
  {"server-id", OPT_SERVER_ID,
3407
1785
   N_("Uniquely identifies the server instance in the community of "
3408
1786
      "replication partners."),
3409
 
   (char**) &server_id, (char**) &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0,
 
1787
   (char**) &server_id, (char**) &server_id, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 0,
3410
1788
   0, 0, 0},
3411
 
  {"skip-new", OPT_SKIP_NEW,
3412
 
   N_("Don't use new, possible wrong routines."),
3413
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
3414
 
  {"skip-slave-start", OPT_SKIP_SLAVE_START,
3415
 
   N_("If set, slave is not autostarted."),
3416
 
   (char**) &opt_skip_slave_start,
3417
 
   (char**) &opt_skip_slave_start, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3418
1789
  {"skip-stack-trace", OPT_SKIP_STACK_TRACE,
3419
1790
   N_("Don't print a stack trace on failure."),
3420
1791
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
3421
1792
   0, 0, 0, 0},
3422
 
  {"skip-thread-priority", OPT_SKIP_PRIOR,
3423
 
   N_("Don't give threads different priorities."),
3424
 
   0, 0, 0, GET_NO_ARG, NO_ARG,
3425
 
   DEFAULT_SKIP_THREAD_PRIORITY, 0, 0, 0, 0, 0},
3426
 
  {"slave-load-tmpdir", OPT_SLAVE_LOAD_TMPDIR,
3427
 
   N_("The location where the slave should put its temporary files when "
3428
 
      "replicating a LOAD DATA INFILE command."),
3429
 
   (char**) &slave_load_tmpdir, (char**) &slave_load_tmpdir, 0, GET_STR_ALLOC,
3430
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3431
 
  {"slave-skip-errors", OPT_SLAVE_SKIP_ERRORS,
3432
 
   N_("Tells the slave thread to continue replication when a query event "
3433
 
      "returns an error from the provided list."),
3434
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3435
 
  {"slave-exec-mode", OPT_SLAVE_EXEC_MODE,
3436
 
   N_("Modes for how replication events should be executed.  Legal values are "
3437
 
      "STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, replication will "
3438
 
      "not stop for operations that are idempotent. In STRICT mode, "
3439
 
      "replication will stop on any unexpected difference between the master "
3440
 
      "and the slave."),
3441
 
   (char**) &slave_exec_mode_str, (char**) &slave_exec_mode_str,
3442
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3443
 
  {"sql-bin-update-same", OPT_SQL_BIN_UPDATE_SAME,
3444
 
   N_("(INGORED)"),
3445
 
   0, 0, 0, GET_DISABLED, NO_ARG, 0, 0, 0, 0, 0, 0},
3446
1793
  {"symbolic-links", 's',
3447
1794
   N_("Enable symbolic link support."),
3448
1795
   (char**) &my_use_symdir, (char**) &my_use_symdir, 0, GET_BOOL, NO_ARG,
3452
1799
     option if compiled with valgrind support.
3453
1800
   */
3454
1801
   IF_PURIFY(0,1), 0, 0, 0, 0, 0},
3455
 
  {"sysdate-is-now", OPT_SYSDATE_IS_NOW,
3456
 
   N_("Non-default option to alias SYSDATE() to NOW() to make it "
3457
 
      "safe-replicable."),
3458
 
   (char**) &global_system_variables.sysdate_is_now,
3459
 
   0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
3460
 
  {"tc-heuristic-recover", OPT_TC_HEURISTIC_RECOVER,
3461
 
   N_("Decision to use in heuristic recover process. Possible values are "
3462
 
      "COMMIT or ROLLBACK."),
3463
 
   (char**) &opt_tc_heuristic_recover, (char**) &opt_tc_heuristic_recover,
3464
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3465
 
  {"temp-pool", OPT_TEMP_POOL,
3466
 
   N_("Using this option will cause most temporary files created to use a "
3467
 
      "small set of names, rather than a unique name for each new file."),
3468
 
   (char**) &use_temp_pool, (char**) &use_temp_pool, 0, GET_BOOL, NO_ARG, 1,
3469
 
   0, 0, 0, 0, 0},
3470
1802
  {"timed_mutexes", OPT_TIMED_MUTEXES,
3471
1803
   N_("Specify whether to time mutexes (only InnoDB mutexes are currently "
3472
1804
      "supported)"),
3473
1805
   (char**) &timed_mutexes, (char**) &timed_mutexes, 0, GET_BOOL, NO_ARG, 0,
3474
1806
    0, 0, 0, 0, 0},
3475
1807
  {"tmpdir", 't',
3476
 
   N_("Path for temporary files. Several paths may be specified, separated "
3477
 
      "by a colon (:)"
3478
 
      ", in this case they are used in a round-robin fashion."),
3479
 
   (char**) &opt_mysql_tmpdir,
3480
 
   (char**) &opt_mysql_tmpdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1808
   N_("Path for temporary files."),
 
1809
   (char**) &opt_drizzle_tmpdir,
 
1810
   (char**) &opt_drizzle_tmpdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3481
1811
  {"transaction-isolation", OPT_TX_ISOLATION,
3482
1812
   N_("Default transaction isolation level."),
3483
1813
   0, 0, 0, GET_STR, REQUIRED_ARG, 0,
3484
1814
   0, 0, 0, 0, 0},
3485
1815
  {"user", 'u',
3486
 
   N_("Run mysqld daemon as user."),
 
1816
   N_("Run drizzled daemon as user."),
3487
1817
   0, 0, 0, GET_STR, REQUIRED_ARG,
3488
1818
   0, 0, 0, 0, 0, 0},
3489
1819
  {"version", 'V',
3491
1821
   0, 0, 0, GET_NO_ARG,
3492
1822
   NO_ARG, 0, 0, 0, 0, 0, 0},
3493
1823
  {"back_log", OPT_BACK_LOG,
3494
 
   N_("The number of outstanding connection requests MySQL can have. This "
3495
 
      "comes into play when the main MySQL thread gets very many connection "
 
1824
   N_("The number of outstanding connection requests Drizzle can have. This "
 
1825
      "comes into play when the main Drizzle thread gets very many connection "
3496
1826
      "requests in a very short time."),
3497
 
    (char**) &back_log, (char**) &back_log, 0, GET_ULONG,
 
1827
    (char**) &back_log, (char**) &back_log, 0, GET_UINT,
3498
1828
    REQUIRED_ARG, 50, 1, 65535, 0, 1, 0 },
3499
 
  { "binlog_cache_size", OPT_BINLOG_CACHE_SIZE,
3500
 
    N_("The size of the cache to hold the SQL statements for the binary log "
3501
 
       "during a transaction. If you often use big, multi-statement "
3502
 
       "transactions you can increase this to get more performance."),
3503
 
    (char**) &binlog_cache_size, (char**) &binlog_cache_size, 0, GET_ULONG,
3504
 
    REQUIRED_ARG, 32*1024L, IO_SIZE, ULONG_MAX, 0, IO_SIZE, 0},
3505
1829
  { "bulk_insert_buffer_size", OPT_BULK_INSERT_BUFFER_SIZE,
3506
 
    N_("Size of tree cache used in bulk insert optimisation. Note that this is "
 
1830
    N_("Size of tree cache used in bulk insert optimization. Note that this is "
3507
1831
       "a limit per thread!"),
3508
1832
    (char**) &global_system_variables.bulk_insert_buff_size,
3509
1833
    (char**) &max_system_variables.bulk_insert_buff_size,
3510
 
    0, GET_ULONG, REQUIRED_ARG, 8192*1024, 0, ULONG_MAX, 0, 1, 0},
3511
 
  { "connect_timeout", OPT_CONNECT_TIMEOUT,
3512
 
    N_("The number of seconds the mysqld server is waiting for a connect "
3513
 
       "packet before responding with 'Bad handshake'."),
3514
 
    (char**) &connect_timeout, (char**) &connect_timeout,
3515
 
    0, GET_ULONG, REQUIRED_ARG, CONNECT_TIMEOUT, 2, LONG_TIMEOUT, 0, 1, 0 },
3516
 
  { "date_format", OPT_DATE_FORMAT,
3517
 
    N_("The DATE format (For future)."),
3518
 
    (char**) &opt_date_time_formats[DRIZZLE_TIMESTAMP_DATE],
3519
 
    (char**) &opt_date_time_formats[DRIZZLE_TIMESTAMP_DATE],
3520
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3521
 
  { "datetime_format", OPT_DATETIME_FORMAT,
3522
 
    N_("The DATETIME/TIMESTAMP format (for future)."),
3523
 
    (char**) &opt_date_time_formats[DRIZZLE_TIMESTAMP_DATETIME],
3524
 
    (char**) &opt_date_time_formats[DRIZZLE_TIMESTAMP_DATETIME],
3525
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3526
 
  { "default_week_format", OPT_DEFAULT_WEEK_FORMAT,
3527
 
    N_("The default week format used by WEEK() functions."),
3528
 
    (char**) &global_system_variables.default_week_format,
3529
 
    (char**) &max_system_variables.default_week_format,
3530
 
    0, GET_ULONG, REQUIRED_ARG, 0, 0, 7L, 0, 1, 0},
 
1834
    0, GET_ULL, REQUIRED_ARG, 8192*1024, 0, ULONG_MAX, 0, 1, 0},
3531
1835
  { "div_precision_increment", OPT_DIV_PRECINCREMENT,
3532
1836
   N_("Precision of the result of '/' operator will be increased on that "
3533
1837
      "value."),
3534
1838
   (char**) &global_system_variables.div_precincrement,
3535
 
   (char**) &max_system_variables.div_precincrement, 0, GET_ULONG,
 
1839
   (char**) &max_system_variables.div_precincrement, 0, GET_UINT,
3536
1840
   REQUIRED_ARG, 4, 0, DECIMAL_MAX_SCALE, 0, 0, 0},
3537
 
  { "expire_logs_days", OPT_EXPIRE_LOGS_DAYS,
3538
 
    N_("If non-zero, binary logs will be purged after expire_logs_days "
3539
 
       "days; possible purges happen at startup and at binary log rotation."),
3540
 
    (char**) &expire_logs_days,
3541
 
    (char**) &expire_logs_days, 0, GET_ULONG,
3542
 
    REQUIRED_ARG, 0, 0, 99, 0, 1, 0},
3543
1841
  { "group_concat_max_len", OPT_GROUP_CONCAT_MAX_LEN,
3544
1842
    N_("The maximum length of the result of function  group_concat."),
3545
1843
    (char**) &global_system_variables.group_concat_max_len,
3546
 
    (char**) &max_system_variables.group_concat_max_len, 0, GET_ULONG,
 
1844
    (char**) &max_system_variables.group_concat_max_len, 0, GET_UINT64,
3547
1845
    REQUIRED_ARG, 1024, 4, ULONG_MAX, 0, 1, 0},
3548
 
  { "interactive_timeout", OPT_INTERACTIVE_TIMEOUT,
3549
 
    N_("The number of seconds the server waits for activity on an interactive "
3550
 
       "connection before closing it."),
3551
 
   (char**) &global_system_variables.net_interactive_timeout,
3552
 
   (char**) &max_system_variables.net_interactive_timeout, 0,
3553
 
   GET_ULONG, REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
3554
1846
  { "join_buffer_size", OPT_JOIN_BUFF_SIZE,
3555
1847
    N_("The size of the buffer that is used for full joins."),
3556
1848
   (char**) &global_system_variables.join_buff_size,
3557
 
   (char**) &max_system_variables.join_buff_size, 0, GET_ULONG,
 
1849
   (char**) &max_system_variables.join_buff_size, 0, GET_UINT64,
3558
1850
   REQUIRED_ARG, 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ULONG_MAX,
3559
1851
   MALLOC_OVERHEAD, IO_SIZE, 0},
3560
 
  {"keep_files_on_create", OPT_KEEP_FILES_ON_CREATE,
3561
 
   N_("Don't overwrite stale .MYD and .MYI even if no directory is specified."),
3562
 
   (char**) &global_system_variables.keep_files_on_create,
3563
 
   (char**) &max_system_variables.keep_files_on_create,
3564
 
   0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
3565
1852
  {"key_buffer_size", OPT_KEY_BUFFER_SIZE,
3566
1853
   N_("The size of the buffer used for index blocks for MyISAM tables. "
3567
1854
      "Increase this to get better index handling (for all reads and multiple "
3568
1855
      "writes) to as much as you can afford;"),
3569
1856
   (char**) &dflt_key_cache_var.param_buff_size,
3570
1857
   (char**) 0,
3571
 
   0, (GET_ULL | GET_ASK_ADDR),
 
1858
   0, (GET_ULL),
3572
1859
   REQUIRED_ARG, KEY_CACHE_SIZE, MALLOC_OVERHEAD, SIZE_T_MAX, MALLOC_OVERHEAD,
3573
1860
   IO_SIZE, 0},
3574
1861
  {"key_cache_age_threshold", OPT_KEY_CACHE_AGE_THRESHOLD,
3578
1865
      "total number of blocks in key cache"),
3579
1866
   (char**) &dflt_key_cache_var.param_age_threshold,
3580
1867
   (char**) 0,
3581
 
   0, (GET_ULONG | GET_ASK_ADDR), REQUIRED_ARG,
 
1868
   0, (GET_UINT32), REQUIRED_ARG,
3582
1869
   300, 100, ULONG_MAX, 0, 100, 0},
3583
1870
  {"key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,
3584
1871
   N_("The default size of key cache blocks"),
3585
1872
   (char**) &dflt_key_cache_var.param_block_size,
3586
1873
   (char**) 0,
3587
 
   0, (GET_ULONG | GET_ASK_ADDR), REQUIRED_ARG,
 
1874
   0, (GET_UINT32), REQUIRED_ARG,
3588
1875
   KEY_CACHE_BLOCK_SIZE, 512, 1024 * 16, 0, 512, 0},
3589
1876
  {"key_cache_division_limit", OPT_KEY_CACHE_DIVISION_LIMIT,
3590
1877
   N_("The minimum percentage of warm blocks in key cache"),
3591
1878
   (char**) &dflt_key_cache_var.param_division_limit,
3592
1879
   (char**) 0,
3593
 
   0, (GET_ULONG | GET_ASK_ADDR) , REQUIRED_ARG, 100,
 
1880
   0, (GET_UINT32) , REQUIRED_ARG, 100,
3594
1881
   1, 100, 0, 1, 0},
3595
 
  {"long_query_time", OPT_LONG_QUERY_TIME,
3596
 
   N_("Log all queries that have taken more than long_query_time seconds to "
3597
 
      "execute to file. The argument will be treated as a decimal value with "
3598
 
      "microsecond precission."),
3599
 
   (char**) &long_query_time, (char**) &long_query_time, 0, GET_DOUBLE,
3600
 
   REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0},
3601
1882
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
3602
1883
   N_("Max packetlength to send/receive from to server."),
3603
1884
   (char**) &global_system_variables.max_allowed_packet,
3604
 
   (char**) &max_system_variables.max_allowed_packet, 0, GET_ULONG,
 
1885
   (char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
3605
1886
   REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
3606
 
  {"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE,
3607
 
   N_("Can be used to restrict the total size used to cache a "
3608
 
      "multi-transaction query."),
3609
 
   (char**) &max_binlog_cache_size, (char**) &max_binlog_cache_size, 0,
3610
 
   GET_ULONG, REQUIRED_ARG, ULONG_MAX, IO_SIZE, ULONG_MAX, 0, IO_SIZE, 0},
3611
 
  {"max_binlog_size", OPT_MAX_BINLOG_SIZE,
3612
 
   N_("Binary log will be rotated automatically when the size exceeds this "
3613
 
      "value. Will also apply to relay logs if max_relay_log_size is 0. "
3614
 
      "The minimum value for this variable is 4096."),
3615
 
   (char**) &max_binlog_size, (char**) &max_binlog_size, 0, GET_ULONG,
3616
 
   REQUIRED_ARG, 1024*1024L*1024L, IO_SIZE, 1024*1024L*1024L, 0, IO_SIZE, 0},
3617
1887
  {"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
3618
1888
   N_("If there is more than this number of interrupted connections from a "
3619
1889
      "host this host will be blocked from further connections."),
3620
 
   (char**) &max_connect_errors, (char**) &max_connect_errors, 0, GET_ULONG,
 
1890
   (char**) &max_connect_errors, (char**) &max_connect_errors, 0, GET_UINT64,
3621
1891
   REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ULONG_MAX, 0, 1, 0},
3622
 
  // Default max_connections of 151 is larger than Apache's default max
3623
 
  // children, to avoid "too many connections" error in a common setup
3624
 
  {"max_connections", OPT_MAX_CONNECTIONS,
3625
 
   N_("The number of simultaneous clients allowed."),
3626
 
   (char**) &max_connections,
3627
 
   (char**) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 151, 1, 100000, 0, 1,
3628
 
   0},
3629
1892
  {"max_error_count", OPT_MAX_ERROR_COUNT,
3630
1893
   N_("Max number of errors/warnings to store for a statement."),
3631
1894
   (char**) &global_system_variables.max_error_count,
3632
1895
   (char**) &max_system_variables.max_error_count,
3633
 
   0, GET_ULONG, REQUIRED_ARG, DEFAULT_ERROR_COUNT, 0, 65535, 0, 1, 0},
 
1896
   0, GET_UINT64, REQUIRED_ARG, DEFAULT_ERROR_COUNT, 0, 65535, 0, 1, 0},
3634
1897
  {"max_heap_table_size", OPT_MAX_HEP_TABLE_SIZE,
3635
1898
   N_("Don't allow creation of heap tables bigger than this."),
3636
1899
   (char**) &global_system_variables.max_heap_table_size,
3646
1909
  {"max_length_for_sort_data", OPT_MAX_LENGTH_FOR_SORT_DATA,
3647
1910
   N_("Max number of bytes in sorted records."),
3648
1911
   (char**) &global_system_variables.max_length_for_sort_data,
3649
 
   (char**) &max_system_variables.max_length_for_sort_data, 0, GET_ULONG,
 
1912
   (char**) &max_system_variables.max_length_for_sort_data, 0, GET_ULL,
3650
1913
   REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
3651
 
  {"max_relay_log_size", OPT_MAX_RELAY_LOG_SIZE,
3652
 
   N_("If non-zero: relay log will be rotated automatically when the size "
3653
 
      "exceeds this value; if zero (the default): when the size exceeds "
3654
 
      "max_binlog_size. 0 excepted, the minimum value for this variable "
3655
 
      "is 4096."),
3656
 
   (char**) &max_relay_log_size, (char**) &max_relay_log_size, 0, GET_ULONG,
3657
 
   REQUIRED_ARG, 0L, 0L, 1024*1024L*1024L, 0, IO_SIZE, 0},
3658
1914
  { "max_seeks_for_key", OPT_MAX_SEEKS_FOR_KEY,
3659
1915
    N_("Limit assumed max number of seeks when looking up rows based on a key"),
3660
1916
    (char**) &global_system_variables.max_seeks_for_key,
3661
 
    (char**) &max_system_variables.max_seeks_for_key, 0, GET_ULONG,
 
1917
    (char**) &max_system_variables.max_seeks_for_key, 0, GET_UINT64,
3662
1918
    REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0 },
3663
1919
  {"max_sort_length", OPT_MAX_SORT_LENGTH,
3664
1920
   N_("The number of bytes to use when sorting BLOB or TEXT values "
3665
1921
      "(only the first max_sort_length bytes of each value are used; the "
3666
1922
      "rest are ignored)."),
3667
1923
   (char**) &global_system_variables.max_sort_length,
3668
 
   (char**) &max_system_variables.max_sort_length, 0, GET_ULONG,
 
1924
   (char**) &max_system_variables.max_sort_length, 0, GET_SIZE,
3669
1925
   REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
3670
 
  {"max_tmp_tables", OPT_MAX_TMP_TABLES,
3671
 
   N_("Maximum number of temporary tables a client can keep open at a time."),
3672
 
   (char**) &global_system_variables.max_tmp_tables,
3673
 
   (char**) &max_system_variables.max_tmp_tables, 0, GET_ULONG,
3674
 
   REQUIRED_ARG, 32, 1, ULONG_MAX, 0, 1, 0},
3675
1926
  {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT,
3676
1927
   N_("After this many write locks, allow some read locks to run in between."),
3677
 
   (char**) &max_write_lock_count, (char**) &max_write_lock_count, 0, GET_ULONG,
 
1928
   (char**) &max_write_lock_count, (char**) &max_write_lock_count, 0, GET_ULL,
3678
1929
   REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0},
3679
1930
  {"min_examined_row_limit", OPT_MIN_EXAMINED_ROW_LIMIT,
3680
1931
   N_("Don't log queries which examine less than min_examined_row_limit "
3681
1932
      "rows to file."),
3682
1933
   (char**) &global_system_variables.min_examined_row_limit,
3683
 
   (char**) &max_system_variables.min_examined_row_limit, 0, GET_ULONG,
 
1934
   (char**) &max_system_variables.min_examined_row_limit, 0, GET_ULL,
3684
1935
   REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1L, 0},
3685
 
  {"myisam_block_size", OPT_MYISAM_BLOCK_SIZE,
3686
 
   N_("Block size to be used for MyISAM index pages."),
3687
 
   (char**) &opt_myisam_block_size,
3688
 
   (char**) &opt_myisam_block_size, 0, GET_ULONG, REQUIRED_ARG,
3689
 
   MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, MI_MAX_KEY_BLOCK_LENGTH,
3690
 
   0, MI_MIN_KEY_BLOCK_LENGTH, 0},
3691
 
  {"myisam_data_pointer_size", OPT_MYISAM_DATA_POINTER_SIZE,
3692
 
   N_("Default pointer size to be used for MyISAM tables."),
3693
 
   (char**) &myisam_data_pointer_size,
3694
 
   (char**) &myisam_data_pointer_size, 0, GET_ULONG, REQUIRED_ARG,
3695
 
   6, 2, 7, 0, 1, 0},
3696
 
  {"myisam_max_sort_file_size", OPT_MYISAM_MAX_SORT_FILE_SIZE,
3697
 
   N_("Don't use the fast sort index method to created index if the "
3698
 
      "temporary file would get bigger than this."),
3699
 
   (char**) &global_system_variables.myisam_max_sort_file_size,
3700
 
   (char**) &max_system_variables.myisam_max_sort_file_size, 0,
3701
 
   GET_ULL, REQUIRED_ARG, (int64_t) LONG_MAX, 0, (uint64_t) MAX_FILE_SIZE,
3702
 
   0, 1024*1024, 0},
3703
 
  {"myisam_repair_threads", OPT_MYISAM_REPAIR_THREADS,
3704
 
   N_("Number of threads to use when repairing MyISAM tables. The value of "
3705
 
      "1 disables parallel repair."),
3706
 
   (char**) &global_system_variables.myisam_repair_threads,
3707
 
   (char**) &max_system_variables.myisam_repair_threads, 0,
3708
 
   GET_ULONG, REQUIRED_ARG, 1, 1, ULONG_MAX, 0, 1, 0},
3709
 
  {"myisam_sort_buffer_size", OPT_MYISAM_SORT_BUFFER_SIZE,
3710
 
   N_("The buffer that is allocated when sorting the index when doing a "
3711
 
      "REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
3712
 
   (char**) &global_system_variables.myisam_sort_buff_size,
3713
 
   (char**) &max_system_variables.myisam_sort_buff_size, 0,
3714
 
   GET_ULONG, REQUIRED_ARG, 8192*1024, 4, INT32_MAX, 0, 1, 0},
3715
 
  {"myisam_stats_method", OPT_MYISAM_STATS_METHOD,
3716
 
   N_("Specifies how MyISAM index statistics collection code should threat "
3717
 
      "NULLs. Possible values of name are 'nulls_unequal' "
3718
 
      "(default behavior), "
3719
 
      "'nulls_equal' (emulate MySQL 4.0 behavior), and 'nulls_ignored'."),
3720
 
   (char**) &myisam_stats_method_str, (char**) &myisam_stats_method_str, 0,
3721
 
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3722
1936
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
3723
1937
   N_("Buffer length for TCP/IP and socket communication."),
3724
1938
   (char**) &global_system_variables.net_buffer_length,
3725
 
   (char**) &max_system_variables.net_buffer_length, 0, GET_ULONG,
 
1939
   (char**) &max_system_variables.net_buffer_length, 0, GET_UINT32,
3726
1940
   REQUIRED_ARG, 16384, 1024, 1024*1024L, 0, 1024, 0},
3727
 
  {"net_read_timeout", OPT_NET_READ_TIMEOUT,
3728
 
   N_("Number of seconds to wait for more data from a connection before "
3729
 
      "aborting the read."),
3730
 
   (char**) &global_system_variables.net_read_timeout,
3731
 
   (char**) &max_system_variables.net_read_timeout, 0, GET_ULONG,
3732
 
   REQUIRED_ARG, NET_READ_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
3733
 
  {"net_retry_count", OPT_NET_RETRY_COUNT,
3734
 
   N_("If a read on a communication port is interrupted, retry this many "
3735
 
      "times before giving up."),
3736
 
   (char**) &global_system_variables.net_retry_count,
3737
 
   (char**) &max_system_variables.net_retry_count,0,
3738
 
   GET_ULONG, REQUIRED_ARG, MYSQLD_NET_RETRY_COUNT, 1, ULONG_MAX, 0, 1, 0},
3739
 
  {"net_write_timeout", OPT_NET_WRITE_TIMEOUT,
3740
 
   N_("Number of seconds to wait for a block to be written to a connection "
3741
 
      "before aborting the write."),
3742
 
   (char**) &global_system_variables.net_write_timeout,
3743
 
   (char**) &max_system_variables.net_write_timeout, 0, GET_ULONG,
3744
 
   REQUIRED_ARG, NET_WRITE_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
3745
 
  { "old", OPT_OLD_MODE,
3746
 
    N_("Use compatible behavior."),
3747
 
    (char**) &global_system_variables.old_mode,
3748
 
    (char**) &max_system_variables.old_mode, 0, GET_BOOL, NO_ARG,
3749
 
    0, 0, 0, 0, 0, 0},
3750
 
  {"open_files_limit", OPT_OPEN_FILES_LIMIT,
3751
 
   N_("If this is not 0, then mysqld will use this value to reserve file "
3752
 
      "descriptors to use with setrlimit(). If this value is 0 then mysqld "
3753
 
      "will reserve max_connections*5 or max_connections + table_cache*2 "
3754
 
      "(whichever is larger) number of files."),
3755
 
   (char**) &open_files_limit, (char**) &open_files_limit, 0, GET_ULONG,
3756
 
   REQUIRED_ARG, 0, 0, OS_FILE_LIMIT, 0, 1, 0},
3757
1941
  {"optimizer_prune_level", OPT_OPTIMIZER_PRUNE_LEVEL,
3758
 
   N_("Controls the heuristic(s) applied during query optimization to prune "
3759
 
      "less-promising partial plans from the optimizer search space. Meaning: "
3760
 
      "0 - do not apply any heuristic, thus perform exhaustive search; "
3761
 
      "1 - prune plans based on number of retrieved rows."),
3762
 
   (char**) &global_system_variables.optimizer_prune_level,
3763
 
   (char**) &max_system_variables.optimizer_prune_level,
3764
 
   0, GET_ULONG, OPT_ARG, 1, 0, 1, 0, 1, 0},
 
1942
    N_("Controls the heuristic(s) applied during query optimization to prune "
 
1943
       "less-promising partial plans from the optimizer search space. Meaning: "
 
1944
       "false - do not apply any heuristic, thus perform exhaustive search; "
 
1945
       "true - prune plans based on number of retrieved rows."),
 
1946
    (char**) &global_system_variables.optimizer_prune_level,
 
1947
    (char**) &max_system_variables.optimizer_prune_level,
 
1948
    0, GET_BOOL, OPT_ARG, 1, 0, 1, 0, 1, 0},
3765
1949
  {"optimizer_search_depth", OPT_OPTIMIZER_SEARCH_DEPTH,
3766
1950
   N_("Maximum depth of search performed by the query optimizer. Values "
3767
1951
      "larger than the number of relations in a query result in better query "
3773
1957
      "testing/comparison)."),
3774
1958
   (char**) &global_system_variables.optimizer_search_depth,
3775
1959
   (char**) &max_system_variables.optimizer_search_depth,
3776
 
   0, GET_ULONG, OPT_ARG, MAX_TABLES+1, 0, MAX_TABLES+2, 0, 1, 0},
 
1960
   0, GET_UINT, OPT_ARG, 0, 0, MAX_TABLES+2, 0, 1, 0},
3777
1961
  {"plugin_dir", OPT_PLUGIN_DIR,
3778
1962
   N_("Directory for plugins."),
3779
1963
   (char**) &opt_plugin_dir_ptr, (char**) &opt_plugin_dir_ptr, 0,
3780
1964
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3781
1965
  {"plugin_load", OPT_PLUGIN_LOAD,
3782
 
   N_("Optional comma separated list of plugins to load, where each plugin is "
3783
 
      "identified by the name of the shared library. "
3784
 
      "[for example: --plugin_load=libmd5udf.so]"),
 
1966
   N_("Optional comma separated list of plugins to load at starup."
 
1967
      "[for example: --plugin_load=crc32,logger_gearman]"),
3785
1968
   (char**) &opt_plugin_load, (char**) &opt_plugin_load, 0,
3786
1969
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3787
1970
  {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
3788
1971
   N_("The size of the buffer that is allocated when preloading indexes"),
3789
1972
   (char**) &global_system_variables.preload_buff_size,
3790
 
   (char**) &max_system_variables.preload_buff_size, 0, GET_ULONG,
 
1973
   (char**) &max_system_variables.preload_buff_size, 0, GET_ULL,
3791
1974
   REQUIRED_ARG, 32*1024L, 1024, 1024*1024*1024L, 0, 1, 0},
3792
1975
  {"query_alloc_block_size", OPT_QUERY_ALLOC_BLOCK_SIZE,
3793
1976
   N_("Allocation block size for query parsing and execution"),
3794
1977
   (char**) &global_system_variables.query_alloc_block_size,
3795
 
   (char**) &max_system_variables.query_alloc_block_size, 0, GET_ULONG,
 
1978
   (char**) &max_system_variables.query_alloc_block_size, 0, GET_UINT,
3796
1979
   REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
3797
1980
  {"query_prealloc_size", OPT_QUERY_PREALLOC_SIZE,
3798
1981
   N_("Persistent buffer for query parsing and execution"),
3799
1982
   (char**) &global_system_variables.query_prealloc_size,
3800
 
   (char**) &max_system_variables.query_prealloc_size, 0, GET_ULONG,
 
1983
   (char**) &max_system_variables.query_prealloc_size, 0, GET_UINT,
3801
1984
   REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, QUERY_ALLOC_PREALLOC_SIZE,
3802
1985
   ULONG_MAX, 0, 1024, 0},
3803
1986
  {"range_alloc_block_size", OPT_RANGE_ALLOC_BLOCK_SIZE,
3804
1987
   N_("Allocation block size for storing ranges during optimization"),
3805
1988
   (char**) &global_system_variables.range_alloc_block_size,
3806
 
   (char**) &max_system_variables.range_alloc_block_size, 0, GET_ULONG,
3807
 
   REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, ULONG_MAX,
 
1989
   (char**) &max_system_variables.range_alloc_block_size, 0, GET_SIZE,
 
1990
   REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, SIZE_MAX,
3808
1991
   0, 1024, 0},
3809
1992
  {"read_buffer_size", OPT_RECORD_BUFFER,
3810
 
   N_("Each thread that does a sequential scan allocates a buffer of this "
3811
 
      "size for each table it scans. If you do many sequential scans, you may "
3812
 
      "want to increase this value."),
3813
 
   (char**) &global_system_variables.read_buff_size,
3814
 
   (char**) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG,
3815
 
   128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT32_MAX, MALLOC_OVERHEAD, IO_SIZE,
3816
 
   0},
3817
 
  {"read_only", OPT_READONLY,
3818
 
   N_("Make all non-temporary tables read-only, with the exception for "
3819
 
      "replication (slave) threads and users with the SUPER privilege"),
3820
 
   (char**) &opt_readonly,
3821
 
   (char**) &opt_readonly,
3822
 
   0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
 
1993
    N_("Each thread that does a sequential scan allocates a buffer of this "
 
1994
       "size for each table it scans. If you do many sequential scans, you may "
 
1995
       "want to increase this value."),
 
1996
    (char**) &global_system_variables.read_buff_size,
 
1997
    (char**) &max_system_variables.read_buff_size,0, GET_UINT, REQUIRED_ARG,
 
1998
    128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT32_MAX, MALLOC_OVERHEAD, IO_SIZE,
 
1999
    0},
3823
2000
  {"read_rnd_buffer_size", OPT_RECORD_RND_BUFFER,
3824
2001
   N_("When reading rows in sorted order after a sort, the rows are read "
3825
2002
      "through this buffer to avoid a disk seeks. If not set, then it's set "
3826
2003
      "to the value of record_buffer."),
3827
2004
   (char**) &global_system_variables.read_rnd_buff_size,
3828
2005
   (char**) &max_system_variables.read_rnd_buff_size, 0,
3829
 
   GET_ULONG, REQUIRED_ARG, 256*1024L, 64 /*IO_SIZE*2+MALLOC_OVERHEAD*/ ,
3830
 
   INT32_MAX, MALLOC_OVERHEAD, 1 /* Small lower limit to be able to test MRR */, 0},
3831
 
  {"record_buffer", OPT_RECORD_BUFFER,
3832
 
   "Alias for read_buffer_size",
3833
 
   (char**) &global_system_variables.read_buff_size,
3834
 
   (char**) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG,
3835
 
   128*1024L, IO_SIZE*2+MALLOC_OVERHEAD,
3836
 
   INT32_MAX, MALLOC_OVERHEAD, IO_SIZE, 0},
3837
 
  {"relay_log_purge", OPT_RELAY_LOG_PURGE,
3838
 
   N_("0 = do not purge relay logs. "
3839
 
      "1 = purge them as soon as they are no more needed."),
3840
 
   (char**) &relay_log_purge,
3841
 
   (char**) &relay_log_purge, 0, GET_BOOL, NO_ARG,
3842
 
   1, 0, 1, 0, 1, 0},
3843
 
  {"relay_log_space_limit", OPT_RELAY_LOG_SPACE_LIMIT,
3844
 
   N_("Maximum space to use for all relay logs."),
3845
 
   (char**) &relay_log_space_limit,
3846
 
   (char**) &relay_log_space_limit, 0, GET_ULL, REQUIRED_ARG, 0L, 0L,
3847
 
   (int64_t) ULONG_MAX, 0, 1, 0},
3848
 
  {"slave_compressed_protocol", OPT_SLAVE_COMPRESSED_PROTOCOL,
3849
 
   N_("Use compression on master/slave protocol."),
3850
 
   (char**) &opt_slave_compressed_protocol,
3851
 
   (char**) &opt_slave_compressed_protocol,
3852
 
   0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
3853
 
  {"slave_net_timeout", OPT_SLAVE_NET_TIMEOUT,
3854
 
   N_("Number of seconds to wait for more data from a master/slave connection "
3855
 
      "before aborting the read."),
3856
 
   (char**) &slave_net_timeout, (char**) &slave_net_timeout, 0,
3857
 
   GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
3858
 
  {"slave_transaction_retries", OPT_SLAVE_TRANS_RETRIES,
3859
 
   N_("Number of times the slave SQL thread will retry a transaction in case "
3860
 
      "it failed with a deadlock or elapsed lock wait timeout, "
3861
 
      "before giving up and stopping."),
3862
 
   (char**) &slave_trans_retries, (char**) &slave_trans_retries, 0,
3863
 
   GET_ULONG, REQUIRED_ARG, 10L, 0L, (int64_t) ULONG_MAX, 0, 1, 0},
3864
 
  {"slave-allow-batching", OPT_SLAVE_ALLOW_BATCHING,
3865
 
   N_("Allow slave to batch requests."),
3866
 
   (char**) &slave_allow_batching, (char**) &slave_allow_batching,
3867
 
   0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
3868
 
  {"slow_launch_time", OPT_SLOW_LAUNCH_TIME,
3869
 
   N_("If creating the thread takes longer than this value (in seconds), the "
3870
 
      "Slow_launch_threads counter will be incremented."),
3871
 
   (char**) &slow_launch_time, (char**) &slow_launch_time, 0, GET_ULONG,
3872
 
   REQUIRED_ARG, 2L, 0L, LONG_TIMEOUT, 0, 1, 0},
 
2006
   GET_UINT, REQUIRED_ARG, 256*1024L, 64 /*IO_SIZE*2+MALLOC_OVERHEAD*/ ,
 
2007
   UINT32_MAX, MALLOC_OVERHEAD, 1 /* Small lower limit to be able to test MRR */, 0},
 
2008
  {"scheduler", OPT_SCHEDULER,
 
2009
   N_("Select scheduler to be used (by default multi-thread)."),
 
2010
   (char**)&opt_scheduler, (char**)&opt_scheduler,
 
2011
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
2012
  /* x8 compared to MySQL's x2. We have UTF8 to consider. */
3873
2013
  {"sort_buffer_size", OPT_SORT_BUFFER,
3874
2014
   N_("Each thread that needs to do a sort allocates a buffer of this size."),
3875
2015
   (char**) &global_system_variables.sortbuff_size,
3876
 
   (char**) &max_system_variables.sortbuff_size, 0, GET_ULONG, REQUIRED_ARG,
3877
 
   MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*2, ULONG_MAX,
 
2016
   (char**) &max_system_variables.sortbuff_size, 0, GET_SIZE, REQUIRED_ARG,
 
2017
   MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*8, SIZE_MAX,
3878
2018
   MALLOC_OVERHEAD, 1, 0},
3879
 
  {"sync-binlog", OPT_SYNC_BINLOG,
3880
 
   N_("Synchronously flush binary log to disk after every #th event. "
3881
 
      "Use 0 (default) to disable synchronous flushing."),
3882
 
   (char**) &sync_binlog_period, (char**) &sync_binlog_period, 0, GET_ULONG,
3883
 
   REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1, 0},
3884
2019
  {"table_definition_cache", OPT_TABLE_DEF_CACHE,
3885
2020
   N_("The number of cached table definitions."),
3886
2021
   (char**) &table_def_size, (char**) &table_def_size,
3887
 
   0, GET_ULONG, REQUIRED_ARG, 128, 1, 512*1024L, 0, 1, 0},
 
2022
   0, GET_ULL, REQUIRED_ARG, 128, 1, 512*1024L, 0, 1, 0},
3888
2023
  {"table_open_cache", OPT_TABLE_OPEN_CACHE,
3889
2024
   N_("The number of cached open tables."),
3890
 
   (char**) &table_cache_size, (char**) &table_cache_size, 0, GET_ULONG,
 
2025
   (char**) &table_cache_size, (char**) &table_cache_size, 0, GET_UINT64,
3891
2026
   REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0},
3892
2027
  {"table_lock_wait_timeout", OPT_TABLE_LOCK_WAIT_TIMEOUT,
3893
2028
   N_("Timeout in seconds to wait for a table level lock before returning an "
3894
2029
      "error. Used only if the connection has active cursors."),
3895
2030
   (char**) &table_lock_wait_timeout, (char**) &table_lock_wait_timeout,
3896
 
   0, GET_ULONG, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
3897
 
  {"thread_cache_size", OPT_THREAD_CACHE_SIZE,
3898
 
   N_("How many threads we should keep in a cache for reuse."),
3899
 
   (char**) &thread_cache_size, (char**) &thread_cache_size, 0, GET_ULONG,
3900
 
   REQUIRED_ARG, 0, 0, 16384, 0, 1, 0},
3901
 
  {"thread_pool_size", OPT_THREAD_CACHE_SIZE,
3902
 
   N_("How many threads we should create to handle query requests in case of "
3903
 
      "'thread_handling=pool-of-threads'"),
3904
 
   (char**) &thread_pool_size, (char**) &thread_pool_size, 0, GET_ULONG,
3905
 
   REQUIRED_ARG, 20, 1, 16384, 0, 1, 0},
 
2031
   0, GET_ULL, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
3906
2032
  {"thread_stack", OPT_THREAD_STACK,
3907
2033
   N_("The stack size for each thread."),
3908
2034
   (char**) &my_thread_stack_size,
3909
 
   (char**) &my_thread_stack_size, 0, GET_ULONG,
 
2035
   (char**) &my_thread_stack_size, 0, GET_SIZE,
3910
2036
   REQUIRED_ARG,DEFAULT_THREAD_STACK,
3911
 
   1024L*128L, ULONG_MAX, 0, 1024, 0},
3912
 
  { "time_format", OPT_TIME_FORMAT,
3913
 
    N_("The TIME format (for future)."),
3914
 
    (char**) &opt_date_time_formats[DRIZZLE_TIMESTAMP_TIME],
3915
 
    (char**) &opt_date_time_formats[DRIZZLE_TIMESTAMP_TIME],
3916
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
2037
   UINT32_C(1024*512), SIZE_MAX, 0, 1024, 0},
3917
2038
  {"tmp_table_size", OPT_TMP_TABLE_SIZE,
3918
 
   N_("If an internal in-memory temporary table exceeds this size, MySQL will"
 
2039
   N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
3919
2040
      " automatically convert it to an on-disk MyISAM table."),
3920
2041
   (char**) &global_system_variables.tmp_table_size,
3921
2042
   (char**) &max_system_variables.tmp_table_size, 0, GET_ULL,
3923
2044
  {"transaction_alloc_block_size", OPT_TRANS_ALLOC_BLOCK_SIZE,
3924
2045
   N_("Allocation block size for transactions to be stored in binary log"),
3925
2046
   (char**) &global_system_variables.trans_alloc_block_size,
3926
 
   (char**) &max_system_variables.trans_alloc_block_size, 0, GET_ULONG,
 
2047
   (char**) &max_system_variables.trans_alloc_block_size, 0, GET_UINT,
3927
2048
   REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
3928
2049
  {"transaction_prealloc_size", OPT_TRANS_PREALLOC_SIZE,
3929
2050
   N_("Persistent buffer for transactions to be stored in binary log"),
3930
2051
   (char**) &global_system_variables.trans_prealloc_size,
3931
 
   (char**) &max_system_variables.trans_prealloc_size, 0, GET_ULONG,
 
2052
   (char**) &max_system_variables.trans_prealloc_size, 0, GET_UINT,
3932
2053
   REQUIRED_ARG, TRANS_ALLOC_PREALLOC_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
3933
 
  {"wait_timeout", OPT_WAIT_TIMEOUT,
3934
 
   N_("The number of seconds the server waits for activity on a connection "
3935
 
      "before closing it."),
3936
 
   (char**) &global_system_variables.net_wait_timeout,
3937
 
   (char**) &max_system_variables.net_wait_timeout, 0, GET_ULONG,
3938
 
   REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT,
3939
 
   0, 1, 0},
3940
2054
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
3941
2055
};
3942
2056
 
3943
 
static int show_net_compression(THD *thd __attribute__((unused)),
3944
 
                                SHOW_VAR *var,
3945
 
                                char *buff __attribute__((unused)))
3946
 
{
3947
 
  var->type= SHOW_MY_BOOL;
3948
 
  var->value= (char *)&thd->net.compress;
3949
 
  return 0;
3950
 
}
3951
 
 
3952
 
static st_show_var_func_container
3953
 
show_net_compression_cont= { &show_net_compression };
3954
 
 
3955
 
static int show_starttime(THD *thd, SHOW_VAR *var, char *buff)
 
2057
static int show_starttime(SHOW_VAR *var, char *buff)
3956
2058
{
3957
2059
  var->type= SHOW_LONG;
3958
2060
  var->value= buff;
3959
 
  *((long *)buff)= (long) (thd->query_start() - server_start_time);
 
2061
  *((long *)buff)= (long) (time(NULL) - server_start_time);
3960
2062
  return 0;
3961
2063
}
3962
2064
 
3963
2065
static st_show_var_func_container
3964
2066
show_starttime_cont= { &show_starttime };
3965
2067
 
3966
 
static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff)
 
2068
static int show_flushstatustime(SHOW_VAR *var, char *buff)
3967
2069
{
3968
2070
  var->type= SHOW_LONG;
3969
2071
  var->value= buff;
3970
 
  *((long *)buff)= (long) (thd->query_start() - flush_status_time);
 
2072
  *((long *)buff)= (long) (time(NULL) - flush_status_time);
3971
2073
  return 0;
3972
2074
}
3973
2075
 
3974
2076
static st_show_var_func_container
3975
2077
show_flushstatustime_cont= { &show_flushstatustime };
3976
2078
 
3977
 
static int show_slave_running(THD *thd __attribute__((unused)),
3978
 
                              SHOW_VAR *var, char *buff)
3979
 
{
3980
 
  var->type= SHOW_MY_BOOL;
3981
 
  pthread_mutex_lock(&LOCK_active_mi);
3982
 
  var->value= buff;
3983
 
  *((bool *)buff)= (bool) (active_mi && active_mi->slave_running &&
3984
 
                                 active_mi->rli.slave_running);
3985
 
  pthread_mutex_unlock(&LOCK_active_mi);
3986
 
  return 0;
3987
 
}
3988
 
 
3989
 
static st_show_var_func_container
3990
 
show_slave_running_cont= { &show_slave_running };
3991
 
 
3992
 
static int show_slave_retried_trans(THD *thd __attribute__((unused)),
3993
 
                                    SHOW_VAR *var, char *buff)
3994
 
{
3995
 
  /*
3996
 
    TODO: with multimaster, have one such counter per line in
3997
 
    SHOW SLAVE STATUS, and have the sum over all lines here.
3998
 
  */
3999
 
  pthread_mutex_lock(&LOCK_active_mi);
4000
 
  if (active_mi)
4001
 
  {
4002
 
    var->type= SHOW_LONG;
4003
 
    var->value= buff;
4004
 
    pthread_mutex_lock(&active_mi->rli.data_lock);
4005
 
    *((long *)buff)= (long)active_mi->rli.retried_trans;
4006
 
    pthread_mutex_unlock(&active_mi->rli.data_lock);
4007
 
  }
4008
 
  else
4009
 
    var->type= SHOW_UNDEF;
4010
 
  pthread_mutex_unlock(&LOCK_active_mi);
4011
 
  return 0;
4012
 
}
4013
 
 
4014
 
static st_show_var_func_container
4015
 
show_slave_retried_trans_cont= { &show_slave_retried_trans };
4016
 
 
4017
 
static int show_slave_received_heartbeats(THD *thd __attribute__((unused)),
4018
 
                                          SHOW_VAR *var, char *buff)
4019
 
{
4020
 
  pthread_mutex_lock(&LOCK_active_mi);
4021
 
  if (active_mi)
4022
 
  {
4023
 
    var->type= SHOW_LONGLONG;
4024
 
    var->value= buff;
4025
 
    pthread_mutex_lock(&active_mi->rli.data_lock);
4026
 
    *((int64_t *)buff)= active_mi->received_heartbeats;
4027
 
    pthread_mutex_unlock(&active_mi->rli.data_lock);
4028
 
  }
4029
 
  else
4030
 
    var->type= SHOW_UNDEF;
4031
 
  pthread_mutex_unlock(&LOCK_active_mi);
4032
 
  return 0;
4033
 
}
4034
 
 
4035
 
static st_show_var_func_container
4036
 
show_slave_received_heartbeats_cont= { &show_slave_received_heartbeats };
4037
 
 
4038
 
static int show_heartbeat_period(THD *thd __attribute__((unused)),
4039
 
                                 SHOW_VAR *var, char *buff)
4040
 
{
4041
 
  pthread_mutex_lock(&LOCK_active_mi);
4042
 
  if (active_mi)
4043
 
  {
4044
 
    var->type= SHOW_CHAR;
4045
 
    var->value= buff;
4046
 
    sprintf(buff, "%.3f",active_mi->heartbeat_period);
4047
 
  }
4048
 
  else
4049
 
    var->type= SHOW_UNDEF;
4050
 
  pthread_mutex_unlock(&LOCK_active_mi);
4051
 
  return 0;
4052
 
}
4053
 
 
4054
 
static st_show_var_func_container
4055
 
show_heartbeat_period_cont= { &show_heartbeat_period};
4056
 
 
4057
 
static int show_open_tables(THD *thd __attribute__((unused)),
4058
 
                            SHOW_VAR *var, char *buff)
 
2079
static int show_open_tables(SHOW_VAR *var, char *buff)
4059
2080
{
4060
2081
  var->type= SHOW_LONG;
4061
2082
  var->value= buff;
4063
2084
  return 0;
4064
2085
}
4065
2086
 
4066
 
static int show_table_definitions(THD *thd __attribute__((unused)),
4067
 
                                  SHOW_VAR *var, char *buff)
 
2087
static int show_table_definitions(SHOW_VAR *var, char *buff)
4068
2088
{
4069
2089
  var->type= SHOW_LONG;
4070
2090
  var->value= buff;
4082
2102
*/
4083
2103
 
4084
2104
SHOW_VAR status_vars[]= {
4085
 
  {"Aborted_clients",          (char*) &aborted_threads,        SHOW_LONG},
4086
 
  {"Aborted_connects",         (char*) &aborted_connects,       SHOW_LONG},
4087
 
  {"Binlog_cache_disk_use",    (char*) &binlog_cache_disk_use,  SHOW_LONG},
4088
 
  {"Binlog_cache_use",         (char*) &binlog_cache_use,       SHOW_LONG},
 
2105
  {"Aborted_clients",          (char*) &aborted_threads,        SHOW_LONGLONG},
 
2106
  {"Aborted_connects",         (char*) &aborted_connects,       SHOW_LONGLONG},
4089
2107
  {"Bytes_received",           (char*) offsetof(STATUS_VAR, bytes_received), SHOW_LONGLONG_STATUS},
4090
2108
  {"Bytes_sent",               (char*) offsetof(STATUS_VAR, bytes_sent), SHOW_LONGLONG_STATUS},
4091
2109
  {"Com",                      (char*) com_status_vars, SHOW_ARRAY},
4092
 
  {"Compression",              (char*) &show_net_compression_cont, SHOW_FUNC},
4093
 
  {"Connections",              (char*) &thread_id,              SHOW_LONG_NOFLUSH},
 
2110
  {"Connections",              (char*) &global_thread_id, SHOW_INT_NOFLUSH},
4094
2111
  {"Created_tmp_disk_tables",  (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
4095
 
  {"Created_tmp_files",        (char*) &my_tmp_file_created,    SHOW_LONG},
 
2112
  {"Created_tmp_files",        (char*) &my_tmp_file_created,SHOW_INT},
4096
2113
  {"Created_tmp_tables",       (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
4097
 
  {"Flush_commands",           (char*) &refresh_version,        SHOW_LONG_NOFLUSH},
 
2114
  {"Flush_commands",           (char*) &refresh_version,    SHOW_INT_NOFLUSH},
4098
2115
  {"Handler_commit",           (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
4099
2116
  {"Handler_delete",           (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
4100
 
  {"Handler_discover",         (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS},
4101
2117
  {"Handler_prepare",          (char*) offsetof(STATUS_VAR, ha_prepare_count),  SHOW_LONG_STATUS},
4102
2118
  {"Handler_read_first",       (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS},
4103
2119
  {"Handler_read_key",         (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS},
4118
2134
  {"Key_write_requests",       (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
4119
2135
  {"Key_writes",               (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
4120
2136
  {"Last_query_cost",          (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
4121
 
  {"Max_used_connections",     (char*) &max_used_connections,  SHOW_LONG},
4122
 
  {"Open_files",               (char*) &my_file_opened,         SHOW_LONG_NOFLUSH},
4123
 
  {"Open_streams",             (char*) &my_stream_opened,       SHOW_LONG_NOFLUSH},
 
2137
  {"Max_used_connections",     (char*) &max_used_connections,  SHOW_INT},
 
2138
  {"Open_files",               (char*) &my_file_opened,    SHOW_INT_NOFLUSH},
 
2139
  {"Open_streams",             (char*) &my_stream_opened,  SHOW_INT_NOFLUSH},
4124
2140
  {"Open_table_definitions",   (char*) &show_table_definitions_cont, SHOW_FUNC},
4125
2141
  {"Open_tables",              (char*) &show_open_tables_cont,       SHOW_FUNC},
4126
 
  {"Opened_files",             (char*) &my_file_total_opened, SHOW_LONG_NOFLUSH},
 
2142
  {"Opened_files",             (char*) &my_file_total_opened, SHOW_INT_NOFLUSH},
4127
2143
  {"Opened_tables",            (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
4128
2144
  {"Opened_table_definitions", (char*) offsetof(STATUS_VAR, opened_shares), SHOW_LONG_STATUS},
4129
2145
  {"Questions",                (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
4132
2148
  {"Select_range",             (char*) offsetof(STATUS_VAR, select_range_count), SHOW_LONG_STATUS},
4133
2149
  {"Select_range_check",       (char*) offsetof(STATUS_VAR, select_range_check_count), SHOW_LONG_STATUS},
4134
2150
  {"Select_scan",              (char*) offsetof(STATUS_VAR, select_scan_count), SHOW_LONG_STATUS},
4135
 
  {"Slave_open_temp_tables",   (char*) &slave_open_temp_tables, SHOW_LONG},
4136
 
  {"Slave_retried_transactions",(char*) &show_slave_retried_trans_cont, SHOW_FUNC},
4137
 
  {"Slave_heartbeat_period",   (char*) &show_heartbeat_period_cont, SHOW_FUNC},
4138
 
  {"Slave_received_heartbeats",(char*) &show_slave_received_heartbeats_cont, SHOW_FUNC},
4139
 
  {"Slave_running",            (char*) &show_slave_running_cont,     SHOW_FUNC},
4140
 
  {"Slow_launch_threads",      (char*) &slow_launch_threads,    SHOW_LONG},
4141
2151
  {"Slow_queries",             (char*) offsetof(STATUS_VAR, long_query_count), SHOW_LONG_STATUS},
4142
2152
  {"Sort_merge_passes",        (char*) offsetof(STATUS_VAR, filesort_merge_passes), SHOW_LONG_STATUS},
4143
2153
  {"Sort_range",               (char*) offsetof(STATUS_VAR, filesort_range_count), SHOW_LONG_STATUS},
4144
2154
  {"Sort_rows",                (char*) offsetof(STATUS_VAR, filesort_rows), SHOW_LONG_STATUS},
4145
2155
  {"Sort_scan",                (char*) offsetof(STATUS_VAR, filesort_scan_count), SHOW_LONG_STATUS},
4146
 
  {"Table_locks_immediate",    (char*) &locks_immediate,        SHOW_LONG},
4147
 
  {"Table_locks_waited",       (char*) &locks_waited,           SHOW_LONG},
4148
 
#ifdef HAVE_MMAP
4149
 
  {"Tc_log_max_pages_used",    (char*) &tc_log_max_pages_used,  SHOW_LONG},
4150
 
  {"Tc_log_page_size",         (char*) &tc_log_page_size,       SHOW_LONG},
4151
 
  {"Tc_log_page_waits",        (char*) &tc_log_page_waits,      SHOW_LONG},
4152
 
#endif
4153
 
  {"Threads_cached",           (char*) &cached_thread_count,    SHOW_LONG_NOFLUSH},
 
2156
  {"Table_locks_immediate",    (char*) &locks_immediate,        SHOW_INT},
 
2157
  {"Table_locks_waited",       (char*) &locks_waited,           SHOW_INT},
4154
2158
  {"Threads_connected",        (char*) &connection_count,       SHOW_INT},
4155
 
  {"Threads_created",          (char*) &thread_created,         SHOW_LONG_NOFLUSH},
4156
 
  {"Threads_running",          (char*) &thread_running,         SHOW_INT},
4157
2159
  {"Uptime",                   (char*) &show_starttime_cont,         SHOW_FUNC},
4158
2160
  {"Uptime_since_flush_status",(char*) &show_flushstatustime_cont,   SHOW_FUNC},
4159
 
  {NULL, NULL, SHOW_LONG}
 
2161
  {NULL, NULL, SHOW_LONGLONG}
4160
2162
};
4161
2163
 
4162
2164
static void print_version(void)
4163
2165
{
4164
 
  set_server_version();
4165
2166
  /*
4166
2167
    Note: the instance manager keys off the string 'Ver' so it can find the
4167
 
    version from the output of 'mysqld --version', so don't change it!
 
2168
    version from the output of 'drizzled --version', so don't change it!
4168
2169
  */
4169
 
  printf("%s  Ver %s for %s on %s (%s)\n",my_progname,
4170
 
         server_version,SYSTEM_TYPE,MACHINE_TYPE, DRIZZLE_COMPILATION_COMMENT);
 
2170
  printf("%s  Ver %s for %s-%s on %s (%s)\n",my_progname,
 
2171
         VERSION, HOST_VENDOR, HOST_OS, HOST_CPU, COMPILATION_COMMENT);
4171
2172
}
4172
2173
 
4173
2174
static void usage(void)
4174
2175
{
4175
 
  if (!(default_charset_info= get_charset_by_csname(default_character_set_name,
4176
 
                                                   MY_CS_PRIMARY,
4177
 
                                                   MYF(MY_WME))))
 
2176
  if (!(default_charset_info= get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
4178
2177
    exit(1);
4179
2178
  if (!default_collation_name)
4180
2179
    default_collation_name= (char*) default_charset_info->name;
4181
2180
  print_version();
4182
 
  puts(_("Copyright (C) 2000 MySQL AB, by Monty and others\n"
 
2181
  puts(_("Copyright (C) 2008 Sun Microsystems\n"
4183
2182
         "This software comes with ABSOLUTELY NO WARRANTY. "
4184
2183
         "This is free software,\n"
4185
2184
         "and you are welcome to modify and redistribute it under the GPL "
4188
2187
 
4189
2188
  printf(_("Usage: %s [OPTIONS]\n"), my_progname);
4190
2189
  {
4191
 
#ifdef FOO
4192
 
  print_defaults(DRIZZLE_CONFIG_NAME,load_default_groups);
4193
 
  puts("");
4194
 
  set_ports();
4195
 
#endif
4196
 
 
4197
 
  /* Print out all the options including plugin supplied options */
4198
 
  my_print_help_inc_plugins(my_long_options, sizeof(my_long_options)/sizeof(my_option));
4199
 
 
4200
 
  puts(_("\nTo see what values a running Drizzle server is using, type\n"
4201
 
         "'drizzleadmin variables' instead of 'drizzled --help'."));
 
2190
     print_defaults(DRIZZLE_CONFIG_NAME,load_default_groups);
 
2191
     puts("");
 
2192
 
 
2193
     /* Print out all the options including plugin supplied options */
 
2194
     my_print_help_inc_plugins(my_long_options);
4202
2195
  }
4203
2196
}
4204
2197
 
4205
2198
 
4206
2199
/**
4207
 
  Initialize all MySQL global variables to default values.
 
2200
  Initialize all Drizzle global variables to default values.
4208
2201
 
4209
2202
  We don't need to set numeric variables refered to in my_long_options
4210
2203
  as these are initialized by my_getopt.
4219
2212
    as these are initialized by my_getopt.
4220
2213
*/
4221
2214
 
4222
 
static void mysql_init_variables(void)
 
2215
static void drizzle_init_variables(void)
4223
2216
{
4224
2217
  /* Things reset to zero */
4225
 
  opt_skip_slave_start= opt_reckless_slave = 0;
4226
 
  mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0;
4227
 
  log_output_options= find_bit_type(log_output_str, &log_output_typelib);
4228
 
  opt_bin_log= 0;
4229
 
  opt_skip_show_db=0;
4230
 
  opt_logname= opt_binlog_index_name= 0;
 
2218
  drizzle_home[0]= pidfile_name[0]= 0;
4231
2219
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
4232
 
  opt_secure_auth= 0;
4233
2220
  opt_secure_file_priv= 0;
4234
 
  segfaulted= kill_in_progress= 0;
 
2221
  segfaulted= 0;
4235
2222
  cleanup_done= 0;
4236
2223
  defaults_argc= 0;
4237
2224
  defaults_argv= 0;
4238
 
  server_id_supplied= 0;
4239
 
  test_flags= select_errors= dropping_tables= ha_open_options=0;
4240
 
  thread_count= thread_running= kill_cached_threads= wake_thread=0;
4241
 
  slave_open_temp_tables= 0;
4242
 
  cached_thread_count= 0;
4243
 
  opt_endinfo= using_udf_functions= 0;
4244
 
  opt_using_transactions= using_update_log= 0;
4245
 
  abort_loop= select_thread_in_use= signal_thread_in_use= 0;
 
2225
  dropping_tables= ha_open_options=0;
 
2226
  test_flags.reset();
 
2227
  wake_thread=0;
 
2228
  opt_endinfo= false;
 
2229
  abort_loop= select_thread_in_use= false;
4246
2230
  ready_to_exit= shutdown_in_progress= 0;
4247
2231
  aborted_threads= aborted_connects= 0;
4248
 
  specialflag= 0;
4249
 
  binlog_cache_use=  binlog_cache_disk_use= 0;
4250
 
  max_used_connections= slow_launch_threads = 0;
4251
 
  mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
4252
 
  opt_mysql_tmpdir= my_bind_addr_str= NULL;
4253
 
  memset(&mysql_tmpdir_list, 0, sizeof(mysql_tmpdir_list));
 
2232
  max_used_connections= 0;
 
2233
  drizzled_user= drizzled_chroot= 0;
 
2234
  drizzled_bind_host= NULL;
4254
2235
  memset(&global_status_var, 0, sizeof(global_status_var));
4255
 
  key_map_full.set_all();
 
2236
  key_map_full.set();
4256
2237
 
4257
2238
  /* Character sets */
4258
2239
  system_charset_info= &my_charset_utf8_general_ci;
4259
2240
  files_charset_info= &my_charset_utf8_general_ci;
4260
 
  national_charset_info= &my_charset_utf8_general_ci;
4261
2241
  table_alias_charset= &my_charset_bin;
4262
2242
  character_set_filesystem= &my_charset_bin;
4263
2243
 
4264
 
  opt_date_time_formats[0]= opt_date_time_formats[1]= opt_date_time_formats[2]= 0;
4265
 
 
4266
2244
  /* Things with default values that are not zero */
4267
 
  delay_key_write_options= (uint) DELAY_KEY_WRITE_ON;
4268
 
  slave_exec_mode_options= 0;
4269
 
  slave_exec_mode_options= (uint)
4270
 
    find_bit_type_or_exit(slave_exec_mode_str, &slave_exec_mode_typelib, NULL);
4271
 
  mysql_home_ptr= mysql_home;
 
2245
  drizzle_home_ptr= drizzle_home;
4272
2246
  pidfile_name_ptr= pidfile_name;
4273
 
  log_error_file_ptr= log_error_file;
4274
2247
  language_ptr= language;
4275
 
  mysql_data_home= mysql_real_data_home;
4276
 
  thd_startup_options= (OPTION_AUTO_IS_NULL | OPTION_BIN_LOG |
4277
 
                        OPTION_QUOTE_SHOW_CREATE | OPTION_SQL_NOTES);
4278
 
  protocol_version= PROTOCOL_VERSION;
4279
 
  what_to_log= ~ (1L << (uint) COM_TIME);
 
2248
  drizzle_data_home= drizzle_real_data_home;
 
2249
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
4280
2250
  refresh_version= 1L;  /* Increments on each reload */
4281
 
  global_query_id= thread_id= 1L;
4282
 
  my_stpcpy(server_version, DRIZZLE_SERVER_VERSION);
4283
 
  myisam_recover_options_str= "OFF";
4284
 
  myisam_stats_method_str= "nulls_unequal";
4285
 
  threads.empty();
4286
 
  thread_cache.empty();
4287
 
  key_caches.empty();
4288
 
  if (!(dflt_key_cache= get_or_create_key_cache(default_key_cache_base.str,
4289
 
                                                default_key_cache_base.length)))
4290
 
    exit(1);
4291
 
  /* set key_cache_hash.default_value = dflt_key_cache */
4292
 
  multi_keycache_init();
 
2251
  global_thread_id= 1UL;
 
2252
  session_list.clear();
4293
2253
 
4294
2254
  /* Set directory paths */
4295
 
  strmake(language, LANGUAGE, sizeof(language)-1);
4296
 
  strmake(mysql_real_data_home, get_relative_path(DATADIR),
4297
 
          sizeof(mysql_real_data_home)-1);
4298
 
  mysql_data_home_buff[0]=FN_CURLIB;    // all paths are relative from here
4299
 
  mysql_data_home_buff[1]=0;
4300
 
  mysql_data_home_len= 2;
4301
 
 
4302
 
  /* Replication parameters */
4303
 
  master_info_file= (char*) "master.info",
4304
 
    relay_log_info_file= (char*) "relay-log.info";
4305
 
  report_user= report_password = report_host= 0;        /* TO BE DELETED */
4306
 
  opt_relay_logname= opt_relaylog_index_name= 0;
 
2255
  strncpy(language, LANGUAGE, sizeof(language)-1);
 
2256
  strncpy(drizzle_real_data_home, get_relative_path(LOCALSTATEDIR),
 
2257
          sizeof(drizzle_real_data_home)-1);
 
2258
  drizzle_data_home_buff[0]=FN_CURLIB;  // all paths are relative from here
 
2259
  drizzle_data_home_buff[1]=0;
 
2260
  drizzle_data_home_len= 2;
4307
2261
 
4308
2262
  /* Variables in libraries */
4309
 
  charsets_dir= 0;
4310
 
  default_character_set_name= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
4311
 
  default_collation_name= compiled_default_collation_name;
4312
 
  sys_charset_system.set((char*) system_charset_info->csname);
4313
 
  character_set_filesystem_name= (char*) "binary";
 
2263
  default_character_set_name= "utf8";
 
2264
  default_collation_name= (char *)compiled_default_collation_name;
 
2265
  character_set_filesystem_name= "binary";
4314
2266
  lc_time_names_name= (char*) "en_US";
4315
2267
  /* Set default values for some option variables */
4316
2268
  default_storage_engine_str= (char*) "innodb";
4317
 
  global_system_variables.table_plugin= NULL;
 
2269
  global_system_variables.storage_engine= NULL;
4318
2270
  global_system_variables.tx_isolation= ISO_REPEATABLE_READ;
4319
2271
  global_system_variables.select_limit= (uint64_t) HA_POS_ERROR;
4320
2272
  max_system_variables.select_limit=    (uint64_t) HA_POS_ERROR;
4321
2273
  global_system_variables.max_join_size= (uint64_t) HA_POS_ERROR;
4322
2274
  max_system_variables.max_join_size=   (uint64_t) HA_POS_ERROR;
4323
 
  global_system_variables.old_alter_table= 0;
4324
 
  global_system_variables.binlog_format= BINLOG_FORMAT_UNSPEC;
4325
 
  /*
4326
 
    Default behavior for 4.1 and 5.0 is to treat NULL values as unequal
4327
 
    when collecting index statistics for MyISAM tables.
4328
 
  */
4329
 
  global_system_variables.myisam_stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
4330
2275
 
4331
2276
  /* Variables that depends on compile options */
4332
 
  opt_error_log= 0;
4333
2277
#ifdef HAVE_BROKEN_REALPATH
4334
2278
  have_symlink=SHOW_OPTION_NO;
4335
2279
#else
4336
2280
  have_symlink=SHOW_OPTION_YES;
4337
2281
#endif
4338
 
#ifdef HAVE_COMPRESS
4339
 
  have_compress= SHOW_OPTION_YES;
4340
 
#else
4341
 
  have_compress= SHOW_OPTION_NO;
4342
 
#endif
4343
2282
 
4344
2283
  const char *tmpenv;
4345
2284
  if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
4346
 
    tmpenv = DEFAULT_DRIZZLE_HOME;
4347
 
  (void) strmake(mysql_home, tmpenv, sizeof(mysql_home)-1);
 
2285
    tmpenv = PREFIX;
 
2286
  (void) strncpy(drizzle_home, tmpenv, sizeof(drizzle_home)-1);
 
2287
  
 
2288
  connection_count= 0;
4348
2289
}
4349
2290
 
4350
2291
 
4351
2292
bool
4352
 
mysqld_get_one_option(int optid,
4353
 
                      const struct my_option *opt __attribute__((unused)),
4354
 
                      char *argument)
 
2293
drizzled_get_one_option(int optid, const struct my_option *opt,
 
2294
                        char *argument)
4355
2295
{
4356
2296
  switch(optid) {
4357
2297
  case '#':
4361
2301
    global_system_variables.tx_isolation= ISO_SERIALIZABLE;
4362
2302
    break;
4363
2303
  case 'b':
4364
 
    strmake(mysql_home,argument,sizeof(mysql_home)-1);
 
2304
    strncpy(drizzle_home,argument,sizeof(drizzle_home)-1);
4365
2305
    break;
4366
2306
  case 'C':
4367
2307
    if (default_collation_name == compiled_default_collation_name)
4368
2308
      default_collation_name= 0;
4369
2309
    break;
4370
2310
  case 'h':
4371
 
    strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1);
 
2311
    strncpy(drizzle_real_data_home,argument, sizeof(drizzle_real_data_home)-1);
4372
2312
    /* Correct pointer set by my_getopt (for embedded library) */
4373
 
    mysql_data_home= mysql_real_data_home;
4374
 
    mysql_data_home_len= strlen(mysql_data_home);
 
2313
    drizzle_data_home= drizzle_real_data_home;
 
2314
    drizzle_data_home_len= strlen(drizzle_data_home);
4375
2315
    break;
4376
2316
  case 'u':
4377
 
    if (!mysqld_user || !strcmp(mysqld_user, argument))
4378
 
      mysqld_user= argument;
 
2317
    if (!drizzled_user || !strcmp(drizzled_user, argument))
 
2318
      drizzled_user= argument;
4379
2319
    else
4380
 
      sql_print_warning(_("Ignoring user change to '%s' because the user was "
 
2320
      errmsg_printf(ERRMSG_LVL_WARN, _("Ignoring user change to '%s' because the user was "
4381
2321
                          "set to '%s' earlier on the command line\n"),
4382
 
                        argument, mysqld_user);
 
2322
                        argument, drizzled_user);
4383
2323
    break;
4384
2324
  case 'L':
4385
 
    strmake(language, argument, sizeof(language)-1);
4386
 
    break;
4387
 
  case OPT_SLAVE_SKIP_ERRORS:
4388
 
    init_slave_skip_errors(argument);
4389
 
    break;
4390
 
  case OPT_SLAVE_EXEC_MODE:
4391
 
    slave_exec_mode_options= (uint)
4392
 
      find_bit_type_or_exit(argument, &slave_exec_mode_typelib, "");
 
2325
    strncpy(language, argument, sizeof(language)-1);
4393
2326
    break;
4394
2327
  case 'V':
4395
2328
    print_version();
4403
2336
      global_system_variables.log_warnings= atoi(argument);
4404
2337
    break;
4405
2338
  case 'T':
4406
 
    test_flags= argument ? (uint) atoi(argument) : 0;
 
2339
    if (argument)
 
2340
    {
 
2341
      test_flags.set((uint32_t) atoi(argument));
 
2342
    }
4407
2343
    opt_endinfo=1;
4408
2344
    break;
4409
 
  case (int) OPT_BIN_LOG:
4410
 
    opt_bin_log= test(argument != disabled_my_option);
4411
 
    break;
4412
 
  case (int) OPT_ERROR_LOG_FILE:
4413
 
    opt_error_log= 1;
4414
 
    break;
4415
 
  case (int)OPT_REPLICATE_IGNORE_DB:
4416
 
    {
4417
 
      rpl_filter->add_ignore_db(argument);
4418
 
      break;
4419
 
    }
4420
 
  case (int)OPT_REPLICATE_DO_DB:
4421
 
    {
4422
 
      rpl_filter->add_do_db(argument);
4423
 
      break;
4424
 
    }
4425
 
  case (int)OPT_REPLICATE_REWRITE_DB:
4426
 
    {
4427
 
      char* key = argument,*p, *val;
4428
 
 
4429
 
      if (!(p= strstr(argument, "->")))
4430
 
      {
4431
 
        fprintf(stderr,
4432
 
                _("Bad syntax in replicate-rewrite-db - missing '->'!\n"));
4433
 
        exit(1);
4434
 
      }
4435
 
      val= p--;
4436
 
      while (my_isspace(mysqld_charset, *p) && p > argument)
4437
 
        *p-- = 0;
4438
 
      if (p == argument)
4439
 
      {
4440
 
        fprintf(stderr,
4441
 
                _("Bad syntax in replicate-rewrite-db - empty FROM db!\n"));
4442
 
        exit(1);
4443
 
      }
4444
 
      *val= 0;
4445
 
      val+= 2;
4446
 
      while (*val && my_isspace(mysqld_charset, *val))
4447
 
        *val++;
4448
 
      if (!*val)
4449
 
      {
4450
 
        fprintf(stderr,
4451
 
                _("Bad syntax in replicate-rewrite-db - empty TO db!\n"));
4452
 
        exit(1);
4453
 
      }
4454
 
 
4455
 
      rpl_filter->add_db_rewrite(key, val);
4456
 
      break;
4457
 
    }
4458
 
 
4459
 
  case (int)OPT_BINLOG_IGNORE_DB:
4460
 
    {
4461
 
      binlog_filter->add_ignore_db(argument);
4462
 
      break;
4463
 
    }
4464
 
  case OPT_BINLOG_FORMAT:
4465
 
    {
4466
 
      int id;
4467
 
      id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
4468
 
      global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
4469
 
      break;
4470
 
    }
4471
 
  case (int)OPT_BINLOG_DO_DB:
4472
 
    {
4473
 
      binlog_filter->add_do_db(argument);
4474
 
      break;
4475
 
    }
4476
 
  case (int)OPT_REPLICATE_DO_TABLE:
4477
 
    {
4478
 
      if (rpl_filter->add_do_table(argument))
4479
 
      {
4480
 
        fprintf(stderr, _("Could not add do table rule '%s'!\n"), argument);
4481
 
        exit(1);
4482
 
      }
4483
 
      break;
4484
 
    }
4485
 
  case (int)OPT_REPLICATE_WILD_DO_TABLE:
4486
 
    {
4487
 
      if (rpl_filter->add_wild_do_table(argument))
4488
 
      {
4489
 
        fprintf(stderr, _("Could not add do table rule '%s'!\n"), argument);
4490
 
        exit(1);
4491
 
      }
4492
 
      break;
4493
 
    }
4494
 
  case (int)OPT_REPLICATE_WILD_IGNORE_TABLE:
4495
 
    {
4496
 
      if (rpl_filter->add_wild_ignore_table(argument))
4497
 
      {
4498
 
        fprintf(stderr, _("Could not add ignore table rule '%s'!\n"), argument);
4499
 
        exit(1);
4500
 
      }
4501
 
      break;
4502
 
    }
4503
 
  case (int)OPT_REPLICATE_IGNORE_TABLE:
4504
 
    {
4505
 
      if (rpl_filter->add_ignore_table(argument))
4506
 
      {
4507
 
        fprintf(stderr, _("Could not add ignore table rule '%s'!\n"), argument);
4508
 
        exit(1);
4509
 
      }
4510
 
      break;
4511
 
    }
4512
2345
  case (int) OPT_WANT_CORE:
4513
 
    test_flags |= TEST_CORE_ON_SIGNAL;
 
2346
    test_flags.set(TEST_CORE_ON_SIGNAL);
4514
2347
    break;
4515
2348
  case (int) OPT_SKIP_STACK_TRACE:
4516
 
    test_flags|=TEST_NO_STACKTRACE;
 
2349
    test_flags.set(TEST_NO_STACKTRACE);
4517
2350
    break;
4518
2351
  case (int) OPT_SKIP_SYMLINKS:
4519
2352
    my_use_symdir=0;
4528
2361
 
4529
2362
      if (getaddrinfo(argument, NULL, &hints, &res_lst) != 0)
4530
2363
      {
4531
 
        sql_print_error(_("Can't start server: cannot resolve hostname!"));
 
2364
          errmsg_printf(ERRMSG_LVL_ERROR, _("Can't start server: cannot resolve hostname!"));
4532
2365
        exit(1);
4533
2366
      }
4534
2367
 
4535
2368
      if (res_lst->ai_next)
4536
2369
      {
4537
 
        sql_print_error(_("Can't start server: bind-address refers to "
 
2370
          errmsg_printf(ERRMSG_LVL_ERROR, _("Can't start server: bind-address refers to "
4538
2371
                          "multiple interfaces!"));
4539
2372
        exit(1);
4540
2373
      }
4542
2375
    }
4543
2376
    break;
4544
2377
  case (int) OPT_PID_FILE:
4545
 
    strmake(pidfile_name, argument, sizeof(pidfile_name)-1);
4546
 
    break;
4547
 
  case OPT_CONSOLE:
4548
 
    if (opt_console)
4549
 
      opt_error_log= 0;                 // Force logs to stdout
4550
 
    break;
4551
 
  case OPT_LOW_PRIORITY_UPDATES:
4552
 
    thr_upgraded_concurrent_insert_lock= TL_WRITE_LOW_PRIORITY;
4553
 
    global_system_variables.low_priority_updates=1;
 
2378
    strncpy(pidfile_name, argument, sizeof(pidfile_name)-1);
4554
2379
    break;
4555
2380
  case OPT_SERVER_ID:
4556
 
    server_id_supplied = 1;
4557
 
    break;
4558
 
  case OPT_DELAY_KEY_WRITE_ALL:
4559
 
    if (argument != disabled_my_option)
4560
 
      argument= (char*) "ALL";
4561
 
    /* Fall through */
4562
 
  case OPT_DELAY_KEY_WRITE:
4563
 
    if (argument == disabled_my_option)
4564
 
      delay_key_write_options= (uint) DELAY_KEY_WRITE_NONE;
4565
 
    else if (! argument)
4566
 
      delay_key_write_options= (uint) DELAY_KEY_WRITE_ON;
4567
 
    else
4568
 
    {
4569
 
      int type;
4570
 
      type= find_type_or_exit(argument, &delay_key_write_typelib, opt->name);
4571
 
      delay_key_write_options= (uint) type-1;
4572
 
    }
4573
 
    break;
4574
 
  case OPT_CHARSETS_DIR:
4575
 
    strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir)-1);
4576
 
    charsets_dir = mysql_charsets_dir;
4577
2381
    break;
4578
2382
  case OPT_TX_ISOLATION:
4579
2383
    {
4582
2386
      global_system_variables.tx_isolation= (type-1);
4583
2387
      break;
4584
2388
    }
4585
 
  case OPT_MYISAM_RECOVER:
4586
 
    {
4587
 
      if (!argument)
4588
 
      {
4589
 
        myisam_recover_options=    HA_RECOVER_DEFAULT;
4590
 
        myisam_recover_options_str= myisam_recover_typelib.type_names[0];
4591
 
      }
4592
 
      else if (!argument[0])
4593
 
      {
4594
 
        myisam_recover_options= HA_RECOVER_NONE;
4595
 
        myisam_recover_options_str= "OFF";
4596
 
      }
4597
 
      else
4598
 
      {
4599
 
        myisam_recover_options_str=argument;
4600
 
        myisam_recover_options=
4601
 
          find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
4602
 
      }
4603
 
      ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
4604
 
      break;
4605
 
    }
4606
2389
  case OPT_TC_HEURISTIC_RECOVER:
4607
2390
    tc_heuristic_recover= find_type_or_exit(argument,
4608
2391
                                            &tc_heuristic_recover_typelib,
4609
2392
                                            opt->name);
4610
2393
    break;
4611
 
  case OPT_MYISAM_STATS_METHOD:
4612
 
    {
4613
 
      uint32_t method_conv;
4614
 
      int method;
 
2394
  }
4615
2395
 
4616
 
      myisam_stats_method_str= argument;
4617
 
      method= find_type_or_exit(argument, &myisam_stats_method_typelib,
4618
 
                                opt->name);
4619
 
      switch (method-1) {
4620
 
      case 2:
4621
 
        method_conv= MI_STATS_METHOD_IGNORE_NULLS;
4622
 
        break;
4623
 
      case 1:
4624
 
        method_conv= MI_STATS_METHOD_NULLS_EQUAL;
4625
 
        break;
4626
 
      case 0:
4627
 
      default:
4628
 
        method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
4629
 
        break;
4630
 
      }
4631
 
      global_system_variables.myisam_stats_method= method_conv;
4632
 
      break;
4633
 
    }
4634
 
  }
4635
2396
  return 0;
4636
2397
}
4637
2398
 
4638
2399
 
4639
 
/** Handle arguments for multiple key caches. */
4640
 
 
4641
 
extern "C" char **mysql_getopt_value(const char *keyname, uint32_t key_length,
4642
 
                                      const struct my_option *option);
4643
 
 
4644
 
char**
4645
 
mysql_getopt_value(const char *keyname, uint32_t key_length,
4646
 
                   const struct my_option *option)
4647
 
{
4648
 
  switch (option->id) {
4649
 
  case OPT_KEY_BUFFER_SIZE:
4650
 
  case OPT_KEY_CACHE_BLOCK_SIZE:
4651
 
  case OPT_KEY_CACHE_DIVISION_LIMIT:
4652
 
  case OPT_KEY_CACHE_AGE_THRESHOLD:
4653
 
  {
4654
 
    KEY_CACHE *key_cache;
4655
 
    if (!(key_cache= get_or_create_key_cache(keyname, key_length)))
4656
 
      exit(1);
4657
 
    switch (option->id) {
4658
 
    case OPT_KEY_BUFFER_SIZE:
4659
 
      return (char**) &key_cache->param_buff_size;
4660
 
    case OPT_KEY_CACHE_BLOCK_SIZE:
4661
 
      return (char**) &key_cache->param_block_size;
4662
 
    case OPT_KEY_CACHE_DIVISION_LIMIT:
4663
 
      return (char**) &key_cache->param_division_limit;
4664
 
    case OPT_KEY_CACHE_AGE_THRESHOLD:
4665
 
      return (char**) &key_cache->param_age_threshold;
4666
 
    }
4667
 
  }
4668
 
  }
4669
 
  return (char **)option->value;
4670
 
}
4671
 
 
4672
 
 
4673
2400
extern "C" void option_error_reporter(enum loglevel level, const char *format, ...);
4674
2401
 
4675
2402
void option_error_reporter(enum loglevel level, const char *format, ...)
4680
2407
  /* Don't print warnings for --loose options during bootstrap */
4681
2408
  if (level == ERROR_LEVEL || global_system_variables.log_warnings)
4682
2409
  {
4683
 
    vprint_msg_to_log(level, format, args);
 
2410
    plugin::ErrorMessage::vprintf(current_session, ERROR_LEVEL, format, args);
4684
2411
  }
4685
2412
  va_end(args);
4686
2413
}
4688
2415
 
4689
2416
/**
4690
2417
  @todo
4691
 
  - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code?
 
2418
  - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys/mysys_err.h" and return that code?
4692
2419
*/
4693
2420
static void get_options(int *argc,char **argv)
4694
2421
{
4695
2422
  int ho_error;
4696
2423
 
4697
 
  my_getopt_register_get_addr(mysql_getopt_value);
4698
2424
  my_getopt_error_reporter= option_error_reporter;
4699
2425
 
4700
2426
  /* Skip unknown options so that they may be processed later by plugins */
4701
2427
  my_getopt_skip_unknown= true;
4702
2428
 
4703
2429
  if ((ho_error= handle_options(argc, &argv, my_long_options,
4704
 
                                mysqld_get_one_option)))
 
2430
                                drizzled_get_one_option)))
4705
2431
    exit(ho_error);
4706
2432
  (*argc)++; /* add back one for the progname handle_options removes */
4707
2433
             /* no need to do this for argv as we are discarding it. */
4720
2446
  if (opt_debugging)
4721
2447
  {
4722
2448
    /* Allow break with SIGINT, no core or stack trace */
4723
 
    test_flags|= TEST_SIGINT | TEST_NO_STACKTRACE;
4724
 
    test_flags&= ~TEST_CORE_ON_SIGNAL;
 
2449
    test_flags.set(TEST_SIGINT);
 
2450
    test_flags.set(TEST_NO_STACKTRACE);
 
2451
    test_flags.reset(TEST_CORE_ON_SIGNAL);
4725
2452
  }
4726
 
  /* Set global MyISAM variables from delay_key_write_options */
4727
 
  fix_delay_key_write((THD*) 0, OPT_GLOBAL);
4728
 
  /* Set global slave_exec_mode from its option */
4729
 
  fix_slave_exec_mode(OPT_GLOBAL);
4730
2453
 
4731
 
  if (mysqld_chroot)
4732
 
    set_root(mysqld_chroot);
 
2454
  if (drizzled_chroot)
 
2455
    set_root(drizzled_chroot);
4733
2456
  fix_paths();
4734
2457
 
4735
2458
  /*
4737
2460
    In most cases the global variables will not be used
4738
2461
  */
4739
2462
  my_default_record_cache_size=global_system_variables.read_buff_size;
4740
 
  myisam_max_temp_length=
4741
 
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
4742
 
 
4743
 
  /* Set global variables based on startup options */
4744
 
  myisam_block_size=(uint) 1 << my_bit_log2(opt_myisam_block_size);
4745
 
 
4746
 
  /* long_query_time is in microseconds */
4747
 
  global_system_variables.long_query_time= max_system_variables.long_query_time=
4748
 
    (int64_t) (long_query_time * 1000000.0);
4749
 
 
4750
 
  if (init_global_datetime_format(DRIZZLE_TIMESTAMP_DATE,
4751
 
                                  &global_system_variables.date_format) ||
4752
 
      init_global_datetime_format(DRIZZLE_TIMESTAMP_TIME,
4753
 
                                  &global_system_variables.time_format) ||
4754
 
      init_global_datetime_format(DRIZZLE_TIMESTAMP_DATETIME,
4755
 
                                  &global_system_variables.datetime_format))
4756
 
    exit(1);
4757
 
 
4758
 
  pool_of_threads_scheduler(&thread_scheduler);  /* purecov: tested */
4759
 
}
4760
 
 
4761
 
 
4762
 
/*
4763
 
  Create version name for running mysqld version
4764
 
  We automaticly add suffixes -debug, -embedded and -log to the version
4765
 
  name to make the version more descriptive.
4766
 
  (DRIZZLE_SERVER_SUFFIX is set by the compilation environment)
4767
 
*/
4768
 
 
4769
 
#ifdef DRIZZLE_SERVER_SUFFIX
4770
 
#define DRIZZLE_SERVER_SUFFIX_STR STRINGIFY_ARG(DRIZZLE_SERVER_SUFFIX)
4771
 
#else
4772
 
#define DRIZZLE_SERVER_SUFFIX_STR DRIZZLE_SERVER_SUFFIX_DEF
4773
 
#endif
4774
 
 
4775
 
static void set_server_version(void)
4776
 
{
4777
 
  char *end= strxmov(server_version, DRIZZLE_SERVER_VERSION,
4778
 
                     DRIZZLE_SERVER_SUFFIX_STR, NULL);
4779
 
  if (opt_bin_log)
4780
 
    my_stpcpy(end, "-log");                        // This may slow down system
4781
 
}
4782
 
 
4783
 
 
4784
 
static char *get_relative_path(const char *path)
 
2463
}
 
2464
 
 
2465
 
 
2466
static const char *get_relative_path(const char *path)
4785
2467
{
4786
2468
  if (test_if_hard_path(path) &&
4787
 
      is_prefix(path,DEFAULT_DRIZZLE_HOME) &&
4788
 
      strcmp(DEFAULT_DRIZZLE_HOME,FN_ROOTDIR))
 
2469
      is_prefix(path,PREFIX) &&
 
2470
      strcmp(PREFIX,FN_ROOTDIR))
4789
2471
  {
4790
 
    path+=(uint) strlen(DEFAULT_DRIZZLE_HOME);
 
2472
    if (strlen(PREFIX) < strlen(path))
 
2473
      path+=(size_t) strlen(PREFIX);
4791
2474
    while (*path == FN_LIBCHAR)
4792
2475
      path++;
4793
2476
  }
4794
 
  return (char*) path;
4795
 
}
4796
 
 
4797
 
 
4798
 
/**
4799
 
  Fix filename and replace extension where 'dir' is relative to
4800
 
  mysql_real_data_home.
4801
 
  @return
4802
 
    1 if len(path) > FN_REFLEN
4803
 
*/
4804
 
 
4805
 
bool
4806
 
fn_format_relative_to_data_home(char * to, const char *name,
4807
 
                                const char *dir, const char *extension)
4808
 
{
4809
 
  char tmp_path[FN_REFLEN];
4810
 
  if (!test_if_hard_path(dir))
4811
 
  {
4812
 
    strxnmov(tmp_path,sizeof(tmp_path)-1, mysql_real_data_home,
4813
 
             dir, NULL);
4814
 
    dir=tmp_path;
4815
 
  }
4816
 
  return !fn_format(to, name, dir, extension,
4817
 
                    MY_APPEND_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
2477
  return path;
4818
2478
}
4819
2479
 
4820
2480
 
4821
2481
static void fix_paths(void)
4822
2482
{
4823
 
  char buff[FN_REFLEN],*pos;
4824
 
  convert_dirname(mysql_home,mysql_home,NULL);
4825
 
  /* Resolve symlinks to allow 'mysql_home' to be a relative symlink */
4826
 
  my_realpath(mysql_home,mysql_home,MYF(0));
4827
 
  /* Ensure that mysql_home ends in FN_LIBCHAR */
4828
 
  pos= strchr(mysql_home, '\0');
 
2483
  char buff[FN_REFLEN],*pos,rp_buff[PATH_MAX];
 
2484
  convert_dirname(drizzle_home,drizzle_home,NULL);
 
2485
  /* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */
 
2486
#if defined(HAVE_BROKEN_REALPATH)
 
2487
   my_load_path(drizzle_home, drizzle_home, NULL);
 
2488
#else
 
2489
  if (!realpath(drizzle_home,rp_buff))
 
2490
    my_load_path(rp_buff, drizzle_home, NULL);
 
2491
  rp_buff[FN_REFLEN-1]= '\0';
 
2492
  strcpy(drizzle_home,rp_buff);
 
2493
  /* Ensure that drizzle_home ends in FN_LIBCHAR */
 
2494
  pos= strchr(drizzle_home, '\0');
 
2495
#endif
4829
2496
  if (pos[-1] != FN_LIBCHAR)
4830
2497
  {
4831
2498
    pos[0]= FN_LIBCHAR;
4832
2499
    pos[1]= 0;
4833
2500
  }
4834
 
  convert_dirname(mysql_real_data_home,mysql_real_data_home,NULL);
4835
 
  (void) fn_format(buff, mysql_real_data_home, "", "",
 
2501
  convert_dirname(drizzle_real_data_home,drizzle_real_data_home,NULL);
 
2502
  (void) fn_format(buff, drizzle_real_data_home, "", "",
4836
2503
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
4837
 
  (void) unpack_dirname(mysql_unpacked_real_data_home, buff);
 
2504
  (void) unpack_dirname(drizzle_unpacked_real_data_home, buff);
4838
2505
  convert_dirname(language,language,NULL);
4839
 
  (void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir
4840
 
  (void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
4841
 
  (void) my_load_path(pidfile_name,pidfile_name,mysql_real_data_home);
 
2506
  (void) my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
 
2507
  (void) my_load_path(drizzle_real_data_home, drizzle_real_data_home,drizzle_home);
 
2508
  (void) my_load_path(pidfile_name, pidfile_name,drizzle_real_data_home);
4842
2509
  (void) my_load_path(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr :
4843
 
                                      get_relative_path(PLUGINDIR), mysql_home);
 
2510
                                      get_relative_path(PKGPLUGINDIR),
 
2511
                                      drizzle_home);
4844
2512
  opt_plugin_dir_ptr= opt_plugin_dir;
4845
2513
 
4846
 
  char *sharedir=get_relative_path(SHAREDIR);
 
2514
  const char *sharedir= get_relative_path(PKGDATADIR);
4847
2515
  if (test_if_hard_path(sharedir))
4848
 
    strmake(buff,sharedir,sizeof(buff)-1);              /* purecov: tested */
 
2516
    strncpy(buff,sharedir,sizeof(buff)-1);
4849
2517
  else
4850
 
    strxnmov(buff,sizeof(buff)-1,mysql_home,sharedir,NULL);
 
2518
  {
 
2519
    strcpy(buff, drizzle_home);
 
2520
    strncat(buff, sharedir, sizeof(buff)-strlen(drizzle_home)-1);
 
2521
  }
4851
2522
  convert_dirname(buff,buff,NULL);
4852
2523
  (void) my_load_path(language,language,buff);
4853
2524
 
4854
 
  /* If --character-sets-dir isn't given, use shared library dir */
4855
 
  if (charsets_dir != mysql_charsets_dir)
4856
 
  {
4857
 
    strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir)-1, buff,
4858
 
             CHARSET_DIR, NULL);
4859
 
  }
4860
 
  (void) my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff);
4861
 
  convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NULL);
4862
 
  charsets_dir=mysql_charsets_dir;
4863
 
 
4864
 
  if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir))
4865
 
    exit(1);
4866
 
  if (!slave_load_tmpdir)
4867
 
  {
4868
 
    if (!(slave_load_tmpdir = (char*) my_strdup(mysql_tmpdir, MYF(MY_FAE))))
 
2525
  {
 
2526
    char *tmp_string;
 
2527
    struct stat buf;
 
2528
 
 
2529
    tmp_string= getenv("TMPDIR");
 
2530
 
 
2531
    if (opt_drizzle_tmpdir)
 
2532
      drizzle_tmpdir= strdup(opt_drizzle_tmpdir);
 
2533
    else if (tmp_string == NULL)
 
2534
      drizzle_tmpdir= strdup(P_tmpdir);
 
2535
    else
 
2536
      drizzle_tmpdir= strdup(tmp_string);
 
2537
 
 
2538
    assert(drizzle_tmpdir);
 
2539
 
 
2540
    if (stat(drizzle_tmpdir, &buf) || (S_ISDIR(buf.st_mode) == false))
 
2541
    {
4869
2542
      exit(1);
 
2543
    }
4870
2544
  }
 
2545
 
4871
2546
  /*
4872
2547
    Convert the secure-file-priv option to system format, allowing
4873
2548
    a quick strcmp to check if read or write is in an allowed dir
4876
2551
  {
4877
2552
    convert_dirname(buff, opt_secure_file_priv, NULL);
4878
2553
    free(opt_secure_file_priv);
4879
 
    opt_secure_file_priv= my_strdup(buff, MYF(MY_FAE));
4880
 
  }
4881
 
}
4882
 
 
4883
 
 
4884
 
static uint32_t find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
4885
 
                                   const char *option)
4886
 
{
4887
 
  uint32_t res;
4888
 
 
4889
 
  const char **ptr;
4890
 
 
4891
 
  if ((res= find_bit_type(x, bit_lib)) == ~(uint32_t) 0)
4892
 
  {
4893
 
    ptr= bit_lib->type_names;
4894
 
    if (!*x)
4895
 
      fprintf(stderr, _("No option given to %s\n"), option);
4896
 
    else
4897
 
      fprintf(stderr, _("Wrong option to %s. Option(s) given: %s\n"),
4898
 
              option, x);
4899
 
    fprintf(stderr, _("Alternatives are: '%s'"), *ptr);
4900
 
    while (*++ptr)
4901
 
      fprintf(stderr, ",'%s'", *ptr);
4902
 
    fprintf(stderr, "\n");
4903
 
    exit(1);
4904
 
  }
4905
 
  return res;
4906
 
}
4907
 
 
4908
 
 
4909
 
/**
4910
 
  @return
4911
 
    a bitfield from a string of substrings separated by ','
4912
 
    or
4913
 
    ~(uint32_t) 0 on error.
4914
 
*/
4915
 
 
4916
 
static uint32_t find_bit_type(const char *x, TYPELIB *bit_lib)
4917
 
{
4918
 
  bool found_end;
4919
 
  int  found_count;
4920
 
  const char *end,*i,*j;
4921
 
  const char **array, *pos;
4922
 
  uint32_t found,found_int,bit;
4923
 
 
4924
 
  found=0;
4925
 
  found_end= 0;
4926
 
  pos=(char *) x;
4927
 
  while (*pos == ' ') pos++;
4928
 
  found_end= *pos == 0;
4929
 
  while (!found_end)
4930
 
  {
4931
 
    if ((end=strrchr(pos,',')) != NULL)         /* Let end point at fieldend */
4932
 
    {
4933
 
      while (end > pos && end[-1] == ' ')
4934
 
        end--;                                  /* Skip end-space */
4935
 
      found_end=1;
4936
 
    }
4937
 
    else
4938
 
    {
4939
 
        end=pos+strlen(pos);
4940
 
        found_end=1;
4941
 
    }
4942
 
    found_int=0; found_count=0;
4943
 
    for (array=bit_lib->type_names, bit=1 ; (i= *array++) ; bit<<=1)
4944
 
    {
4945
 
      j=pos;
4946
 
      while (j != end)
4947
 
      {
4948
 
        if (my_toupper(mysqld_charset,*i++) !=
4949
 
            my_toupper(mysqld_charset,*j++))
4950
 
          goto skip;
4951
 
      }
4952
 
      found_int=bit;
4953
 
      if (! *i)
4954
 
      {
4955
 
        found_count=1;
4956
 
        break;
4957
 
      }
4958
 
      else if (j != pos)                        // Half field found
4959
 
      {
4960
 
        found_count++;                          // Could be one of two values
4961
 
      }
4962
 
skip: ;
4963
 
    }
4964
 
    if (found_count != 1)
4965
 
      return(~(uint32_t) 0);                            // No unique value
4966
 
    found|=found_int;
4967
 
    pos=end+1;
4968
 
  }
4969
 
 
4970
 
  return(found);
4971
 
} /* find_bit_type */
4972
 
 
4973
 
 
4974
 
/**
4975
 
  Create file to store pid number.
4976
 
*/
4977
 
static void create_pid_file()
4978
 
{
4979
 
  File file;
4980
 
  if ((file = my_create(pidfile_name,0664,
4981
 
                        O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0)
4982
 
  {
4983
 
    char buff[21], *end;
4984
 
    end= int10_to_str((long) getpid(), buff, 10);
4985
 
    *end++= '\n';
4986
 
    if (!my_write(file, (unsigned char*) buff, (uint) (end-buff), MYF(MY_WME | MY_NABP)))
4987
 
    {
4988
 
      (void) my_close(file, MYF(0));
4989
 
      return;
4990
 
    }
4991
 
    (void) my_close(file, MYF(0));
4992
 
  }
4993
 
  sql_perror("Can't start server: can't create PID file");
4994
 
  exit(1);
4995
 
}
4996
 
 
4997
 
/** Clear most status variables. */
4998
 
void refresh_status(THD *thd)
4999
 
{
5000
 
  pthread_mutex_lock(&LOCK_status);
5001
 
 
5002
 
  /* Add thread's status variabes to global status */
5003
 
  add_to_status(&global_status_var, &thd->status_var);
5004
 
 
5005
 
  /* Reset thread's status variables */
5006
 
  memset(&thd->status_var, 0, sizeof(thd->status_var));
5007
 
 
5008
 
  /* Reset some global variables */
5009
 
  reset_status_vars();
5010
 
 
5011
 
  /* Reset the counters of all key caches (default and named). */
5012
 
  process_key_caches(reset_key_cache_counters);
5013
 
  flush_status_time= time((time_t*) 0);
5014
 
  pthread_mutex_unlock(&LOCK_status);
5015
 
 
5016
 
  /*
5017
 
    Set max_used_connections to the number of currently open
5018
 
    connections.  Lock LOCK_thread_count out of LOCK_status to avoid
5019
 
    deadlocks.  Status reset becomes not atomic, but status data is
5020
 
    not exact anyway.
5021
 
  */
5022
 
  pthread_mutex_lock(&LOCK_thread_count);
5023
 
  max_used_connections= thread_count;
5024
 
  pthread_mutex_unlock(&LOCK_thread_count);
5025
 
}
5026
 
 
 
2554
    opt_secure_file_priv= strdup(buff);
 
2555
    if (opt_secure_file_priv == NULL)
 
2556
      exit(1);
 
2557
  }
 
2558
}
5027
2559
 
5028
2560
/*****************************************************************************
5029
2561
  Instantiate templates
5031
2563
 
5032
2564
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
5033
2565
/* Used templates */
5034
 
template class I_List<THD>;
5035
 
template class I_List_iterator<THD>;
5036
2566
template class I_List<i_string>;
5037
2567
template class I_List<i_string_pair>;
5038
 
template class I_List<NAMED_LIST>;
5039
2568
template class I_List<Statement>;
5040
2569
template class I_List_iterator<Statement>;
5041
2570
#endif