~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Monty Taylor
  • Date: 2008-07-28 02:47:38 UTC
  • mto: (212.5.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 219.
  • Revision ID: monty@inaugust.com-20080728024738-366ikqnoqv7d8g6l
Fixed the includes in places to make the myisam header file move work.

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