~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/drizzled.cc

Merge/fix in FAQ.

Show diffs side-by-side

added added

removed removed

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