~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/drizzled.cc

  • Committer: Mark Atwood
  • Date: 2008-07-12 11:37:59 UTC
  • mto: This revision was merged to the branch mainline in revision 139.
  • Revision ID: me@mark.atwood.name-20080712113759-nrjn1bq1e0shuory
Add hello_world() UDF

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