~drizzle-trunk/drizzle/development

520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
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
1 by brian
clean slate
20
798.2.28 by Brian Aker
More pulling of code... master_pos function code removed.
21
#include <drizzled/configmake.h>
243.1.17 by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.)
22
#include <drizzled/server_includes.h>
520.6.2 by Monty Taylor
Removed netdb.h from common_includes. Check it out - it was only used in ***2*** files. _Definitely_ a common include.
23
24
#include <netdb.h>
25
#include <sys/poll.h>
26
#include <netinet/tcp.h>
520.6.5 by Monty Taylor
Removed signal.h from common_includes.
27
#include <signal.h>
520.6.2 by Monty Taylor
Removed netdb.h from common_includes. Check it out - it was only used in ***2*** files. _Definitely_ a common include.
28
212.5.28 by Monty Taylor
Moved my_bit and my_list
29
#include <mysys/my_bit.h>
779.3.37 by Monty Taylor
Renmaed libdrizzle in the tree to libdrizzleclient to avoid namespace clashes
30
#include <libdrizzleclient/libdrizzle.h>
614 by Brian Aker
Remove filtering (wrong layer, belongs in plugin).
31
#include <mysys/hash.h>
520.6.2 by Monty Taylor
Removed netdb.h from common_includes. Check it out - it was only used in ***2*** files. _Definitely_ a common include.
32
#include <drizzled/stacktrace.h>
212.5.13 by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys.
33
#include <mysys/mysys_err.h>
549 by Monty Taylor
Took gettext.h out of header files.
34
#include <drizzled/error.h>
722.4.1 by Mark Atwood
integrate errmsg plugin into sql_print_* functions
35
#include <drizzled/errmsg_print.h>
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
36
#include <drizzled/tztime.h>
575.4.7 by Monty Taylor
More header cleanup.
37
#include <drizzled/sql_base.h>
38
#include <drizzled/show.h>
39
#include <drizzled/sql_parse.h>
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
40
#include <drizzled/item/cmpfunc.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
41
#include <drizzled/session.h>
42
#include <drizzled/db.h>
43
#include <drizzled/item/create.h>
612.1.1 by Mark Atwood
remove some errmsg dead code, use more of the errmsg plugin
44
#include <drizzled/errmsg.h>
670.2.4 by Monty Taylor
Removed more stuff from the headers.
45
#include <drizzled/unireg.h>
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
46
#include <drizzled/plugin_scheduling.h>
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
47
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
1 by brian
clean slate
48
481.1.15 by Monty Taylor
Removed time.h and sys/time.h from global.h.
49
#if TIME_WITH_SYS_TIME
50
# include <sys/time.h>
51
# include <time.h>
52
#else
53
# if HAVE_SYS_TIME_H
54
#  include <sys/time.h>
55
# else
56
#  include <time.h>
57
# endif
58
#endif
59
230.1.5 by Monty Taylor
Fixed a quick includes in drizzled.cc.
60
#include <storage/myisam/ha_myisam.h>
1 by brian
clean slate
61
62
#ifdef HAVE_SYS_PRCTL_H
63
#include <sys/prctl.h>
64
#endif
65
66
#ifndef DEFAULT_SKIP_THREAD_PRIORITY
67
#define DEFAULT_SKIP_THREAD_PRIORITY 0
68
#endif
69
779.3.37 by Monty Taylor
Renmaed libdrizzle in the tree to libdrizzleclient to avoid namespace clashes
70
#include <libdrizzleclient/errmsg.h>
202.3.8 by Monty Taylor
Actually turn gettext on...
71
#include <locale.h>
1 by brian
clean slate
72
383.1.6 by Brian Aker
Removed more of the charset support.
73
#define mysqld_charset &my_charset_utf8_general_ci
1 by brian
clean slate
74
75
#ifdef HAVE_purify
76
#define IF_PURIFY(A,B) (A)
77
#else
78
#define IF_PURIFY(A,B) (B)
79
#endif
80
481.1.23 by Monty Taylor
Removed custome max size_t with SIZE_MAX
81
#define MAX_MEM_TABLE_SIZE SIZE_MAX
1 by brian
clean slate
82
83
extern "C" {					// Because of SCO 3.2V4.2
84
#include <errno.h>
85
#include <sys/stat.h>
212.5.21 by Monty Taylor
Moved my_getopt.h
86
#include <mysys/my_getopt.h>
1 by brian
clean slate
87
#ifdef HAVE_SYSENT_H
88
#include <sysent.h>
89
#endif
90
#ifdef HAVE_PWD_H
91
#include <pwd.h>				// For getpwent
92
#endif
93
#ifdef HAVE_GRP_H
94
#include <grp.h>
95
#endif
96
97
#include <sys/resource.h>
98
99
#ifdef HAVE_SELECT_H
100
#  include <select.h>
101
#endif
102
103
#ifdef HAVE_SYS_SELECT_H
104
#include <sys/select.h>
105
#endif
106
107
#include <sys/utsname.h>
108
109
#ifdef HAVE_SYS_MMAN_H
110
#include <sys/mman.h>
111
#endif
112
113
#define SIGNAL_FMT "signal %d"
236.1.40 by Monty Taylor
A few meaningless changes.
114
1 by brian
clean slate
115
116
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H)
117
#include <ieeefp.h>
118
#ifdef HAVE_FP_EXCEPT				// Fix type conflict
119
typedef fp_except fp_except_t;
120
#endif
121
#endif /* __FreeBSD__ && HAVE_IEEEFP_H */
122
123
#ifdef HAVE_FPU_CONTROL_H
124
#include <fpu_control.h>
125
#endif
126
127
#ifdef HAVE_SYS_FPU_H
128
/* for IRIX to use set_fpc_csr() */
129
#include <sys/fpu.h>
130
#endif
131
575.4.6 by Monty Taylor
Removed my_getwd.
132
1 by brian
clean slate
133
inline void setup_fpu()
134
{
135
#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H)
136
  /*
137
     We can't handle floating point exceptions with threads, so disable
138
     this on freebsd.
139
     Don't fall for overflow, underflow,divide-by-zero or loss of precision
140
  */
141
#if defined(__i386__)
142
  fpsetmask(~(FP_X_INV | FP_X_DNML | FP_X_OFL | FP_X_UFL | FP_X_DZ |
143
	      FP_X_IMP));
144
#else
145
  fpsetmask(~(FP_X_INV |             FP_X_OFL | FP_X_UFL | FP_X_DZ |
146
              FP_X_IMP));
147
#endif /* __i386__ */
148
#endif /* __FreeBSD__ && HAVE_IEEEFP_H */
149
150
  /*
151
    x86 (32-bit) requires FPU precision to be explicitly set to 64 bit for
152
    portable results of floating point operations
153
  */
154
#if defined(__i386__) && defined(HAVE_FPU_CONTROL_H) && defined(_FPU_DOUBLE)
155
  fpu_control_t cw;
156
  _FPU_GETCW(cw);
157
  cw= (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
158
  _FPU_SETCW(cw);
159
#endif /* __i386__ && HAVE_FPU_CONTROL_H && _FPU_DOUBLE */
160
}
161
162
} /* cplusplus */
163
212.5.13 by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys.
164
#include <mysys/my_pthread.h>			// For thr_setconcurency()
1 by brian
clean slate
165
538 by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib.
166
#include <drizzled/gettext.h>
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
167
1 by brian
clean slate
168
#ifdef SOLARIS
169
extern "C" int gethostname(char *name, int namelen);
170
#endif
171
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
172
extern "C" void handle_segfault(int sig);
1 by brian
clean slate
173
575.4.6 by Monty Taylor
Removed my_getwd.
174
using namespace std;
175
1 by brian
clean slate
176
/* Constants */
177
178
const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"};
179
/*
180
  WARNING: When adding new SQL modes don't forget to update the
181
           tables definitions that stores it's value.
182
           (ie: mysql.event, mysql.proc)
183
*/
184
static const char *optimizer_switch_names[]=
185
{
186
  "no_materialization", "no_semijoin",
461 by Monty Taylor
Removed NullS. bu-bye.
187
  NULL
1 by brian
clean slate
188
};
189
190
/* Corresponding defines are named OPTIMIZER_SWITCH_XXX */
191
static const unsigned int optimizer_switch_names_len[]=
192
{
193
  /*no_materialization*/          19,
194
  /*no_semijoin*/                 11
195
};
196
197
TYPELIB optimizer_switch_typelib= { array_elements(optimizer_switch_names)-1,"",
198
                                    optimizer_switch_names,
199
                                    (unsigned int *)optimizer_switch_names_len };
200
201
static const char *tc_heuristic_recover_names[]=
202
{
461 by Monty Taylor
Removed NullS. bu-bye.
203
  "COMMIT", "ROLLBACK", NULL
1 by brian
clean slate
204
};
205
static TYPELIB tc_heuristic_recover_typelib=
206
{
207
  array_elements(tc_heuristic_recover_names)-1,"",
208
  tc_heuristic_recover_names, NULL
209
};
210
211
const char *first_keyword= "first", *binary_keyword= "BINARY";
212
const char *my_localhost= "localhost";
722.1.3 by Monty Taylor
Cleaned up a few build things.
213
const char * const DRIZZLE_CONFIG_NAME= "drizzled";
1 by brian
clean slate
214
#define GET_HA_ROWS GET_ULL
215
216
/*
217
  Used with --help for detailed option
218
*/
259 by Brian Aker
First pass on PAM auth
219
static bool opt_help= false;
1 by brian
clean slate
220
221
arg_cmp_func Arg_comparator::comparator_matrix[5][2] =
222
{{&Arg_comparator::compare_string,     &Arg_comparator::compare_e_string},
223
 {&Arg_comparator::compare_real,       &Arg_comparator::compare_e_real},
224
 {&Arg_comparator::compare_int_signed, &Arg_comparator::compare_e_int},
225
 {&Arg_comparator::compare_row,        &Arg_comparator::compare_e_row},
226
 {&Arg_comparator::compare_decimal,    &Arg_comparator::compare_e_decimal}};
227
228
/* static variables */
229
230
/* the default log output is log tables */
900 by Brian Aker
Creating signal handler plugin.
231
static bool volatile select_thread_in_use;
1 by brian
clean slate
232
static bool volatile ready_to_exit;
722.4.1 by Mark Atwood
integrate errmsg plugin into sql_print_* functions
233
static bool opt_debugging= 0;
566 by Brian Aker
Clean up dead thead code.
234
static uint32_t wake_thread;
366 by Patrick Galbraith
Ulong conversion
235
static uint32_t killed_threads, thread_created;
722.4.1 by Mark Atwood
integrate errmsg plugin into sql_print_* functions
236
static char *drizzled_user, *drizzled_chroot;
798.2.32 by Brian Aker
Last removal of variables.
237
static char *language_ptr, *opt_init_connect;
1 by brian
clean slate
238
static char *default_character_set_name;
239
static char *character_set_filesystem_name;
240
static char *lc_time_names_name;
241
static char *my_bind_addr_str;
236.1.40 by Monty Taylor
A few meaningless changes.
242
static char *default_collation_name;
1 by brian
clean slate
243
static char *default_storage_engine_str;
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
244
static char compiled_default_collation_name[]= DRIZZLE_DEFAULT_COLLATION_NAME;
855 by Brian Aker
Refactor reset of status.
245
static struct pollfd fds[UINT8_MAX];
246
static uint8_t pollfd_count= 0;
1 by brian
clean slate
247
248
/* Global variables */
249
92 by Brian Aker
Removed opt_update_log
250
bool opt_bin_log;
147 by Brian Aker
More my_bool conversion. This time the set_var class.
251
bool opt_log_queries_not_using_indexes= false;
252
bool opt_skip_show_db= false;
1 by brian
clean slate
253
bool server_id_supplied = 0;
254
bool opt_endinfo, using_udf_functions;
150 by Brian Aker
More bool removal. More cow bell!
255
bool locked_in_memory;
604 by Brian Aker
Remove lock condition needed (we do row based replication, so... lock is
256
bool opt_using_transactions;
1 by brian
clean slate
257
bool volatile abort_loop;
258
bool volatile shutdown_in_progress;
150 by Brian Aker
More bool removal. More cow bell!
259
bool opt_skip_slave_start = 0; ///< If set, slave is not autostarted
260
bool opt_reckless_slave = 0;
261
bool opt_enable_named_pipe= 0;
147 by Brian Aker
More my_bool conversion. This time the set_var class.
262
bool opt_local_infile;
150 by Brian Aker
More bool removal. More cow bell!
263
bool opt_safe_user_create = 0;
264
bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
265
bool opt_log_slave_updates= 0;
855 by Brian Aker
Refactor reset of status.
266
uint32_t max_used_connections;
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
267
const char *opt_scheduler= "pool_of_threads";
1 by brian
clean slate
268
629.2.7 by Monty Taylor
Fixed a couple of memory buffer size issues.
269
size_t my_thread_stack_size= 65536;
270
1 by brian
clean slate
271
/*
272
  Legacy global handlerton. These will be removed (please do not add more).
273
*/
274
handlerton *heap_hton;
275
handlerton *myisam_hton;
276
150 by Brian Aker
More bool removal. More cow bell!
277
bool use_temp_pool;
1 by brian
clean slate
278
char* opt_secure_file_priv= 0;
279
/*
280
  True if there is at least one per-hour limit for some user, so we should
281
  check them before each query (and possibly reset counters when hour is
282
  changed). False otherwise.
283
*/
150 by Brian Aker
More bool removal. More cow bell!
284
bool opt_noacl;
1 by brian
clean slate
285
286
#ifdef HAVE_INITGROUPS
163 by Brian Aker
Merge Monty's code.
287
static bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
1 by brian
clean slate
288
#endif
574.2.1 by ysano
Rename mysql to drizzle.
289
uint32_t drizzled_port, test_flags, select_errors, dropping_tables, ha_open_options;
290
uint32_t drizzled_port_timeout;
722.1.3 by Monty Taylor
Cleaned up a few build things.
291
uint32_t delay_key_write_options, protocol_version= PROTOCOL_VERSION;
482 by Brian Aker
Remove uint.
292
uint32_t lower_case_table_names= 1;
293
uint32_t tc_heuristic_recover= 0;
294
uint32_t volatile thread_count, thread_running;
520.1.22 by Brian Aker
Second pass of thd cleanup
295
uint64_t session_startup_options;
626 by Brian Aker
More of the same (ulong/64)
296
uint32_t back_log;
892.2.2 by Monty Taylor
More solaris warnings.
297
uint32_t connect_timeout;
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
298
uint32_t server_id;
622.1.1 by Brian Aker
32bit fixes around vars
299
uint64_t table_cache_size;
300
uint64_t table_def_size;
301
uint64_t slow_launch_time;
625 by Brian Aker
ulong/64 bit straighten out.
302
uint64_t slave_open_temp_tables;
366 by Patrick Galbraith
Ulong conversion
303
uint32_t refresh_version;  /* Increments on each reload */
625 by Brian Aker
ulong/64 bit straighten out.
304
uint64_t aborted_threads;
305
uint64_t aborted_connects;
622.1.1 by Brian Aker
32bit fixes around vars
306
uint64_t max_connect_errors;
366 by Patrick Galbraith
Ulong conversion
307
ulong thread_id=1L;
606 by Brian Aker
Remove dead lex structure and clean up use of pid_t
308
pid_t current_pid;
625 by Brian Aker
ulong/64 bit straighten out.
309
uint64_t slow_launch_threads= 0;
1 by brian
clean slate
310
311
const double log_10[] = {
312
  1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,
313
  1e010, 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019,
314
  1e020, 1e021, 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029,
315
  1e030, 1e031, 1e032, 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039,
316
  1e040, 1e041, 1e042, 1e043, 1e044, 1e045, 1e046, 1e047, 1e048, 1e049,
317
  1e050, 1e051, 1e052, 1e053, 1e054, 1e055, 1e056, 1e057, 1e058, 1e059,
318
  1e060, 1e061, 1e062, 1e063, 1e064, 1e065, 1e066, 1e067, 1e068, 1e069,
319
  1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076, 1e077, 1e078, 1e079,
320
  1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087, 1e088, 1e089,
321
  1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098, 1e099,
322
  1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109,
323
  1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119,
324
  1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129,
325
  1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139,
326
  1e140, 1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149,
327
  1e150, 1e151, 1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159,
328
  1e160, 1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169,
329
  1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178, 1e179,
330
  1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188, 1e189,
331
  1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199,
332
  1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209,
333
  1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219,
334
  1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229,
335
  1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239,
336
  1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249,
337
  1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259,
338
  1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269,
339
  1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279,
340
  1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286, 1e287, 1e288, 1e289,
341
  1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296, 1e297, 1e298, 1e299,
342
  1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308
343
};
344
855 by Brian Aker
Refactor reset of status.
345
time_t server_start_time;
346
time_t flush_status_time;
1 by brian
clean slate
347
909 by Brian Aker
Remove the need for unireg init
348
/* FRM Junk */
349
const char *reg_ext= ".frm";
350
uint32_t reg_ext_length= 4;
351
575.4.1 by ysano
Rename mysql to drizzle.
352
char drizzle_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
1 by brian
clean slate
353
char *default_tz_name;
722.4.1 by Mark Atwood
integrate errmsg plugin into sql_print_* functions
354
char glob_hostname[FN_REFLEN];
575.4.1 by ysano
Rename mysql to drizzle.
355
char drizzle_real_data_home[FN_REFLEN],
856 by Brian Aker
Remove dead code around charset variable/directory.
356
     language[FN_REFLEN], 
357
     *opt_init_file, 
358
     *opt_tc_log_file;
575.4.1 by ysano
Rename mysql to drizzle.
359
char drizzle_unpacked_real_data_home[FN_REFLEN];
1 by brian
clean slate
360
const key_map key_map_empty(0);
361
key_map key_map_full(0);                        // Will be initialized later
362
575.4.1 by ysano
Rename mysql to drizzle.
363
uint32_t drizzle_data_home_len;
575.4.3 by ysano
Rename mysql to drizzle.
364
char drizzle_data_home_buff[2], *drizzle_data_home=drizzle_real_data_home;
1 by brian
clean slate
365
char server_version[SERVER_VERSION_LENGTH];
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
366
char *drizzle_tmpdir= NULL;
367
char *opt_drizzle_tmpdir= NULL;
1 by brian
clean slate
368
const char *myisam_recover_options_str="OFF";
369
const char *myisam_stats_method_str="nulls_unequal";
370
371
/** name of reference on left espression in rewritten IN subquery */
372
const char *in_left_expr_name= "<left expr>";
373
/** name of additional condition */
374
const char *in_additional_cond= "<IN COND>";
375
const char *in_having_cond= "<IN HAVING>";
376
377
my_decimal decimal_zero;
378
/* classes for comparation parsing/processing */
379
380
FILE *stderror_file=0;
381
520.1.21 by Brian Aker
THD -> Session rename
382
I_List<Session> threads;
1 by brian
clean slate
383
I_List<NAMED_LIST> key_caches;
384
385
struct system_variables global_system_variables;
386
struct system_variables max_system_variables;
387
struct system_status_var global_status_var;
388
389
MY_BITMAP temp_pool;
390
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
391
const CHARSET_INFO *system_charset_info, *files_charset_info ;
392
const CHARSET_INFO *national_charset_info, *table_alias_charset;
393
const CHARSET_INFO *character_set_filesystem;
1 by brian
clean slate
394
395
MY_LOCALE *my_default_lc_time_names;
396
177.3.1 by mark
remove ifdef HAVE_DLOPEN, make configure require dlopen()
397
SHOW_COMP_OPTION have_symlink;
1 by brian
clean slate
398
399
/* Thread specific variables */
400
670.2.1 by Monty Taylor
Moved pthread keys
401
pthread_key_t THR_Mem_root;
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
402
pthread_key_t THR_Session;
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
403
pthread_mutex_t LOCK_drizzleclient_create_db, 
808 by Brian Aker
Move number of threads to use for pool of threads to module. Removed slave
404
                LOCK_open, 
405
                LOCK_thread_count,
566 by Brian Aker
Clean up dead thead code.
406
                LOCK_status,
407
                LOCK_global_read_lock,
854 by Brian Aker
Removed double lock usage.
408
                LOCK_global_system_variables;
1 by brian
clean slate
409
658 by Brian Aker
Part removal of my_pthread.h
410
pthread_rwlock_t	LOCK_sys_init_connect;
411
pthread_rwlock_t	LOCK_system_variables_hash;
1 by brian
clean slate
412
pthread_cond_t COND_refresh, COND_thread_count, COND_global_read_lock;
413
pthread_t signal_thread;
414
pthread_attr_t connection_attrib;
415
pthread_cond_t  COND_server_started;
416
417
/* replication parameters, if master_host is not NULL, we are a slave */
482 by Brian Aker
Remove uint.
418
uint32_t report_port= DRIZZLE_PORT;
130 by Brian Aker
ulong cleanup
419
uint32_t master_retry_count= 0;
1 by brian
clean slate
420
char *master_info_file;
571 by Brian Aker
Removed random dead code left over from previous scheduler (plus the... has
421
char *report_host;
438.1.1 by Brian Aker
First pass of removing historical logging.
422
char *opt_logname;
1 by brian
clean slate
423
424
/* Static variables */
425
900 by Brian Aker
Creating signal handler plugin.
426
static bool segfaulted;
1 by brian
clean slate
427
#ifdef HAVE_STACK_TRACE_ON_SEGV
150 by Brian Aker
More bool removal. More cow bell!
428
static bool opt_do_pstack;
1 by brian
clean slate
429
#endif /* HAVE_STACK_TRACE_ON_SEGV */
900 by Brian Aker
Creating signal handler plugin.
430
int cleanup_done;
574.2.1 by ysano
Rename mysql to drizzle.
431
static char *drizzle_home_ptr, *pidfile_name_ptr;
1 by brian
clean slate
432
static int defaults_argc;
433
static char **defaults_argv;
434
static char *opt_bin_logname;
435
520.1.21 by Brian Aker
THD -> Session rename
436
struct rand_struct sql_rand; ///< used by sql_class.cc:Session::Session()
1 by brian
clean slate
437
438
struct passwd *user_info;
439
static pthread_t select_thread;
482 by Brian Aker
Remove uint.
440
static uint32_t thr_kill_signal;
1 by brian
clean slate
441
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
442
extern scheduling_st thread_scheduler;
1 by brian
clean slate
443
444
/**
445
  Number of currently active user connections. The variable is protected by
854 by Brian Aker
Removed double lock usage.
446
  LOCK_thread_count.
1 by brian
clean slate
447
*/
910.5.3 by Monty Taylor
Rolled back the atomic2 patch.
448
uint32_t connection_count= 0;
1 by brian
clean slate
449
450
/* Function declarations */
451
779.3.23 by Monty Taylor
More fixy-fixes.
452
extern "C" pthread_handler_t signal_hand(void *arg);
574.2.1 by ysano
Rename mysql to drizzle.
453
static void drizzle_init_variables(void);
1 by brian
clean slate
454
static void get_options(int *argc,char **argv);
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
455
extern "C" bool drizzled_get_one_option(int, const struct my_option *, char *);
1 by brian
clean slate
456
static void set_server_version(void);
457
static int init_thread_environment();
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
458
static const char *get_relative_path(const char *path);
1 by brian
clean slate
459
static void fix_paths(void);
11 by Brian Aker
Removing old UNIX socket bits
460
void handle_connections_sockets();
779.3.23 by Monty Taylor
More fixy-fixes.
461
extern "C" pthread_handler_t handle_slave(void *arg);
366 by Patrick Galbraith
Ulong conversion
462
static uint32_t find_bit_type(const char *x, TYPELIB *bit_lib);
463
static uint32_t find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
1 by brian
clean slate
464
                                   const char *option);
465
static void clean_up(bool print_message);
466
467
static void usage(void);
468
static void clean_up_mutexes(void);
779.3.23 by Monty Taylor
More fixy-fixes.
469
extern "C" bool safe_read_error_impl(NET *net);
1 by brian
clean slate
470
471
/****************************************************************************
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
472
** Code to end drizzled
1 by brian
clean slate
473
****************************************************************************/
474
900 by Brian Aker
Creating signal handler plugin.
475
void close_connections(void)
1 by brian
clean slate
476
{
907 by Brian Aker
Shutdown for Linux fixed.
477
  int x;
478
479
  /* Abort listening to new connections */
480
  for (x= 0; x < pollfd_count; x++)
481
  {
482
    if (fds[x].fd != -1)
483
    {
484
      (void) shutdown(fds[x].fd, SHUT_RDWR);
485
      (void) close(fds[x].fd);
486
      fds[x].fd= -1;
487
    }
488
  }
489
1 by brian
clean slate
490
491
  /* kill connection thread */
492
  (void) pthread_mutex_lock(&LOCK_thread_count);
493
494
  while (select_thread_in_use)
495
  {
496
    struct timespec abstime;
497
    int error;
498
499
    set_timespec(abstime, 2);
482 by Brian Aker
Remove uint.
500
    for (uint32_t tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
1 by brian
clean slate
501
    {
907 by Brian Aker
Shutdown for Linux fixed.
502
      error=pthread_cond_timedwait(&COND_thread_count,&LOCK_thread_count, &abstime);
1 by brian
clean slate
503
      if (error != EINTR)
907 by Brian Aker
Shutdown for Linux fixed.
504
        break;
1 by brian
clean slate
505
    }
506
  }
507
  (void) pthread_mutex_unlock(&LOCK_thread_count);
508
509
510
  /*
511
    First signal all threads that it's time to die
512
    This will give the threads some time to gracefully abort their
513
    statements and inform their clients that the server is about to die.
514
  */
515
520.1.21 by Brian Aker
THD -> Session rename
516
  Session *tmp;
1 by brian
clean slate
517
  (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
518
520.1.21 by Brian Aker
THD -> Session rename
519
  I_List_iterator<Session> it(threads);
1 by brian
clean slate
520
  while ((tmp=it++))
521
  {
520.1.21 by Brian Aker
THD -> Session rename
522
    tmp->killed= Session::KILL_CONNECTION;
1 by brian
clean slate
523
    thread_scheduler.post_kill_notification(tmp);
524
    if (tmp->mysys_var)
525
    {
526
      tmp->mysys_var->abort=1;
527
      pthread_mutex_lock(&tmp->mysys_var->mutex);
528
      if (tmp->mysys_var->current_cond)
529
      {
566 by Brian Aker
Clean up dead thead code.
530
        pthread_mutex_lock(tmp->mysys_var->current_mutex);
531
        pthread_cond_broadcast(tmp->mysys_var->current_cond);
532
        pthread_mutex_unlock(tmp->mysys_var->current_mutex);
1 by brian
clean slate
533
      }
534
      pthread_mutex_unlock(&tmp->mysys_var->mutex);
535
    }
536
  }
537
  (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
538
855 by Brian Aker
Refactor reset of status.
539
  /* TODO This is a crappy way to handle this. Fix for proper shutdown. */
1 by brian
clean slate
540
  if (thread_count)
541
    sleep(2);					// Give threads time to die
542
543
  /*
544
    Force remaining threads to die by closing the connection to the client
545
    This will ensure that threads that are waiting for a command from the
546
    client on a blocking read call are aborted.
547
  */
548
549
  for (;;)
550
  {
551
    (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
552
    if (!(tmp=threads.get()))
553
    {
554
      (void) pthread_mutex_unlock(&LOCK_thread_count);
555
      break;
556
    }
840.1.19 by Monty Taylor
Renamed vio.
557
    if (tmp->drizzleclient_vio_ok())
1 by brian
clean slate
558
    {
559
      if (global_system_variables.log_warnings)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
560
            errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),my_progname,
1 by brian
clean slate
561
                          tmp->thread_id,
694 by Brian Aker
Refactor out char* strdup for string class in user.
562
                          (tmp->security_ctx.user.c_str() ?
563
                           tmp->security_ctx.user.c_str() : ""));
693 by Brian Aker
Cleaning up session class.
564
      tmp->close_connection(0,0);
1 by brian
clean slate
565
    }
566
    (void) pthread_mutex_unlock(&LOCK_thread_count);
567
  }
568
  /* All threads has now been aborted */
569
  (void) pthread_mutex_lock(&LOCK_thread_count);
570
  while (thread_count)
571
  {
572
    (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
573
  }
574
  (void) pthread_mutex_unlock(&LOCK_thread_count);
575
}
576
577
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
578
extern "C" void print_signal_warning(int sig)
1 by brian
clean slate
579
{
580
  if (global_system_variables.log_warnings)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
581
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64), sig,my_thread_id());
447 by Monty Taylor
Removed DONT_REMEMBER_SIGNAL define.
582
#ifndef HAVE_BSD_SIGNALS
1 by brian
clean slate
583
  my_sigset(sig,print_signal_warning);		/* int. thread system calls */
584
#endif
585
  if (sig == SIGALRM)
586
    alarm(2);					/* reschedule alarm */
587
}
588
589
/**
590
  cleanup all memory and end program nicely.
591
592
    If SIGNALS_DONT_BREAK_READ is defined, this function is called
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
593
    by the main thread. To get Drizzle to shut down nicely in this case
1 by brian
clean slate
594
    (Mac OS X) we have to call exit() instead if pthread_exit().
595
596
  @note
597
    This function never returns.
598
*/
900 by Brian Aker
Creating signal handler plugin.
599
extern "C" void unireg_end(void)
1 by brian
clean slate
600
{
601
  clean_up(1);
602
  my_thread_end();
603
#if defined(SIGNALS_DONT_BREAK_READ)
604
  exit(0);
605
#else
606
  pthread_exit(0);				// Exit is in main thread
607
#endif
608
}
609
610
611
extern "C" void unireg_abort(int exit_code)
612
{
613
614
  if (exit_code)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
615
    errmsg_printf(ERRMSG_LVL_ERROR, _("Aborting\n"));
1 by brian
clean slate
616
  else if (opt_help)
617
    usage();
228 by Brian Aker
First pass on socket cleanup.
618
  clean_up(!opt_help && (exit_code)); /* purecov: inspected */
1 by brian
clean slate
619
  clean_up_mutexes();
620
  my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
621
  exit(exit_code); /* purecov: inspected */
622
}
623
624
909 by Brian Aker
Remove the need for unireg init
625
static void clean_up(bool print_message)
1 by brian
clean slate
626
{
627
  if (cleanup_done++)
628
    return; /* purecov: inspected */
629
630
  table_cache_free();
631
  table_def_free();
632
  set_var_free();
633
  free_charsets();
634
  udf_free();
635
  plugin_shutdown();
636
  ha_end();
637
  xid_cache_free();
481 by Brian Aker
Remove all of uchar.
638
  delete_elements(&key_caches, (void (*)(const char*, unsigned char*)) free_key_cache);
1 by brian
clean slate
639
  multi_keycache_free();
640
  free_status_vars();
641
  my_free_open_file_info();
642
  if (defaults_argv)
643
    free_defaults(defaults_argv);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
644
  free(sys_init_connect.value);
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
645
  free(drizzle_tmpdir);
460 by Monty Taylor
Removed x_free calls.
646
  if (opt_bin_logname)
647
    free(opt_bin_logname);
648
  if (opt_secure_file_priv)
649
    free(opt_secure_file_priv);
1 by brian
clean slate
650
  bitmap_free(&temp_pool);
651
914.2.1 by Brian Aker
Cleanup pid handler.
652
  (void) unlink(pidfile_name);	// This may not always exist
228 by Brian Aker
First pass on socket cleanup.
653
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
654
  if (print_message && server_start_time)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
655
    errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),my_progname);
202.3.7 by Monty Taylor
Gettext error compiles and passes test!
656
  /* Returns NULL on globerrs, we don't want to try to free that */
657
  //void *freeme=
658
  (void *)my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST);
659
  // TODO!!!! EPIC FAIL!!!! This sefaults if uncommented.
660
/*  if (freeme != NULL)
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
661
    free(freeme);  */
1 by brian
clean slate
662
  (void) pthread_mutex_lock(&LOCK_thread_count);
663
  ready_to_exit=1;
664
  /* do the broadcast inside the lock to ensure that my_end() is not called */
665
  (void) pthread_cond_broadcast(&COND_thread_count);
666
  (void) pthread_mutex_unlock(&LOCK_thread_count);
667
668
  /*
669
    The following lines may never be executed as the main thread may have
670
    killed us
671
  */
672
} /* clean_up */
673
674
675
static void clean_up_mutexes()
676
{
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
677
  (void) pthread_mutex_destroy(&LOCK_drizzleclient_create_db);
1 by brian
clean slate
678
  (void) pthread_mutex_destroy(&LOCK_lock_db);
679
  (void) pthread_mutex_destroy(&LOCK_open);
680
  (void) pthread_mutex_destroy(&LOCK_thread_count);
681
  (void) pthread_mutex_destroy(&LOCK_status);
658 by Brian Aker
Part removal of my_pthread.h
682
  (void) pthread_rwlock_destroy(&LOCK_sys_init_connect);
1 by brian
clean slate
683
  (void) pthread_mutex_destroy(&LOCK_global_system_variables);
658 by Brian Aker
Part removal of my_pthread.h
684
  (void) pthread_rwlock_destroy(&LOCK_system_variables_hash);
1 by brian
clean slate
685
  (void) pthread_mutex_destroy(&LOCK_global_read_lock);
686
  (void) pthread_cond_destroy(&COND_thread_count);
687
  (void) pthread_cond_destroy(&COND_refresh);
688
  (void) pthread_cond_destroy(&COND_global_read_lock);
689
}
690
691
692
/****************************************************************************
693
** Init IP and UNIX socket
694
****************************************************************************/
695
696
static void set_ports()
697
{
698
  char	*env;
574.2.1 by ysano
Rename mysql to drizzle.
699
  if (!drizzled_port)
1 by brian
clean slate
700
  {					// Get port if not from commandline
574.2.1 by ysano
Rename mysql to drizzle.
701
    drizzled_port= DRIZZLE_PORT;
1 by brian
clean slate
702
703
    /*
704
      if builder specifically requested a default port, use that
705
      (even if it coincides with our factory default).
706
      only if they didn't do we check /etc/services (and, failing
165.1.1 by Elliot Murphy
new port number from IANA
707
      on that, fall back to the factory default of 4427).
1 by brian
clean slate
708
      either default can be overridden by the environment variable
301 by Brian Aker
Clean up port startup
709
      DRIZZLE_TCP_PORT, which in turn can be overridden with command
1 by brian
clean slate
710
      line options.
711
    */
712
713
    struct  servent *serv_ptr;
301 by Brian Aker
Clean up port startup
714
    if ((serv_ptr= getservbyname("drizzle", "tcp")))
574.2.1 by ysano
Rename mysql to drizzle.
715
      drizzled_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
716
301 by Brian Aker
Clean up port startup
717
    if ((env = getenv("DRIZZLE_TCP_PORT")))
895 by Brian Aker
Completion (?) of uint conversion.
718
      drizzled_port= (uint32_t) atoi(env);		/* purecov: inspected */
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
719
574.2.1 by ysano
Rename mysql to drizzle.
720
    assert(drizzled_port);
1 by brian
clean slate
721
  }
722
}
723
724
/* Change to run as another user if started with --user */
725
726
static struct passwd *check_user(const char *user)
727
{
728
  struct passwd *tmp_user_info;
729
  uid_t user_id= geteuid();
730
731
  // Don't bother if we aren't superuser
732
  if (user_id)
733
  {
734
    if (user)
735
    {
736
      /* Don't give a warning, if real user is same as given with --user */
737
      /* purecov: begin tested */
738
      tmp_user_info= getpwnam(user);
739
      if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
740
          global_system_variables.log_warnings)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
741
            errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
742
                            "if running as root\n"));
1 by brian
clean slate
743
      /* purecov: end */
744
    }
745
    return NULL;
746
  }
747
  if (!user)
748
  {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
749
      errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
750
                      "the manual to find out how to run drizzled as root!\n"));
228 by Brian Aker
First pass on socket cleanup.
751
    unireg_abort(1);
1 by brian
clean slate
752
  }
753
  /* purecov: begin tested */
754
  if (!strcmp(user,"root"))
755
    return NULL;                        // Avoid problem with dynamic libraries
756
757
  if (!(tmp_user_info= getpwnam(user)))
758
  {
759
    // Allow a numeric uid to be used
760
    const char *pos;
761
    for (pos= user; my_isdigit(mysqld_charset,*pos); pos++) ;
762
    if (*pos)                                   // Not numeric id
763
      goto err;
764
    if (!(tmp_user_info= getpwuid(atoi(user))))
765
      goto err;
766
  }
767
  return tmp_user_info;
768
  /* purecov: end */
769
770
err:
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
771
  errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Can't change to run as user '%s' ;  "
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
772
                    "Please check that the user exists!\n"),user);
1 by brian
clean slate
773
  unireg_abort(1);
774
775
#ifdef PR_SET_DUMPABLE
776
  if (test_flags & TEST_CORE_ON_SIGNAL)
777
  {
778
    /* inform kernel that process is dumpable */
779
    (void) prctl(PR_SET_DUMPABLE, 1);
780
  }
781
#endif
782
908.1.13 by Monty Taylor
Fix for Sun Studio 5.10.
783
/* Sun Studio 5.10 doesn't like this line.  5.9 requires it */
908.1.14 by Monty Taylor
I never learn.
784
#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x590)
908.1.12 by Monty Taylor
mmm.
785
  return NULL;
908.1.13 by Monty Taylor
Fix for Sun Studio 5.10.
786
#endif
908.1.12 by Monty Taylor
mmm.
787
1 by brian
clean slate
788
}
789
790
static void set_user(const char *user, struct passwd *user_info_arg)
791
{
792
  /* purecov: begin tested */
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
793
  assert(user_info_arg != 0);
1 by brian
clean slate
794
#ifdef HAVE_INITGROUPS
795
  /*
796
    We can get a SIGSEGV when calling initgroups() on some systems when NSS
797
    is configured to use LDAP and the server is statically linked.  We set
798
    calling_initgroups as a flag to the SIGSEGV handler that is then used to
799
    output a specific message to help the user resolve this problem.
800
  */
163 by Brian Aker
Merge Monty's code.
801
  calling_initgroups= true;
1 by brian
clean slate
802
  initgroups((char*) user, user_info_arg->pw_gid);
163 by Brian Aker
Merge Monty's code.
803
  calling_initgroups= false;
1 by brian
clean slate
804
#endif
805
  if (setgid(user_info_arg->pw_gid) == -1)
806
  {
807
    sql_perror("setgid");
808
    unireg_abort(1);
809
  }
810
  if (setuid(user_info_arg->pw_uid) == -1)
811
  {
812
    sql_perror("setuid");
813
    unireg_abort(1);
814
  }
815
  /* purecov: end */
816
}
817
818
819
static void set_effective_user(struct passwd *user_info_arg)
820
{
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
821
  assert(user_info_arg != 0);
1 by brian
clean slate
822
  if (setregid((gid_t)-1, user_info_arg->pw_gid) == -1)
823
  {
824
    sql_perror("setregid");
825
    unireg_abort(1);
826
  }
827
  if (setreuid((uid_t)-1, user_info_arg->pw_uid) == -1)
828
  {
829
    sql_perror("setreuid");
830
    unireg_abort(1);
831
  }
832
}
833
834
835
/** Change root user if started with @c --chroot . */
836
static void set_root(const char *path)
837
{
575.4.6 by Monty Taylor
Removed my_getwd.
838
  if ((chroot(path) == -1) || !chdir("/"))
1 by brian
clean slate
839
  {
840
    sql_perror("chroot");
841
    unireg_abort(1);
842
  }
843
}
844
845
846
static void network_init(void)
847
{
848
  int   ret;
482 by Brian Aker
Remove uint.
849
  uint32_t  waited;
850
  uint32_t  this_wait;
851
  uint32_t  retry;
1 by brian
clean slate
852
  char port_buf[NI_MAXSERV];
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
853
  struct addrinfo *ai;
854
  struct addrinfo *next;
855
  struct addrinfo hints;
856
  int error;
1 by brian
clean slate
857
858
  set_ports();
859
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
860
  memset(fds, 0, sizeof(struct pollfd) * UINT8_MAX);
861
  memset(&hints, 0, sizeof (hints));
862
  hints.ai_flags= AI_PASSIVE;
863
  hints.ai_socktype= SOCK_STREAM;
864
574.2.1 by ysano
Rename mysql to drizzle.
865
  snprintf(port_buf, NI_MAXSERV, "%d", drizzled_port);
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
866
  error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
867
  if (error != 0)
868
  {
869
    sql_perror(ER(ER_IPSOCK_ERROR));		/* purecov: tested */
870
    unireg_abort(1);				/* purecov: tested */
871
  }
872
873
  for (next= ai, pollfd_count= 0; next; next= next->ai_next, pollfd_count++)
874
  {
875
    int ip_sock;
876
877
    ip_sock= socket(next->ai_family, next->ai_socktype, next->ai_protocol);
1 by brian
clean slate
878
268 by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef
879
    if (ip_sock == -1)
1 by brian
clean slate
880
    {
881
      sql_perror(ER(ER_IPSOCK_ERROR));		/* purecov: tested */
882
      unireg_abort(1);				/* purecov: tested */
883
    }
884
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
885
    fds[pollfd_count].fd= ip_sock;
886
    fds[pollfd_count].events= POLLIN | POLLERR;
887
231 by Brian Aker
Move reuse to working location :)
888
    /* Add options for our listening socket */
889
    {
890
      struct linger ling = {0, 0};
891
      int flags =1;
892
287.2.3 by Andrew Garner
fixed identation problems
893
#ifdef IPV6_V6ONLY
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
894
      if (next->ai_family == AF_INET6)
293 by Brian Aker
Merge + closesocket() fix
895
      {
287.2.3 by Andrew Garner
fixed identation problems
896
        error= setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &flags, sizeof(flags));
287.2.1 by Andrew Garner
enable ipv6 in drizzled
897
        if (error != 0)
898
        {
899
          perror("setsockopt");
900
          assert(error == 0);
901
        }
902
      }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
903
#endif
267 by Brian Aker
More error control around socket calls.
904
      error= setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&flags, sizeof(flags));
905
      if (error != 0)
906
      {
907
        perror("setsockopt");
908
        assert(error == 0);
909
      }
910
      error= setsockopt(ip_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
911
      if (error != 0)
912
      {
913
        perror("setsockopt");
914
        assert(error == 0);
915
      }
916
      error= setsockopt(ip_sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling));
917
      if (error != 0)
918
      {
919
        perror("setsockopt");
920
        assert(error == 0);
921
      }
922
      error= setsockopt(ip_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
923
      if (error != 0)
924
      {
925
        perror("setsockopt");
926
        assert(error == 0);
927
      }
231 by Brian Aker
Move reuse to working location :)
928
    }
929
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
930
1 by brian
clean slate
931
    /*
932
      Sometimes the port is not released fast enough when stopping and
933
      restarting the server. This happens quite often with the test suite
934
      on busy Linux systems. Retry to bind the address at these intervals:
935
      Sleep intervals: 1, 2, 4,  6,  9, 13, 17, 22, ...
936
      Retry at second: 1, 3, 7, 13, 22, 35, 52, 74, ...
574.2.1 by ysano
Rename mysql to drizzle.
937
      Limit the sequence by drizzled_port_timeout (set --port-open-timeout=#).
1 by brian
clean slate
938
    */
939
    for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
940
    {
923.2.2 by Monty Taylor
Changed some names that conflict with c++0x reserved names.
941
      if (((ret= ::bind(ip_sock, next->ai_addr, next->ai_addrlen)) >= 0 ) ||
429 by Monty Taylor
Removed SOCKET redefines.
942
          (errno != EADDRINUSE) ||
574.2.1 by ysano
Rename mysql to drizzle.
943
          (waited >= drizzled_port_timeout))
1 by brian
clean slate
944
        break;
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
945
          errmsg_printf(ERRMSG_LVL_INFO, _("Retrying bind on TCP/IP port %u"), drizzled_port);
1 by brian
clean slate
946
      this_wait= retry * retry / 3 + 1;
947
      sleep(this_wait);
948
    }
949
    if (ret < 0)
950
    {
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
951
      sql_perror(_("Can't start server: Bind on TCP/IP port"));
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
952
          errmsg_printf(ERRMSG_LVL_ERROR, _("Do you already have another drizzled server running "
574.2.1 by ysano
Rename mysql to drizzle.
953
                        "on port: %d ?"),drizzled_port);
1 by brian
clean slate
954
      unireg_abort(1);
955
    }
956
    if (listen(ip_sock,(int) back_log) < 0)
957
    {
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
958
      sql_perror(_("Can't start server: listen() on TCP/IP port"));
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
959
          errmsg_printf(ERRMSG_LVL_ERROR, _("listen() on TCP/IP failed with error %d"),
429 by Monty Taylor
Removed SOCKET redefines.
960
                      errno);
1 by brian
clean slate
961
      unireg_abort(1);
962
    }
963
  }
964
287.2.1 by Andrew Garner
enable ipv6 in drizzled
965
  freeaddrinfo(ai);
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
966
  return;
1 by brian
clean slate
967
}
968
969
970
971
/** Called when a thread is aborted. */
972
/* ARGSUSED */
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
973
extern "C" void end_thread_signal(int )
1 by brian
clean slate
974
{
520.1.22 by Brian Aker
Second pass of thd cleanup
975
  Session *session=current_session;
976
  if (session)
1 by brian
clean slate
977
  {
978
    statistic_increment(killed_threads, &LOCK_status);
809 by Brian Aker
Refactor of scheduler plugin code to simplify around one structure. Also
979
    (void)thread_scheduler.end_thread(session, 0);		/* purecov: inspected */
1 by brian
clean slate
980
  }
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
981
  return;;				/* purecov: deadcode */
1 by brian
clean slate
982
}
983
984
985
/*
520.1.22 by Brian Aker
Second pass of thd cleanup
986
  Unlink session from global list of available connections and free session
1 by brian
clean slate
987
988
  SYNOPSIS
520.1.22 by Brian Aker
Second pass of thd cleanup
989
    unlink_session()
990
    session		 Thread handler
1 by brian
clean slate
991
992
  NOTES
993
    LOCK_thread_count is locked and left locked
994
*/
995
520.1.22 by Brian Aker
Second pass of thd cleanup
996
void unlink_session(Session *session)
1 by brian
clean slate
997
{
520.1.22 by Brian Aker
Second pass of thd cleanup
998
  session->cleanup();
1 by brian
clean slate
999
910.5.3 by Monty Taylor
Rolled back the atomic2 patch.
1000
  (void) pthread_mutex_lock(&LOCK_thread_count);
854 by Brian Aker
Removed double lock usage.
1001
  connection_count--;
1 by brian
clean slate
1002
  thread_count--;
520.1.22 by Brian Aker
Second pass of thd cleanup
1003
  delete session;
910.5.3 by Monty Taylor
Rolled back the atomic2 patch.
1004
  pthread_mutex_unlock(&LOCK_thread_count);
853 by Brian Aker
Moved locks around (aka... unlink_session now handles its own locking).
1005
  return;
1 by brian
clean slate
1006
}
1007
1008
1009
#ifdef THREAD_SPECIFIC_SIGPIPE
1010
/**
1011
  Aborts a thread nicely. Comes here on SIGPIPE.
1012
1013
  @todo
1014
    One should have to fix that thr_alarm know about this thread too.
1015
*/
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
1016
extern "C" void abort_thread(int )
1 by brian
clean slate
1017
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1018
  Session *session=current_session;
1019
  if (session)
1020
    session->killed= Session::KILL_CONNECTION;
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
1021
  return;;
1 by brian
clean slate
1022
}
1023
#endif
1024
492.3.25 by Lee
Changes to get drizzle building on Solaris 10 (SPARC)
1025
#if defined(BACKTRACE_DEMANGLE)
1 by brian
clean slate
1026
#include <cxxabi.h>
1027
extern "C" char *my_demangle(const char *mangled_name, int *status)
1028
{
1029
  return abi::__cxa_demangle(mangled_name, NULL, NULL, status);
1030
}
1031
#endif
1032
1033
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
1034
extern "C" void handle_segfault(int sig)
1 by brian
clean slate
1035
{
1036
  time_t curr_time;
1037
  struct tm tm;
1038
1039
  /*
1040
    Strictly speaking, one needs a mutex here
1041
    but since we have got SIGSEGV already, things are a mess
1042
    so not having the mutex is not as bad as possibly using a buggy
1043
    mutex - so we keep things simple
1044
  */
1045
  if (segfaulted)
1046
  {
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1047
    fprintf(stderr, _("Fatal " SIGNAL_FMT " while backtracing\n"), sig);
1 by brian
clean slate
1048
    exit(1);
1049
  }
1050
1051
  segfaulted = 1;
1052
685.3.4 by Toru Maesaka
Fixed the issues pointed out by Jay's code review
1053
  curr_time= time(NULL);
1054
  if(curr_time == (time_t)-1)
685.3.2 by Toru Maesaka
Removed my_time() and added error checking
1055
  {
1056
    fprintf(stderr, "Fetal: time() call failed\n");
1057
    exit(1);
1058
  }
1059
1 by brian
clean slate
1060
  localtime_r(&curr_time, &tm);
1061
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
1062
  fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d - drizzled got "
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1063
          SIGNAL_FMT " ;\n"
1064
          "This could be because you hit a bug. It is also possible that "
1065
          "this binary\n or one of the libraries it was linked against is "
1066
          "corrupt, improperly built,\n or misconfigured. This error can "
1067
          "also be caused by malfunctioning hardware.\n",
1 by brian
clean slate
1068
          tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday,
1069
          tm.tm_hour, tm.tm_min, tm.tm_sec,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1070
          sig);
1071
  fprintf(stderr, _("We will try our best to scrape up some info that "
1072
                    "will hopefully help diagnose\n"
1073
                    "the problem, but since we have already crashed, "
1074
                    "something is definitely wrong\nand this may fail.\n\n"));
366 by Patrick Galbraith
Ulong conversion
1075
  fprintf(stderr, "key_buffer_size=%u\n",
1076
          (uint32_t) dflt_key_cache->key_cache_mem_size);
1 by brian
clean slate
1077
  fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
366 by Patrick Galbraith
Ulong conversion
1078
  fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
1 by brian
clean slate
1079
  fprintf(stderr, "max_threads=%u\n", thread_scheduler.max_threads);
1080
  fprintf(stderr, "thread_count=%u\n", thread_count);
1081
  fprintf(stderr, "connection_count=%u\n", connection_count);
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
1082
  fprintf(stderr, _("It is possible that drizzled could use up to \n"
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1083
                    "key_buffer_size + (read_buffer_size + "
622 by Brian Aker
More ulong work.
1084
                    "sort_buffer_size)*max_threads = %"PRIu64" K\n"
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1085
                    "bytes of memory\n"
1086
                    "Hope that's ok; if not, decrease some variables in the "
1087
                    "equation.\n\n"),
622 by Brian Aker
More ulong work.
1088
          (uint64_t)(((uint32_t) dflt_key_cache->key_cache_mem_size +
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1089
                     (global_system_variables.read_buff_size +
1090
                      global_system_variables.sortbuff_size) *
832.2.4 by Mark Atwood
remove max_connections from memory use message
1091
                     thread_scheduler.max_threads) / 1024));
1 by brian
clean slate
1092
1093
#ifdef HAVE_STACKTRACE
520.1.22 by Brian Aker
Second pass of thd cleanup
1094
  Session *session= current_session;
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
1095
1 by brian
clean slate
1096
  if (!(test_flags & TEST_NO_STACKTRACE))
1097
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1098
    fprintf(stderr,"session: 0x%lx\n",(long) session);
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1099
    fprintf(stderr,_("Attempting backtrace. You can use the following "
1100
                     "information to find out\n"
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
1101
                     "where drizzled died. If you see no messages after this, "
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1102
                     "something went\n"
1103
                     "terribly wrong...\n"));
520.1.22 by Brian Aker
Second pass of thd cleanup
1104
    print_stacktrace(session ? (unsigned char*) session->thread_stack : (unsigned char*) 0,
1 by brian
clean slate
1105
                     my_thread_stack_size);
1106
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
1107
  if (session)
1 by brian
clean slate
1108
  {
1109
    const char *kreason= "UNKNOWN";
520.1.22 by Brian Aker
Second pass of thd cleanup
1110
    switch (session->killed) {
520.1.21 by Brian Aker
THD -> Session rename
1111
    case Session::NOT_KILLED:
1 by brian
clean slate
1112
      kreason= "NOT_KILLED";
1113
      break;
520.1.21 by Brian Aker
THD -> Session rename
1114
    case Session::KILL_BAD_DATA:
1 by brian
clean slate
1115
      kreason= "KILL_BAD_DATA";
1116
      break;
520.1.21 by Brian Aker
THD -> Session rename
1117
    case Session::KILL_CONNECTION:
1 by brian
clean slate
1118
      kreason= "KILL_CONNECTION";
1119
      break;
520.1.21 by Brian Aker
THD -> Session rename
1120
    case Session::KILL_QUERY:
1 by brian
clean slate
1121
      kreason= "KILL_QUERY";
1122
      break;
520.1.21 by Brian Aker
THD -> Session rename
1123
    case Session::KILLED_NO_VALUE:
1 by brian
clean slate
1124
      kreason= "KILLED_NO_VALUE";
1125
      break;
1126
    }
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1127
    fprintf(stderr, _("Trying to get some variables.\n"
1128
                      "Some pointers may be invalid and cause the "
1129
                      "dump to abort...\n"));
520.1.22 by Brian Aker
Second pass of thd cleanup
1130
    safe_print_str("session->query", session->query, 1024);
1131
    fprintf(stderr, "session->thread_id=%"PRIu32"\n", (uint32_t) session->thread_id);
1132
    fprintf(stderr, "session->killed=%s\n", kreason);
1 by brian
clean slate
1133
  }
1134
  fflush(stderr);
1135
#endif /* HAVE_STACKTRACE */
1136
1137
#ifdef HAVE_INITGROUPS
1138
  if (calling_initgroups)
672.1.3 by Andrew Hutchings
Minor string fixes (mainly US English spelling and typos)
1139
    fprintf(stderr, _("\nThis crash occurred while the server was calling "
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1140
                      "initgroups(). This is\n"
1141
                      "often due to the use of a drizzled that is statically "
1142
                      "linked against glibc\n"
1143
                      "and configured to use LDAP in /etc/nsswitch.conf. "
1144
                      "You will need to either\n"
1145
                      "upgrade to a version of glibc that does not have this "
1146
                      "problem (2.3.4 or\n"
1147
                      "later when used with nscd), disable LDAP in your "
1148
                      "nsswitch.conf, or use a\n"
1149
                      "drizzled that is not statically linked.\n"));
1 by brian
clean slate
1150
#endif
1151
1152
  if (thd_lib_detected == THD_LIB_LT && !getenv("LD_ASSUME_KERNEL"))
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1153
    fprintf(stderr,
1154
            _("\nYou are running a statically-linked LinuxThreads binary "
1155
              "on an NPTL system.\n"
1156
              "This can result in crashes on some distributions due "
1157
              "to LT/NPTL conflicts.\n"
1158
              "You should either build a dynamically-linked binary, or force "
1159
              "LinuxThreads\n"
1160
              "to be used with the LD_ASSUME_KERNEL environment variable. "
1161
              "Please consult\n"
1162
              "the documentation for your distribution on how to do that.\n"));
236.1.40 by Monty Taylor
A few meaningless changes.
1163
1 by brian
clean slate
1164
  if (locked_in_memory)
1165
  {
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1166
    fprintf(stderr,
1167
            _("\nThe '--memlock' argument, which was enabled, uses system "
1168
              "calls that are\n"
1169
              "unreliable and unstable on some operating systems and "
1170
              "operating-system\n"
1171
              "versions (notably, some versions of Linux).  "
1172
              "This crash could be due to use\n"
1173
              "of those buggy OS calls.  You should consider whether you "
1174
              "really need the\n"
1175
              "'--memlock' parameter and/or consult the OS "
1176
              "distributor about 'mlockall'\n bugs.\n"));
1 by brian
clean slate
1177
  }
1178
1179
#ifdef HAVE_WRITE_CORE
1180
  if (test_flags & TEST_CORE_ON_SIGNAL)
1181
  {
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1182
    fprintf(stderr, _("Writing a core file\n"));
1 by brian
clean slate
1183
    fflush(stderr);
1184
    write_core(sig);
1185
  }
1186
#endif
1187
1188
  exit(1);
1189
}
1190
1191
#ifndef SA_RESETHAND
1192
#define SA_RESETHAND 0
1193
#endif
1194
#ifndef SA_NODEFER
1195
#define SA_NODEFER 0
1196
#endif
1197
1198
static void init_signals(void)
1199
{
1200
  sigset_t set;
1201
  struct sigaction sa;
1202
1203
  if (!(test_flags & TEST_NO_STACKTRACE) || (test_flags & TEST_CORE_ON_SIGNAL))
1204
  {
1205
    sa.sa_flags = SA_RESETHAND | SA_NODEFER;
1206
    sigemptyset(&sa.sa_mask);
1207
    sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
1208
1209
    init_stacktrace();
1210
    sa.sa_handler=handle_segfault;
1211
    sigaction(SIGSEGV, &sa, NULL);
1212
    sigaction(SIGABRT, &sa, NULL);
1213
#ifdef SIGBUS
1214
    sigaction(SIGBUS, &sa, NULL);
1215
#endif
1216
    sigaction(SIGILL, &sa, NULL);
1217
    sigaction(SIGFPE, &sa, NULL);
1218
  }
1219
1220
#ifdef HAVE_GETRLIMIT
1221
  if (test_flags & TEST_CORE_ON_SIGNAL)
1222
  {
1223
    /* Change limits so that we will get a core file */
1224
    STRUCT_RLIMIT rl;
1225
    rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
1226
    if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1227
        errmsg_printf(ERRMSG_LVL_WARN, _("setrlimit could not change the size of core files "
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
1228
                          "to 'infinity';  We may not be able to generate a "
1229
                          "core file on signals"));
1 by brian
clean slate
1230
  }
1231
#endif
1232
  (void) sigemptyset(&set);
1233
  my_sigset(SIGPIPE,SIG_IGN);
1234
  sigaddset(&set,SIGPIPE);
1235
#ifndef IGNORE_SIGHUP_SIGQUIT
1236
  sigaddset(&set,SIGQUIT);
1237
  sigaddset(&set,SIGHUP);
1238
#endif
1239
  sigaddset(&set,SIGTERM);
1240
1241
  /* Fix signals if blocked by parents (can happen on Mac OS X) */
1242
  sigemptyset(&sa.sa_mask);
1243
  sa.sa_flags = 0;
1244
  sa.sa_handler = print_signal_warning;
1245
  sigaction(SIGTERM, &sa, (struct sigaction*) 0);
1246
  sa.sa_flags = 0;
1247
  sa.sa_handler = print_signal_warning;
1248
  sigaction(SIGHUP, &sa, (struct sigaction*) 0);
1249
#ifdef SIGTSTP
1250
  sigaddset(&set,SIGTSTP);
1251
#endif
1252
  if (test_flags & TEST_SIGINT)
1253
  {
1254
    my_sigset(thr_kill_signal, end_thread_signal);
1255
    // May be SIGINT
1256
    sigdelset(&set, thr_kill_signal);
1257
  }
1258
  else
1259
    sigaddset(&set,SIGINT);
1260
  sigprocmask(SIG_SETMASK,&set,NULL);
1261
  pthread_sigmask(SIG_SETMASK,&set,NULL);
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
1262
  return;;
1 by brian
clean slate
1263
}
1264
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
1265
static void check_data_home(const char *)
1 by brian
clean slate
1266
{}
1267
1268
1269
/**
1270
  All global error messages are sent here where the first one is stored
1271
  for the client.
1272
*/
1273
/* ARGSUSED */
482 by Brian Aker
Remove uint.
1274
extern "C" void my_message_sql(uint32_t error, const char *str, myf MyFlags);
1 by brian
clean slate
1275
482 by Brian Aker
Remove uint.
1276
void my_message_sql(uint32_t error, const char *str, myf MyFlags)
1 by brian
clean slate
1277
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1278
  Session *session;
1 by brian
clean slate
1279
  /*
1280
    Put here following assertion when situation with EE_* error codes
1281
    will be fixed
1282
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
1283
  if ((session= current_session))
1 by brian
clean slate
1284
  {
1285
    if (MyFlags & ME_FATALERROR)
520.1.22 by Brian Aker
Second pass of thd cleanup
1286
      session->is_fatal_error= 1;
1 by brian
clean slate
1287
1288
    /*
520.1.21 by Brian Aker
THD -> Session rename
1289
      TODO: There are two exceptions mechanism (Session and sp_rcontext),
1 by brian
clean slate
1290
      this could be improved by having a common stack of handlers.
1291
    */
520.1.22 by Brian Aker
Second pass of thd cleanup
1292
    if (session->handle_error(error, str,
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
1293
                          DRIZZLE_ERROR::WARN_LEVEL_ERROR))
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
1294
      return;;
1 by brian
clean slate
1295
1296
    /*
520.1.22 by Brian Aker
Second pass of thd cleanup
1297
      session->lex->current_select == 0 if lex structure is not inited
1 by brian
clean slate
1298
      (not query command (COM_QUERY))
1299
    */
520.1.22 by Brian Aker
Second pass of thd cleanup
1300
    if (! (session->lex->current_select &&
1301
        session->lex->current_select->no_error && !session->is_fatal_error))
1 by brian
clean slate
1302
    {
520.1.22 by Brian Aker
Second pass of thd cleanup
1303
      if (! session->main_da.is_error())            // Return only first message
1 by brian
clean slate
1304
      {
1305
        if (error == 0)
1306
          error= ER_UNKNOWN_ERROR;
1307
        if (str == NULL)
1308
          str= ER(error);
520.1.22 by Brian Aker
Second pass of thd cleanup
1309
        session->main_da.set_error_status(session, error, str);
1 by brian
clean slate
1310
      }
1311
    }
1312
520.1.22 by Brian Aker
Second pass of thd cleanup
1313
    if (!session->no_warnings_for_error && !session->is_fatal_error)
1 by brian
clean slate
1314
    {
1315
      /*
1316
        Suppress infinite recursion if there a memory allocation error
1317
        inside push_warning.
1318
      */
520.1.22 by Brian Aker
Second pass of thd cleanup
1319
      session->no_warnings_for_error= true;
1320
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
1321
      session->no_warnings_for_error= false;
1 by brian
clean slate
1322
    }
1323
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
1324
  if (!session || MyFlags & ME_NOREFRESH)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1325
    errmsg_printf(ERRMSG_LVL_ERROR, "%s: %s",my_progname,str); /* purecov: inspected */
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
1326
  return;;
1 by brian
clean slate
1327
}
1328
1329
1330
static const char *load_default_groups[]= {
722.1.3 by Monty Taylor
Cleaned up a few build things.
1331
DRIZZLE_CONFIG_NAME,"server", DRIZZLE_BASE_VERSION, 0, 0};
1 by brian
clean slate
1332
1333
SHOW_VAR com_status_vars[]= {
1334
  {"admin_commands",       (char*) offsetof(STATUS_VAR, com_other), SHOW_LONG_STATUS},
895 by Brian Aker
Completion (?) of uint conversion.
1335
  {"assign_to_keycache",   (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ASSIGN_TO_KEYCACHE]), SHOW_LONG_STATUS},
1336
  {"alter_db",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ALTER_DB]), SHOW_LONG_STATUS},
1337
  {"alter_table",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ALTER_TABLE]), SHOW_LONG_STATUS},
1338
  {"analyze",              (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ANALYZE]), SHOW_LONG_STATUS},
1339
  {"begin",                (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_BEGIN]), SHOW_LONG_STATUS},
1340
  {"change_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CHANGE_DB]), SHOW_LONG_STATUS},
1341
  {"check",                (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CHECK]), SHOW_LONG_STATUS},
1342
  {"checksum",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CHECKSUM]), SHOW_LONG_STATUS},
1343
  {"commit",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_COMMIT]), SHOW_LONG_STATUS},
1344
  {"create_db",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CREATE_DB]), SHOW_LONG_STATUS},
1345
  {"create_index",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CREATE_INDEX]), SHOW_LONG_STATUS},
1346
  {"create_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_CREATE_TABLE]), SHOW_LONG_STATUS},
1347
  {"delete",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DELETE]), SHOW_LONG_STATUS},
1348
  {"delete_multi",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DELETE_MULTI]), SHOW_LONG_STATUS},
1349
  {"drop_db",              (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DROP_DB]), SHOW_LONG_STATUS},
1350
  {"drop_index",           (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DROP_INDEX]), SHOW_LONG_STATUS},
1351
  {"drop_table",           (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_DROP_TABLE]), SHOW_LONG_STATUS},
1352
  {"empty_query",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_EMPTY_QUERY]), SHOW_LONG_STATUS},
1353
  {"flush",                (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_FLUSH]), SHOW_LONG_STATUS},
1354
  {"insert",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_INSERT]), SHOW_LONG_STATUS},
1355
  {"insert_select",        (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_INSERT_SELECT]), SHOW_LONG_STATUS},
1356
  {"kill",                 (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_KILL]), SHOW_LONG_STATUS},
1357
  {"load",                 (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_LOAD]), SHOW_LONG_STATUS},
1358
  {"lock_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_LOCK_TABLES]), SHOW_LONG_STATUS},
1359
  {"optimize",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_OPTIMIZE]), SHOW_LONG_STATUS},
1360
  {"release_savepoint",    (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_RELEASE_SAVEPOINT]), SHOW_LONG_STATUS},
1361
  {"rename_table",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_RENAME_TABLE]), SHOW_LONG_STATUS},
1362
  {"repair",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_REPAIR]), SHOW_LONG_STATUS},
1363
  {"replace",              (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_REPLACE]), SHOW_LONG_STATUS},
1364
  {"replace_select",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_REPLACE_SELECT]), SHOW_LONG_STATUS},
1365
  {"rollback",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ROLLBACK]), SHOW_LONG_STATUS},
1366
  {"rollback_to_savepoint",(char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_ROLLBACK_TO_SAVEPOINT]), SHOW_LONG_STATUS},
1367
  {"savepoint",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
1368
  {"select",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SELECT]), SHOW_LONG_STATUS},
1369
  {"set_option",           (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SET_OPTION]), SHOW_LONG_STATUS},
1370
  {"show_create_db",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_CREATE_DB]), SHOW_LONG_STATUS},
1371
  {"show_create_table",    (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_CREATE]), SHOW_LONG_STATUS},
1372
  {"show_databases",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_DATABASES]), SHOW_LONG_STATUS},
1373
  {"show_engine_status",   (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_ENGINE_STATUS]), SHOW_LONG_STATUS},
1374
  {"show_errors",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_ERRORS]), SHOW_LONG_STATUS},
1375
  {"show_fields",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_FIELDS]), SHOW_LONG_STATUS},
1376
  {"show_keys",            (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_KEYS]), SHOW_LONG_STATUS},
1377
  {"show_open_tables",     (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS},
1378
  {"show_plugins",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_PLUGINS]), SHOW_LONG_STATUS},
1379
  {"show_processlist",     (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS},
1380
  {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
1381
  {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
1382
  {"show_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
1383
  {"show_variables",       (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
1384
  {"show_warnings",        (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
1385
  {"truncate",             (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_TRUNCATE]), SHOW_LONG_STATUS},
1386
  {"unlock_tables",        (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_UNLOCK_TABLES]), SHOW_LONG_STATUS},
1387
  {"update",               (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_UPDATE]), SHOW_LONG_STATUS},
1388
  {"update_multi",         (char*) offsetof(STATUS_VAR, com_stat[(uint32_t) SQLCOM_UPDATE_MULTI]), SHOW_LONG_STATUS},
625 by Brian Aker
ulong/64 bit straighten out.
1389
  {NULL, NULL, SHOW_LONGLONG}
1 by brian
clean slate
1390
};
1391
1392
static int init_common_variables(const char *conf_file_name, int argc,
685.3.2 by Toru Maesaka
Removed my_time() and added error checking
1393
                                 char **argv, const char **groups)
1 by brian
clean slate
1394
{
685.3.4 by Toru Maesaka
Fixed the issues pointed out by Jay's code review
1395
  time_t curr_time;
1 by brian
clean slate
1396
  umask(((~my_umask) & 0666));
1397
  my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
1398
  tzset();			// Set tzname
1399
685.3.4 by Toru Maesaka
Fixed the issues pointed out by Jay's code review
1400
  curr_time= time(NULL);
1401
  if (curr_time == (time_t)-1)
685.3.2 by Toru Maesaka
Removed my_time() and added error checking
1402
    return 1;
1403
298 by Brian Aker
ulong conversion.
1404
  max_system_variables.pseudo_thread_id= UINT32_MAX;
685.3.4 by Toru Maesaka
Fixed the issues pointed out by Jay's code review
1405
  server_start_time= flush_status_time= curr_time;
1 by brian
clean slate
1406
1407
  if (init_thread_environment())
1408
    return 1;
574.2.1 by ysano
Rename mysql to drizzle.
1409
  drizzle_init_variables();
1 by brian
clean slate
1410
1411
#ifdef HAVE_TZNAME
1412
  {
1413
    struct tm tm_tmp;
1414
    localtime_r(&server_start_time,&tm_tmp);
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
1415
    strncpy(system_time_zone, tzname[tm_tmp.tm_isdst != 0 ? 1 : 0],
1 by brian
clean slate
1416
            sizeof(system_time_zone)-1);
1417
1418
 }
1419
#endif
1420
  /*
1421
    We set SYSTEM time zone as reasonable default and
1422
    also for failure of my_tz_init() and bootstrap mode.
1423
    If user explicitly set time zone with --default-time-zone
1424
    option we will change this value in my_tz_init().
1425
  */
1426
  global_system_variables.time_zone= my_tz_SYSTEM;
1427
1428
  if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1429
  {
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
1430
    strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1431
      errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1 by brian
clean slate
1432
                      glob_hostname);
907.1.2 by Jay Pipes
Merging in old r902 temporal changes
1433
    strncpy(pidfile_name, STRING_WITH_LEN("drizzle"));
1 by brian
clean slate
1434
  }
1435
  else
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
1436
    strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1437
  strcpy(fn_ext(pidfile_name),".pid");		// Add proper extension
1 by brian
clean slate
1438
1439
  /*
1440
    Add server status variables to the dynamic list of
1441
    status variables that is shown by SHOW STATUS.
1442
    Later, in plugin_init, and mysql_install_plugin
1443
    new entries could be added to that list.
1444
  */
1445
  if (add_status_vars(status_vars))
1446
    return 1; // an error was already reported
1447
1448
  load_defaults(conf_file_name, groups, &argc, &argv);
1449
  defaults_argv=argv;
1450
  defaults_argc=argc;
1451
  get_options(&defaults_argc, defaults_argv);
1452
  set_server_version();
1453
1454
1455
  /* connections and databases needs lots of files */
832.2.10 by Mark Atwood
remove open_files_limit parameter
1456
  (void) my_set_max_open_files(0xFFFFFFFF);
832.2.5 by Mark Atwood
Remove max_connection and max_open_files resizing
1457
909 by Brian Aker
Remove the need for unireg init
1458
  current_pid=(ulong) getpid();		/* Save for later ref */
1459
  init_time();				/* Init time-functions (read zone) */
1460
1 by brian
clean slate
1461
  if (init_errmessage())	/* Read error messages from file */
1462
    return 1;
1463
  if (item_create_init())
1464
    return 1;
1465
  if (set_var_init())
1466
    return 1;
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
1467
  /* Creates static regex matching for temporal values */
1468
  if (! init_temporal_formats())
1469
    return 1;
1 by brian
clean slate
1470
  /*
1471
    Process a comma-separated character set list and choose
1472
    the first available character set. This is mostly for
1473
    test purposes, to be able to start "mysqld" even if
1474
    the requested character set is not available (see bug#18743).
1475
  */
1476
  for (;;)
1477
  {
1478
    char *next_character_set_name= strchr(default_character_set_name, ',');
1479
    if (next_character_set_name)
1480
      *next_character_set_name++= '\0';
1481
    if (!(default_charset_info=
862 by Brian Aker
Remove charset directory code.
1482
          get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
1 by brian
clean slate
1483
    {
1484
      if (next_character_set_name)
1485
      {
1486
        default_character_set_name= next_character_set_name;
1487
        default_collation_name= 0;          // Ignore collation
1488
      }
1489
      else
1490
        return 1;                           // Eof of the list
1491
    }
1492
    else
1493
      break;
1494
  }
1495
1496
  if (default_collation_name)
1497
  {
862 by Brian Aker
Remove charset directory code.
1498
    const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1 by brian
clean slate
1499
    if (!default_collation)
1500
    {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1501
          errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1 by brian
clean slate
1502
      return 1;
1503
    }
1504
    if (!my_charset_same(default_charset_info, default_collation))
1505
    {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1506
          errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
1507
                      default_collation_name,
1508
                      default_charset_info->csname);
1 by brian
clean slate
1509
      return 1;
1510
    }
1511
    default_charset_info= default_collation;
1512
  }
1513
  /* Set collactions that depends on the default collation */
1514
  global_system_variables.collation_server=	 default_charset_info;
1515
  global_system_variables.collation_database=	 default_charset_info;
1516
1517
  global_system_variables.optimizer_use_mrr= 1;
1518
  global_system_variables.optimizer_switch= 0;
1519
236.1.40 by Monty Taylor
A few meaningless changes.
1520
  if (!(character_set_filesystem=
862 by Brian Aker
Remove charset directory code.
1521
        get_charset_by_csname(character_set_filesystem_name, MY_CS_PRIMARY)))
1 by brian
clean slate
1522
    return 1;
1523
  global_system_variables.character_set_filesystem= character_set_filesystem;
1524
1525
  if (!(my_default_lc_time_names=
1526
        my_locale_by_name(lc_time_names_name)))
1527
  {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1528
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown locale: '%s'"), lc_time_names_name);
1 by brian
clean slate
1529
    return 1;
1530
  }
1531
  global_system_variables.lc_time_names= my_default_lc_time_names;
236.1.40 by Monty Taylor
A few meaningless changes.
1532
1 by brian
clean slate
1533
  sys_init_connect.value_length= 0;
1534
  if ((sys_init_connect.value= opt_init_connect))
1535
    sys_init_connect.value_length= strlen(opt_init_connect);
1536
  else
656.1.19 by Monty Taylor
Removed my_strdup from drizzled/
1537
    sys_init_connect.value=strdup("");
656.1.52 by Monty Taylor
Added more return value checks.
1538
  if (sys_init_connect.value == NULL)
1539
    return 1;
1 by brian
clean slate
1540
1541
  if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
1542
    return 1;
1543
1544
  /* Reset table_alias_charset, now that lower_case_table_names is set. */
224.2.2 by Brian Aker
Second pass cleanup around filesystem type.
1545
  lower_case_table_names= 1; /* This we need to look at */
224.2.1 by Brian Aker
First pass for table name issue across platforms.
1546
  table_alias_charset= files_charset_info;
1 by brian
clean slate
1547
1548
  return 0;
1549
}
1550
1551
1552
static int init_thread_environment()
1553
{
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
1554
  (void) pthread_mutex_init(&LOCK_drizzleclient_create_db,MY_MUTEX_INIT_SLOW);
1 by brian
clean slate
1555
  (void) pthread_mutex_init(&LOCK_lock_db,MY_MUTEX_INIT_SLOW);
1556
  (void) pthread_mutex_init(&LOCK_open, NULL);
1557
  (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
1558
  (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST);
1559
  (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
658 by Brian Aker
Part removal of my_pthread.h
1560
  (void) pthread_rwlock_init(&LOCK_system_variables_hash, NULL);
1 by brian
clean slate
1561
  (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST);
658 by Brian Aker
Part removal of my_pthread.h
1562
  (void) pthread_rwlock_init(&LOCK_sys_init_connect, NULL);
1 by brian
clean slate
1563
  (void) pthread_cond_init(&COND_thread_count,NULL);
1564
  (void) pthread_cond_init(&COND_refresh,NULL);
1565
  (void) pthread_cond_init(&COND_global_read_lock,NULL);
1566
1567
  /* Parameter for threads created for connections */
1568
  (void) pthread_attr_init(&connection_attrib);
1569
  (void) pthread_attr_setdetachstate(&connection_attrib,
1570
				     PTHREAD_CREATE_DETACHED);
1571
  pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM);
6 by Brian Aker
Second pass on pthread cleanup
1572
  {
1573
    struct sched_param tmp_sched_param;
1574
1575
    memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
1576
    tmp_sched_param.sched_priority= WAIT_PRIOR;
1577
    (void)pthread_attr_setschedparam(&connection_attrib, &tmp_sched_param);
1578
  }
1 by brian
clean slate
1579
520.1.21 by Brian Aker
THD -> Session rename
1580
  if (pthread_key_create(&THR_Session,NULL) ||
670.2.1 by Monty Taylor
Moved pthread keys
1581
      pthread_key_create(&THR_Mem_root,NULL))
1 by brian
clean slate
1582
  {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1583
      errmsg_printf(ERRMSG_LVL_ERROR, _("Can't create thread-keys"));
1 by brian
clean slate
1584
    return 1;
1585
  }
1586
  return 0;
1587
}
1588
1589
1590
static int init_server_components()
1591
{
1592
  /*
1593
    We need to call each of these following functions to ensure that
1594
    all things are initialized so that unireg_abort() doesn't fail
1595
  */
1596
  if (table_cache_init() | table_def_init())
1597
    unireg_abort(1);
1598
892.2.3 by Monty Taylor
Fixed fixes.
1599
  drizzleclient_randominit(&sql_rand,
1600
                           (uint64_t) server_start_time,
1601
                           (uint64_t) server_start_time/2);
1 by brian
clean slate
1602
  setup_fpu();
1603
  init_thr_lock();
1604
1605
  /* Setup logs */
1606
1607
  if (xid_cache_init())
1608
  {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1609
      errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory"));
1 by brian
clean slate
1610
    unireg_abort(1);
1611
  }
1612
1613
  /* call ha_init_key_cache() on all key caches to init them */
1614
  process_key_caches(&ha_init_key_cache);
1615
1616
  /* Allow storage engine to give real error messages */
1617
  if (ha_init_errors())
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
1618
    return(1);
1 by brian
clean slate
1619
1620
  if (plugin_init(&defaults_argc, defaults_argv,
1621
                  (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
1622
                  (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
1623
  {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1624
      errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins."));
1 by brian
clean slate
1625
    unireg_abort(1);
1626
  }
1627
1628
  if (opt_help)
1629
    unireg_abort(0);
1630
1631
  /* we do want to exit if there are any other unknown options */
1632
  if (defaults_argc > 1)
1633
  {
1634
    int ho_error;
1635
    char **tmp_argv= defaults_argv;
1636
    struct my_option no_opts[]=
1637
    {
1638
      {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1639
    };
1640
    /*
1641
      We need to eat any 'loose' arguments first before we conclude
1642
      that there are unprocessed options.
1643
      But we need to preserve defaults_argv pointer intact for
1644
      free_defaults() to work. Thus we use a copy here.
1645
    */
1646
    my_getopt_skip_unknown= 0;
1647
1648
    if ((ho_error= handle_options(&defaults_argc, &tmp_argv, no_opts,
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
1649
                                  drizzled_get_one_option)))
1 by brian
clean slate
1650
      unireg_abort(ho_error);
1651
1652
    if (defaults_argc)
1653
    {
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
1654
      fprintf(stderr,
1655
              _("%s: Too many arguments (first extra is '%s').\n"
1656
                "Use --verbose --help to get a list of available options\n"),
1 by brian
clean slate
1657
              my_progname, *tmp_argv);
1658
      unireg_abort(1);
1659
    }
1660
  }
1661
1662
  /* We have to initialize the storage engines before CSV logging */
1663
  if (ha_init())
1664
  {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1665
      errmsg_printf(ERRMSG_LVL_ERROR, _("Can't init databases"));
1 by brian
clean slate
1666
    unireg_abort(1);
1667
  }
1668
1669
  /*
1670
    Check that the default storage engine is actually available.
1671
  */
1672
  if (default_storage_engine_str)
1673
  {
1674
    LEX_STRING name= { default_storage_engine_str,
1675
                       strlen(default_storage_engine_str) };
1676
    plugin_ref plugin;
1677
    handlerton *hton;
236.1.40 by Monty Taylor
A few meaningless changes.
1678
1 by brian
clean slate
1679
    if ((plugin= ha_resolve_by_name(0, &name)))
236.1.44 by Monty Taylor
Added en_US translation file.
1680
    {
202.3.11 by Monty Taylor
Ding dong. errmsg.sys is dead.
1681
      hton= plugin_data(plugin,handlerton *);
236.1.44 by Monty Taylor
Added en_US translation file.
1682
    }
1 by brian
clean slate
1683
    else
1684
    {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1685
          errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown/unsupported table type: %s"),
1 by brian
clean slate
1686
                      default_storage_engine_str);
1687
      unireg_abort(1);
1688
    }
1689
    if (!ha_storage_engine_is_enabled(hton))
1690
    {
907.3.5 by Monty Taylor
Fixed new 64-bit caused solaris warnings.
1691
      errmsg_printf(ERRMSG_LVL_ERROR, _("Default storage engine (%s) is not available"),
1692
                    default_storage_engine_str);
228 by Brian Aker
First pass on socket cleanup.
1693
      unireg_abort(1);
907.3.5 by Monty Taylor
Fixed new 64-bit caused solaris warnings.
1694
      //assert(global_system_variables.table_plugin);
1 by brian
clean slate
1695
    }
1696
    else
1697
    {
1698
      /*
236.1.40 by Monty Taylor
A few meaningless changes.
1699
        Need to unlock as global_system_variables.table_plugin
1 by brian
clean slate
1700
        was acquired during plugin_init()
1701
      */
1702
      plugin_unlock(0, global_system_variables.table_plugin);
1703
      global_system_variables.table_plugin= plugin;
1704
    }
1705
  }
1706
1707
  if (ha_recover(0))
1708
  {
1709
    unireg_abort(1);
1710
  }
1711
1712
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
1713
  if (locked_in_memory && !getuid())
1714
  {
1715
    if (setreuid((uid_t)-1, 0) == -1)
1716
    {                        // this should never happen
1717
      sql_perror("setreuid");
1718
      unireg_abort(1);
1719
    }
1720
    if (mlockall(MCL_CURRENT))
1721
    {
1722
      if (global_system_variables.log_warnings)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1723
            errmsg_printf(ERRMSG_LVL_WARN, _("Failed to lock memory. Errno: %d\n"),errno);
1 by brian
clean slate
1724
      locked_in_memory= 0;
1725
    }
1726
    if (user_info)
574.2.1 by ysano
Rename mysql to drizzle.
1727
      set_user(drizzled_user, user_info);
1 by brian
clean slate
1728
  }
1729
  else
1730
#endif
1731
    locked_in_memory=0;
1732
1733
  init_update_queries();
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
1734
  return(0);
1 by brian
clean slate
1735
}
1736
1737
1738
int main(int argc, char **argv)
1739
{
236.1.60 by Monty Taylor
Another stab at protecting NLS stuff.
1740
#if defined(ENABLE_NLS)
1741
# if defined(HAVE_LOCALE_H)
202.3.8 by Monty Taylor
Actually turn gettext on...
1742
  setlocale(LC_ALL, "");
236.1.60 by Monty Taylor
Another stab at protecting NLS stuff.
1743
# endif
202.3.8 by Monty Taylor
Actually turn gettext on...
1744
  bindtextdomain("drizzle", LOCALEDIR);
1745
  textdomain("drizzle");
236.1.60 by Monty Taylor
Another stab at protecting NLS stuff.
1746
#endif
202.3.8 by Monty Taylor
Actually turn gettext on...
1747
1 by brian
clean slate
1748
  MY_INIT(argv[0]);		// init my_sys library & pthreads
1749
  /* nothing should come before this line ^^^ */
1750
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
1751
  /* Set signal used to kill Drizzle */
1 by brian
clean slate
1752
#if defined(SIGUSR2)
1753
  thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
1754
#else
1755
  thr_kill_signal= SIGINT;
1756
#endif
1757
1758
#ifdef _CUSTOMSTARTUPCONFIG_
1759
  if (_cust_check_startup())
1760
  {
1761
    / * _cust_check_startup will report startup failure error * /
1762
    exit(1);
1763
  }
1764
#endif
1765
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
1766
  if (init_common_variables(DRIZZLE_CONFIG_NAME,
1 by brian
clean slate
1767
			    argc, argv, load_default_groups))
1768
    unireg_abort(1);				// Will do exit
1769
1770
  init_signals();
5 by Brian Aker
Removed my_pthread_setprio()
1771
900 by Brian Aker
Creating signal handler plugin.
1772
  pthread_attr_setstacksize(&connection_attrib, my_thread_stack_size);
161 by Brian Aker
I had removed most of the pthread_setschedparam() calls a bit ago. This
1773
1 by brian
clean slate
1774
#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
1775
  {
1776
    /* Retrieve used stack size;  Needed for checking stack overflows */
1777
    size_t stack_size= 0;
1778
    pthread_attr_getstacksize(&connection_attrib, &stack_size);
1779
    /* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
1780
    if (stack_size && stack_size < my_thread_stack_size)
1781
    {
1782
      if (global_system_variables.log_warnings)
298 by Brian Aker
ulong conversion.
1783
      {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1784
            errmsg_printf(ERRMSG_LVL_WARN, _("Asked for %"PRIu64" thread stack, "
629.2.7 by Monty Taylor
Fixed a couple of memory buffer size issues.
1785
                            "but got %"PRIu64),
1786
                          (uint64_t)my_thread_stack_size,
1787
                          (uint64_t)stack_size);
298 by Brian Aker
ulong conversion.
1788
      }
1 by brian
clean slate
1789
      my_thread_stack_size= stack_size;
1790
    }
1791
  }
1792
#endif
1793
1794
  select_thread=pthread_self();
1795
  select_thread_in_use=1;
1796
1797
  /*
1798
    We have enough space for fiddling with the argv, continue
1799
  */
575.4.1 by ysano
Rename mysql to drizzle.
1800
  check_data_home(drizzle_real_data_home);
575.4.6 by Monty Taylor
Removed my_getwd.
1801
  if (chdir(drizzle_real_data_home) && !opt_help)
1 by brian
clean slate
1802
    unireg_abort(1);				/* purecov: inspected */
575.4.3 by ysano
Rename mysql to drizzle.
1803
  drizzle_data_home= drizzle_data_home_buff;
575.4.1 by ysano
Rename mysql to drizzle.
1804
  drizzle_data_home[0]=FN_CURLIB;		// all paths are relative from here
1805
  drizzle_data_home[1]=0;
1806
  drizzle_data_home_len= 2;
1 by brian
clean slate
1807
574.2.1 by ysano
Rename mysql to drizzle.
1808
  if ((user_info= check_user(drizzled_user)))
1 by brian
clean slate
1809
  {
1810
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
1811
    if (locked_in_memory) // getuid() == 0 here
1812
      set_effective_user(user_info);
1813
    else
1814
#endif
574.2.1 by ysano
Rename mysql to drizzle.
1815
      set_user(drizzled_user, user_info);
1 by brian
clean slate
1816
  }
1817
798.2.28 by Brian Aker
More pulling of code... master_pos function code removed.
1818
  if (server_id == 0)
1 by brian
clean slate
1819
  {
1820
    server_id= 1;
1821
  }
1822
1823
  if (init_server_components())
1824
    unireg_abort(1);
1825
1826
  network_init();
1827
722.2.12 by Monty Taylor
Removed assert(0); Added function ptr in libdrizzle.
1828
  safe_read_error_hook= safe_read_error_impl; 
1 by brian
clean slate
1829
1830
  /*
1831
    init signals & alarm
1832
    After this we can't quit by a simple unireg_abort
1833
  */
1834
  error_handler_hook= my_message_sql;
1835
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
1836
  if (drizzle_rm_tmp_tables() || my_tz_init((Session *)0, default_tz_name))
1 by brian
clean slate
1837
  {
909 by Brian Aker
Remove the need for unireg init
1838
    abort_loop= true;
1 by brian
clean slate
1839
    select_thread_in_use=0;
900 by Brian Aker
Creating signal handler plugin.
1840
    (void) pthread_kill(signal_thread, SIGTERM);
1 by brian
clean slate
1841
914.2.1 by Brian Aker
Cleanup pid handler.
1842
    (void) unlink(pidfile_name);	// Not needed anymore
1 by brian
clean slate
1843
1844
    exit(1);
1845
  }
1846
1847
  init_status_vars();
1848
  /*
1849
    init_slave() must be called after the thread keys are created.
1850
    Some parts of the code (e.g. SHOW STATUS LIKE 'slave_running' and other
1851
    places) assume that active_mi != 0, so let's fail if it's 0 (out of
1852
    memory); a message has already been printed.
1853
  */
1854
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1855
  errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)),my_progname,server_version,
574.2.1 by ysano
Rename mysql to drizzle.
1856
                        "", drizzled_port, COMPILATION_COMMENT);
11 by Brian Aker
Removing old UNIX socket bits
1857
1858
1859
  handle_connections_sockets();
1 by brian
clean slate
1860
  /* (void) pthread_attr_destroy(&connection_attrib); */
236.1.40 by Monty Taylor
A few meaningless changes.
1861
1 by brian
clean slate
1862
1863
  (void) pthread_mutex_lock(&LOCK_thread_count);
1864
  select_thread_in_use=0;			// For close_connections
1865
  (void) pthread_mutex_unlock(&LOCK_thread_count);
1866
  (void) pthread_cond_broadcast(&COND_thread_count);
1867
1868
  /* Wait until cleanup is done */
1869
  (void) pthread_mutex_lock(&LOCK_thread_count);
1870
  while (!ready_to_exit)
1871
    pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
1872
  (void) pthread_mutex_unlock(&LOCK_thread_count);
1873
1874
  clean_up(1);
907.3.5 by Monty Taylor
Fixed new 64-bit caused solaris warnings.
1875
  clean_up_mutexes();
1876
  my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
1877
  return 0;
1 by brian
clean slate
1878
}
1879
1880
1881
/**
1882
  Create new thread to handle incoming connection.
1883
1884
    This function will create new thread to handle the incoming
1885
    connection.  If there are idle cached threads one will be used.
520.1.22 by Brian Aker
Second pass of thd cleanup
1886
    'session' will be pushed into 'threads'.
1 by brian
clean slate
1887
1888
    In single-threaded mode (\#define ONE_THREAD) connection will be
1889
    handled inside this function.
1890
520.1.22 by Brian Aker
Second pass of thd cleanup
1891
  @param[in,out] session    Thread handle of future thread.
1 by brian
clean slate
1892
*/
1893
520.1.22 by Brian Aker
Second pass of thd cleanup
1894
static void create_new_thread(Session *session)
1 by brian
clean slate
1895
{
910.5.3 by Monty Taylor
Rolled back the atomic2 patch.
1896
  pthread_mutex_lock(&LOCK_thread_count);
1 by brian
clean slate
1897
1898
  ++connection_count;
1899
1900
  if (connection_count > max_used_connections)
1901
    max_used_connections= connection_count;
1902
1903
  /*
520.1.22 by Brian Aker
Second pass of thd cleanup
1904
    The initialization of thread_id is done in create_embedded_session() for
1 by brian
clean slate
1905
    the embedded library.
1906
    TODO: refactor this to avoid code duplication there
1907
  */
910.5.3 by Monty Taylor
Rolled back the atomic2 patch.
1908
  session->thread_id= session->variables.pseudo_thread_id= thread_id++;
1 by brian
clean slate
1909
1910
  thread_count++;
1911
859 by Brian Aker
Fix for error when thread/whatever can not be created on connection.
1912
  /* 
1913
    If we error on creation we drop the connection and delete the session.
1914
  */
1915
  if (thread_scheduler.add_connection(session))
1916
  {
1917
    char error_message_buff[DRIZZLE_ERRMSG_SIZE];
1918
1919
    session->killed= Session::KILL_CONNECTION;                        // Safety
1920
1921
    statistic_increment(aborted_connects, &LOCK_status);
1922
1923
    /* Can't use my_error() since store_globals has not been called. */
1924
    snprintf(error_message_buff, sizeof(error_message_buff), ER(ER_CANT_CREATE_THREAD), 1); /* TODO replace will better error message */
1925
    net_send_error(session, ER_CANT_CREATE_THREAD, error_message_buff);
910.5.3 by Monty Taylor
Rolled back the atomic2 patch.
1926
    (void) pthread_mutex_lock(&LOCK_thread_count);
859 by Brian Aker
Fix for error when thread/whatever can not be created on connection.
1927
    --connection_count;
1928
    session->close_connection(0, 0);
1929
    delete session;
910.5.3 by Monty Taylor
Rolled back the atomic2 patch.
1930
    (void) pthread_mutex_unlock(&LOCK_thread_count);
859 by Brian Aker
Fix for error when thread/whatever can not be created on connection.
1931
  }
1 by brian
clean slate
1932
}
1933
1934
1935
	/* Handle new connections and spawn new process to handle them */
1936
11 by Brian Aker
Removing old UNIX socket bits
1937
void handle_connections_sockets()
1 by brian
clean slate
1938
{
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
1939
  int x;
268 by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef
1940
  int sock,new_sock;
482 by Brian Aker
Remove uint.
1941
  uint32_t error_count=0;
520.1.22 by Brian Aker
Second pass of thd cleanup
1942
  Session *session;
1 by brian
clean slate
1943
  struct sockaddr_storage cAddr;
1944
1945
  while (!abort_loop)
1946
  {
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
1947
    int number_of;
1948
1949
    if ((number_of= poll(fds, pollfd_count, -1)) == -1)
1 by brian
clean slate
1950
    {
429 by Monty Taylor
Removed SOCKET redefines.
1951
      if (errno != EINTR)
1 by brian
clean slate
1952
      {
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
1953
        if (!select_errors++ && !abort_loop)	/* purecov: inspected */
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1954
                errmsg_printf(ERRMSG_LVL_ERROR, _("drizzled: Got error %d from select"),
429 by Monty Taylor
Removed SOCKET redefines.
1955
                          errno); /* purecov: inspected */
1 by brian
clean slate
1956
      }
1957
      continue;
1958
    }
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
1959
    if (number_of == 0)
1960
      continue;
236.1.40 by Monty Taylor
A few meaningless changes.
1961
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
1962
#ifdef FIXME_IF_WE_WERE_KEEPING_THIS
1963
    assert(number_of > 1); /* Not handling this at the moment */
1964
#endif
1965
1 by brian
clean slate
1966
    if (abort_loop)
1967
    {
1968
      break;
1969
    }
1970
229 by Brian Aker
This is the second pass through the code. Mainly to get the socket loop
1971
    for (x= 0, sock= -1; x < pollfd_count; x++)
1972
    {
1973
      if (fds[x].revents == POLLIN)
1974
      {
1975
        sock= fds[x].fd;
1976
        break;
1977
      }
1978
    }
1979
    assert(sock != -1);
1 by brian
clean slate
1980
482 by Brian Aker
Remove uint.
1981
    for (uint32_t retry=0; retry < MAX_ACCEPT_RETRY; retry++)
1 by brian
clean slate
1982
    {
473 by Monty Taylor
Removed size_socket. For crying out loud.
1983
      SOCKET_SIZE_TYPE length= sizeof(struct sockaddr_storage);
1 by brian
clean slate
1984
      new_sock= accept(sock, (struct sockaddr *)(&cAddr),
1985
                       &length);
429 by Monty Taylor
Removed SOCKET redefines.
1986
      if (new_sock != -1 || (errno != EINTR && errno != EAGAIN))
693 by Brian Aker
Cleaning up session class.
1987
        break;
1 by brian
clean slate
1988
    }
228 by Brian Aker
First pass on socket cleanup.
1989
1990
268 by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef
1991
    if (new_sock == -1)
1 by brian
clean slate
1992
    {
1993
      if ((error_count++ & 255) == 0)		// This can happen often
693 by Brian Aker
Cleaning up session class.
1994
        sql_perror("Error in accept");
429 by Monty Taylor
Removed SOCKET redefines.
1995
      if (errno == ENFILE || errno == EMFILE)
693 by Brian Aker
Cleaning up session class.
1996
        sleep(1);				// Give other threads some time
1 by brian
clean slate
1997
      continue;
1998
    }
1999
2000
    {
473 by Monty Taylor
Removed size_socket. For crying out loud.
2001
      SOCKET_SIZE_TYPE dummyLen;
1 by brian
clean slate
2002
      struct sockaddr_storage dummy;
2003
      dummyLen = sizeof(dummy);
236.1.40 by Monty Taylor
A few meaningless changes.
2004
      if (  getsockname(new_sock,(struct sockaddr *)&dummy,
292 by Brian Aker
Merge
2005
                        (socklen_t *)&dummyLen) < 0  )
1 by brian
clean slate
2006
      {
292 by Brian Aker
Merge
2007
        sql_perror("Error on new connection socket");
2008
        (void) shutdown(new_sock, SHUT_RDWR);
293 by Brian Aker
Merge + closesocket() fix
2009
        (void) close(new_sock);
292 by Brian Aker
Merge
2010
        continue;
287.1.1 by Andrew Garner
extended check for bad connections after accept
2011
      }
292 by Brian Aker
Merge
2012
      dummyLen = sizeof(dummy);
2013
      if ( getpeername(new_sock, (struct sockaddr *)&dummy,
2014
                       (socklen_t *)&dummyLen) < 0)
287.1.1 by Andrew Garner
extended check for bad connections after accept
2015
      {
292 by Brian Aker
Merge
2016
        sql_perror("Error on new connection socket");
2017
        (void) shutdown(new_sock, SHUT_RDWR);
293 by Brian Aker
Merge + closesocket() fix
2018
        (void) close(new_sock);
287.1.1 by Andrew Garner
extended check for bad connections after accept
2019
         continue;
1 by brian
clean slate
2020
      }
2021
    }
2022
2023
    /*
2024
    ** Don't allow too many connections
2025
    */
2026
520.1.22 by Brian Aker
Second pass of thd cleanup
2027
    if (!(session= new Session))
1 by brian
clean slate
2028
    {
2029
      (void) shutdown(new_sock, SHUT_RDWR);
398.1.10 by Monty Taylor
Actually removed VOID() this time.
2030
      close(new_sock);
1 by brian
clean slate
2031
      continue;
2032
    }
840.1.20 by Monty Taylor
Renamed non-prefixed things from libdrizzleclient to drizzleclient.
2033
    if (drizzleclient_net_init_sock(&session->net, new_sock, sock == 0))
1 by brian
clean slate
2034
    {
520.1.22 by Brian Aker
Second pass of thd cleanup
2035
      delete session;
1 by brian
clean slate
2036
      continue;
2037
    }
2038
520.1.22 by Brian Aker
Second pass of thd cleanup
2039
    create_new_thread(session);
1 by brian
clean slate
2040
  }
2041
}
2042
2043
2044
/****************************************************************************
2045
  Handle start options
2046
******************************************************************************/
2047
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
2048
enum options_drizzled
1 by brian
clean slate
2049
{
867 by Brian Aker
Remove dead options.
2050
  OPT_ISAM_LOG=256,
2051
  OPT_SKIP_NEW,
2052
  OPT_SOCKET,
236.1.40 by Monty Taylor
A few meaningless changes.
2053
  OPT_BIN_LOG,
1 by brian
clean slate
2054
  OPT_BIND_ADDRESS,            OPT_PID_FILE,
245 by Brian Aker
Removed dead variables.
2055
  OPT_SKIP_PRIOR,
1 by brian
clean slate
2056
  OPT_FLUSH,                   OPT_SAFE,
867 by Brian Aker
Remove dead options.
2057
  OPT_STORAGE_ENGINE,          
2058
  OPT_INIT_FILE,
438.1.1 by Brian Aker
First pass of removing historical logging.
2059
  OPT_DELAY_KEY_WRITE_ALL,
856 by Brian Aker
Remove dead code around charset variable/directory.
2060
  OPT_DELAY_KEY_WRITE,
1 by brian
clean slate
2061
  OPT_WANT_CORE,
867 by Brian Aker
Remove dead options.
2062
  OPT_MEMLOCK,
2063
  OPT_MYISAM_RECOVER,
614 by Brian Aker
Remove filtering (wrong layer, belongs in plugin).
2064
  OPT_SERVER_ID,
867 by Brian Aker
Remove dead options.
2065
  OPT_TC_HEURISTIC_RECOVER,
236.1.40 by Monty Taylor
A few meaningless changes.
2066
  OPT_ENGINE_CONDITION_PUSHDOWN,
1 by brian
clean slate
2067
  OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_COMPLETION_TYPE,
2068
  OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS,
867 by Brian Aker
Remove dead options.
2069
  OPT_DO_PSTACK,
2070
  OPT_LOCAL_INFILE,
798.2.18 by Brian Aker
Remove dead COM for BINLOG/REGISTER.
2071
  OPT_BACK_LOG,
1 by brian
clean slate
2072
  OPT_CONNECT_TIMEOUT,
160.1.2 by mark
remove FTPARSER and last remains of full text search
2073
  OPT_FLUSH_TIME,
1 by brian
clean slate
2074
  OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE,
2075
  OPT_KEY_BUFFER_SIZE, OPT_KEY_CACHE_BLOCK_SIZE,
2076
  OPT_KEY_CACHE_DIVISION_LIMIT, OPT_KEY_CACHE_AGE_THRESHOLD,
2077
  OPT_LONG_QUERY_TIME,
2078
  OPT_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET,
832.2.8 by Mark Atwood
remove sysvar max_connections
2079
  OPT_MAX_CONNECT_ERRORS,
1 by brian
clean slate
2080
  OPT_MAX_HEP_TABLE_SIZE,
245 by Brian Aker
Removed dead variables.
2081
  OPT_MAX_JOIN_SIZE,
1 by brian
clean slate
2082
  OPT_MAX_RELAY_LOG_SIZE, OPT_MAX_SORT_LENGTH,
2083
  OPT_MAX_SEEKS_FOR_KEY, OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS,
2084
  OPT_MAX_LENGTH_FOR_SORT_DATA,
2085
  OPT_MAX_WRITE_LOCK_COUNT, OPT_BULK_INSERT_BUFFER_SIZE,
2086
  OPT_MAX_ERROR_COUNT, OPT_MULTI_RANGE_COUNT, OPT_MYISAM_DATA_POINTER_SIZE,
2087
  OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
2088
  OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE,
2089
  OPT_MYISAM_USE_MMAP, OPT_MYISAM_REPAIR_THREADS,
2090
  OPT_MYISAM_STATS_METHOD,
2091
  OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT,
2092
  OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT,
2093
  OPT_PRELOAD_BUFFER_SIZE,
245 by Brian Aker
Removed dead variables.
2094
  OPT_RECORD_BUFFER,
867 by Brian Aker
Remove dead options.
2095
  OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT,
2096
  OPT_DEBUGGING,
1 by brian
clean slate
2097
  OPT_SORT_BUFFER, OPT_TABLE_OPEN_CACHE, OPT_TABLE_DEF_CACHE,
2098
  OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK,
2099
  OPT_WAIT_TIMEOUT,
80.2.1 by mark
remove handling of suspicious UDFs
2100
  OPT_RANGE_ALLOC_BLOCK_SIZE,
1 by brian
clean slate
2101
  OPT_QUERY_ALLOC_BLOCK_SIZE, OPT_QUERY_PREALLOC_SIZE,
2102
  OPT_TRANS_ALLOC_BLOCK_SIZE, OPT_TRANS_PREALLOC_SIZE,
2103
  OPT_OLD_ALTER_TABLE,
2104
  OPT_GROUP_CONCAT_MAX_LEN,
2105
  OPT_DEFAULT_COLLATION,
2106
  OPT_CHARACTER_SET_FILESYSTEM,
2107
  OPT_LC_TIME_NAMES,
2108
  OPT_INIT_CONNECT,
2109
  OPT_DEFAULT_TIME_ZONE,
2110
  OPT_SYSDATE_IS_NOW,
2111
  OPT_OPTIMIZER_SEARCH_DEPTH,
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
2112
  OPT_SCHEDULER,
1 by brian
clean slate
2113
  OPT_OPTIMIZER_PRUNE_LEVEL,
2114
  OPT_UPDATABLE_VIEWS_WITH_LIMIT,
2115
  OPT_AUTO_INCREMENT, OPT_AUTO_INCREMENT_OFFSET,
2116
  OPT_ENABLE_LARGE_PAGES,
2117
  OPT_TIMED_MUTEXES,
2118
  OPT_TABLE_LOCK_WAIT_TIMEOUT,
2119
  OPT_PLUGIN_LOAD,
2120
  OPT_PLUGIN_DIR,
2121
  OPT_PORT_OPEN_TIMEOUT,
2122
  OPT_KEEP_FILES_ON_CREATE,
2123
  OPT_SECURE_FILE_PRIV,
2124
  OPT_MIN_EXAMINED_ROW_LIMIT,
867 by Brian Aker
Remove dead options.
2125
  OPT_OLD_MODE
1 by brian
clean slate
2126
};
2127
2128
366 by Patrick Galbraith
Ulong conversion
2129
#define LONG_TIMEOUT ((uint32_t) 3600L*24L*365L)
1 by brian
clean slate
2130
2131
struct my_option my_long_options[] =
2132
{
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2133
  {"help", '?', N_("Display this help and exit."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2134
   (char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1 by brian
clean slate
2135
   0, 0},
2136
  {"auto-increment-increment", OPT_AUTO_INCREMENT,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2137
   N_("Auto-increment columns are incremented by this"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2138
   (char**) &global_system_variables.auto_increment_increment,
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
2139
   (char**) &max_system_variables.auto_increment_increment, 0, GET_ULL,
2140
   OPT_ARG, 1, 1, UINT64_MAX, 0, 1, 0 },
1 by brian
clean slate
2141
  {"auto-increment-offset", OPT_AUTO_INCREMENT_OFFSET,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2142
   N_("Offset added to Auto-increment columns. Used when "
2143
      "auto-increment-increment != 1"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2144
   (char**) &global_system_variables.auto_increment_offset,
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
2145
   (char**) &max_system_variables.auto_increment_offset, 0, GET_ULL, OPT_ARG,
2146
   1, 1, UINT64_MAX, 0, 1, 0 },
1 by brian
clean slate
2147
  {"basedir", 'b',
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2148
   N_("Path to installation directory. All paths are usually resolved "
2149
      "relative to this."),
574.2.1 by ysano
Rename mysql to drizzle.
2150
   (char**) &drizzle_home_ptr, (char**) &drizzle_home_ptr, 0, GET_STR, REQUIRED_ARG,
1 by brian
clean slate
2151
   0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2152
  {"bind-address", OPT_BIND_ADDRESS, N_("IP address to bind to."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2153
   (char**) &my_bind_addr_str, (char**) &my_bind_addr_str, 0, GET_STR,
1 by brian
clean slate
2154
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2155
  {"character-set-filesystem", OPT_CHARACTER_SET_FILESYSTEM,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2156
   N_("Set the filesystem character set."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2157
   (char**) &character_set_filesystem_name,
2158
   (char**) &character_set_filesystem_name,
1 by brian
clean slate
2159
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2160
  {"character-set-server", 'C',
2161
   N_("Set the default character set."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2162
   (char**) &default_character_set_name, (char**) &default_character_set_name,
1 by brian
clean slate
2163
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2164
  {"chroot", 'r',
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
2165
   N_("Chroot drizzled daemon during startup."),
574.2.1 by ysano
Rename mysql to drizzle.
2166
   (char**) &drizzled_chroot, (char**) &drizzled_chroot, 0, GET_STR, REQUIRED_ARG,
1 by brian
clean slate
2167
   0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2168
  {"collation-server", OPT_DEFAULT_COLLATION,
2169
   N_("Set the default collation."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2170
   (char**) &default_collation_name, (char**) &default_collation_name,
1 by brian
clean slate
2171
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2172
  {"completion-type", OPT_COMPLETION_TYPE,
2173
   N_("Default completion type."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2174
   (char**) &global_system_variables.completion_type,
619 by Brian Aker
Removed ulong methods from vars.
2175
   (char**) &max_system_variables.completion_type, 0, GET_UINT,
1 by brian
clean slate
2176
   REQUIRED_ARG, 0, 0, 2, 0, 1, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2177
  {"core-file", OPT_WANT_CORE,
2178
   N_("Write core on errors."),
2179
   0, 0, 0, GET_NO_ARG,
1 by brian
clean slate
2180
   NO_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2181
  {"datadir", 'h',
2182
   N_("Path to the database root."),
575.4.1 by ysano
Rename mysql to drizzle.
2183
   (char**) &drizzle_data_home,
2184
   (char**) &drizzle_data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
2185
  {"default-storage-engine", OPT_STORAGE_ENGINE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2186
   N_("Set the default storage engine (table type) for tables."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2187
   (char**)&default_storage_engine_str, (char**)&default_storage_engine_str,
1 by brian
clean slate
2188
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2189
  {"default-time-zone", OPT_DEFAULT_TIME_ZONE,
2190
   N_("Set the default time zone."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2191
   (char**) &default_tz_name, (char**) &default_tz_name,
1 by brian
clean slate
2192
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2193
  {"delay-key-write", OPT_DELAY_KEY_WRITE,
2194
   N_("Type of DELAY_KEY_WRITE."),
1 by brian
clean slate
2195
   0,0,0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
2196
#ifdef HAVE_STACK_TRACE_ON_SEGV
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2197
  {"enable-pstack", OPT_DO_PSTACK,
2198
   N_("Print a symbolic stack trace on failure."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2199
   (char**) &opt_do_pstack, (char**) &opt_do_pstack, 0, GET_BOOL, NO_ARG, 0, 0,
1 by brian
clean slate
2200
   0, 0, 0, 0},
2201
#endif /* HAVE_STACK_TRACE_ON_SEGV */
2202
  {"engine-condition-pushdown",
2203
   OPT_ENGINE_CONDITION_PUSHDOWN,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2204
   N_("Push supported query conditions to the storage engine."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2205
   (char**) &global_system_variables.engine_condition_pushdown,
2206
   (char**) &global_system_variables.engine_condition_pushdown,
520.1.2 by Brian Aker
Disabling ICP, its buggy.
2207
   0, GET_BOOL, NO_ARG, false, 0, 0, 0, 0, 0},
1 by brian
clean slate
2208
  /* See how it's handled in get_one_option() */
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2209
  {"exit-info", 'T',
2210
   N_("Used for debugging;  Use at your own risk!"),
2211
   0, 0, 0, GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
2212
  {"flush", OPT_FLUSH,
2213
   N_("Flush tables to disk between SQL commands."),
2214
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
2215
  /* We must always support the next option to make scripts like mysqltest
2216
     easier to do */
2217
  {"gdb", OPT_DEBUGGING,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2218
   N_("Set up signals usable for debugging"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2219
   (char**) &opt_debugging, (char**) &opt_debugging,
1 by brian
clean slate
2220
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2221
  {"init-connect", OPT_INIT_CONNECT,
2222
   N_("Command(s) that are executed for each new connection"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2223
   (char**) &opt_init_connect, (char**) &opt_init_connect, 0, GET_STR_ALLOC,
1 by brian
clean slate
2224
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2225
  {"init-file", OPT_INIT_FILE,
2226
   N_("Read SQL commands from this file at startup."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2227
   (char**) &opt_init_file, (char**) &opt_init_file, 0, GET_STR, REQUIRED_ARG,
1 by brian
clean slate
2228
   0, 0, 0, 0, 0, 0},
2229
  {"language", 'L',
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2230
   N_("(IGNORED)"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2231
   (char**) &language_ptr, (char**) &language_ptr, 0, GET_STR, REQUIRED_ARG,
1 by brian
clean slate
2232
   0, 0, 0, 0, 0, 0},
2233
  {"lc-time-names", OPT_LC_TIME_NAMES,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2234
   N_("Set the language used for the month names and the days of the week."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2235
   (char**) &lc_time_names_name,
2236
   (char**) &lc_time_names_name,
1 by brian
clean slate
2237
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
2238
  {"local-infile", OPT_LOCAL_INFILE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2239
   N_("Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0)."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2240
   (char**) &opt_local_infile,
2241
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG,
1 by brian
clean slate
2242
   1, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2243
  {"log", 'l',
2244
   N_("Log connections and queries to file."),
2245
   (char**) &opt_logname,
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2246
   (char**) &opt_logname, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2247
  {"log-isam", OPT_ISAM_LOG,
2248
   N_("Log all MyISAM changes to file."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2249
   (char**) &myisam_log_filename, (char**) &myisam_log_filename, 0, GET_STR,
1 by brian
clean slate
2250
   OPT_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2251
  {"log-warnings", 'W',
2252
   N_("Log some not critical warnings to the log file."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2253
   (char**) &global_system_variables.log_warnings,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2254
   (char**) &max_system_variables.log_warnings, 0, GET_BOOL, OPT_ARG, 1, 0, 0,
1 by brian
clean slate
2255
   0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2256
  {"memlock", OPT_MEMLOCK,
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
2257
   N_("Lock drizzled in memory."),
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2258
   (char**) &locked_in_memory,
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2259
   (char**) &locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
2260
  {"myisam-recover", OPT_MYISAM_RECOVER,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2261
   N_("Syntax: myisam-recover[=option[,option...]], where option can be "
2262
      "DEFAULT, BACKUP, FORCE or QUICK."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2263
   (char**) &myisam_recover_options_str, (char**) &myisam_recover_options_str, 0,
1 by brian
clean slate
2264
   GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2265
  {"new", 'n',
2266
   N_("Use very new possible 'unsafe' functions."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2267
   (char**) &global_system_variables.new_mode,
2268
   (char**) &max_system_variables.new_mode,
1 by brian
clean slate
2269
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
2270
  {"old-alter-table", OPT_OLD_ALTER_TABLE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2271
   N_("Use old, non-optimized alter table."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2272
   (char**) &global_system_variables.old_alter_table,
2273
   (char**) &max_system_variables.old_alter_table, 0, GET_BOOL, NO_ARG,
1 by brian
clean slate
2274
   0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2275
  {"pid-file", OPT_PID_FILE,
2276
   N_("Pid file used by safe_mysqld."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2277
   (char**) &pidfile_name_ptr, (char**) &pidfile_name_ptr, 0, GET_STR,
1 by brian
clean slate
2278
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2279
  {"port", 'P',
2280
   N_("Port number to use for connection or 0 for default to, in "
520.4.28 by Monty Taylor
Changed my.cnf to drizzle.cnf and /etc/mysql to /etc/drizzle.
2281
      "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2282
      "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ")."),
574.2.1 by ysano
Rename mysql to drizzle.
2283
   (char**) &drizzled_port,
2284
   (char**) &drizzled_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
2285
  {"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2286
   N_("Maximum time in seconds to wait for the port to become free. "
2287
      "(Default: no wait)"),
574.2.1 by ysano
Rename mysql to drizzle.
2288
   (char**) &drizzled_port_timeout,
2289
   (char**) &drizzled_port_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2290
  {"safe-mode", OPT_SAFE,
2291
   N_("Skip some optimize stages (for testing)."),
1 by brian
clean slate
2292
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
2293
  {"secure-file-priv", OPT_SECURE_FILE_PRIV,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2294
   N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
2295
      "within specified directory"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2296
   (char**) &opt_secure_file_priv, (char**) &opt_secure_file_priv, 0,
1 by brian
clean slate
2297
   GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2298
  {"server-id",	OPT_SERVER_ID,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2299
   N_("Uniquely identifies the server instance in the community of "
2300
      "replication partners."),
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2301
   (char**) &server_id, (char**) &server_id, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 0,
1 by brian
clean slate
2302
   0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2303
  {"skip-new", OPT_SKIP_NEW,
2304
   N_("Don't use new, possible wrong routines."),
1 by brian
clean slate
2305
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
2306
  {"skip-stack-trace", OPT_SKIP_STACK_TRACE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2307
   N_("Don't print a stack trace on failure."),
2308
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
1 by brian
clean slate
2309
   0, 0, 0, 0},
2310
  {"skip-thread-priority", OPT_SKIP_PRIOR,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2311
   N_("Don't give threads different priorities."),
2312
   0, 0, 0, GET_NO_ARG, NO_ARG,
1 by brian
clean slate
2313
   DEFAULT_SKIP_THREAD_PRIORITY, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2314
  {"symbolic-links", 's',
2315
   N_("Enable symbolic link support."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2316
   (char**) &my_use_symdir, (char**) &my_use_symdir, 0, GET_BOOL, NO_ARG,
1 by brian
clean slate
2317
   /*
2318
     The system call realpath() produces warnings under valgrind and
2319
     purify. These are not suppressed: instead we disable symlinks
2320
     option if compiled with valgrind support.
2321
   */
2322
   IF_PURIFY(0,1), 0, 0, 0, 0, 0},
2323
  {"sysdate-is-now", OPT_SYSDATE_IS_NOW,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2324
   N_("Non-default option to alias SYSDATE() to NOW() to make it "
2325
      "safe-replicable."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2326
   (char**) &global_system_variables.sysdate_is_now,
1 by brian
clean slate
2327
   0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
2328
  {"temp-pool", OPT_TEMP_POOL,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2329
   N_("Using this option will cause most temporary files created to use a "
2330
      "small set of names, rather than a unique name for each new file."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2331
   (char**) &use_temp_pool, (char**) &use_temp_pool, 0, GET_BOOL, NO_ARG, 1,
1 by brian
clean slate
2332
   0, 0, 0, 0, 0},
2333
  {"timed_mutexes", OPT_TIMED_MUTEXES,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2334
   N_("Specify whether to time mutexes (only InnoDB mutexes are currently "
2335
      "supported)"),
236.1.40 by Monty Taylor
A few meaningless changes.
2336
   (char**) &timed_mutexes, (char**) &timed_mutexes, 0, GET_BOOL, NO_ARG, 0,
1 by brian
clean slate
2337
    0, 0, 0, 0, 0},
2338
  {"tmpdir", 't',
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
2339
   N_("Path for temporary files."),
575.4.3 by ysano
Rename mysql to drizzle.
2340
   (char**) &opt_drizzle_tmpdir,
2341
   (char**) &opt_drizzle_tmpdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
2342
  {"transaction-isolation", OPT_TX_ISOLATION,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2343
   N_("Default transaction isolation level."),
2344
   0, 0, 0, GET_STR, REQUIRED_ARG, 0,
1 by brian
clean slate
2345
   0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2346
  {"user", 'u',
574.2.1 by ysano
Rename mysql to drizzle.
2347
   N_("Run drizzled daemon as user."),
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2348
   0, 0, 0, GET_STR, REQUIRED_ARG,
1 by brian
clean slate
2349
   0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2350
  {"version", 'V',
2351
   N_("Output version information and exit."),
2352
   0, 0, 0, GET_NO_ARG,
1 by brian
clean slate
2353
   NO_ARG, 0, 0, 0, 0, 0, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2354
  {"back_log", OPT_BACK_LOG,
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
2355
   N_("The number of outstanding connection requests Drizzle can have. This "
2356
      "comes into play when the main Drizzle thread gets very many connection "
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2357
      "requests in a very short time."),
626 by Brian Aker
More of the same (ulong/64)
2358
    (char**) &back_log, (char**) &back_log, 0, GET_UINT,
1 by brian
clean slate
2359
    REQUIRED_ARG, 50, 1, 65535, 0, 1, 0 },
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2360
  { "bulk_insert_buffer_size", OPT_BULK_INSERT_BUFFER_SIZE,
672.1.3 by Andrew Hutchings
Minor string fixes (mainly US English spelling and typos)
2361
    N_("Size of tree cache used in bulk insert optimization. Note that this is "
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2362
       "a limit per thread!"),
2363
    (char**) &global_system_variables.bulk_insert_buff_size,
2364
    (char**) &max_system_variables.bulk_insert_buff_size,
619 by Brian Aker
Removed ulong methods from vars.
2365
    0, GET_ULL, REQUIRED_ARG, 8192*1024, 0, ULONG_MAX, 0, 1, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2366
  { "connect_timeout", OPT_CONNECT_TIMEOUT,
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
2367
    N_("The number of seconds the drizzled server is waiting for a connect "
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2368
       "packet before responding with 'Bad handshake'."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2369
    (char**) &connect_timeout, (char**) &connect_timeout,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2370
    0, GET_UINT32, REQUIRED_ARG, CONNECT_TIMEOUT, 2, LONG_TIMEOUT, 0, 1, 0 },
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2371
  { "div_precision_increment", OPT_DIV_PRECINCREMENT,
2372
   N_("Precision of the result of '/' operator will be increased on that "
2373
      "value."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2374
   (char**) &global_system_variables.div_precincrement,
619 by Brian Aker
Removed ulong methods from vars.
2375
   (char**) &max_system_variables.div_precincrement, 0, GET_UINT,
1 by brian
clean slate
2376
   REQUIRED_ARG, 4, 0, DECIMAL_MAX_SCALE, 0, 0, 0},
2377
  { "group_concat_max_len", OPT_GROUP_CONCAT_MAX_LEN,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2378
    N_("The maximum length of the result of function  group_concat."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2379
    (char**) &global_system_variables.group_concat_max_len,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2380
    (char**) &max_system_variables.group_concat_max_len, 0, GET_UINT64,
1 by brian
clean slate
2381
    REQUIRED_ARG, 1024, 4, ULONG_MAX, 0, 1, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2382
  { "interactive_timeout", OPT_INTERACTIVE_TIMEOUT,
2383
    N_("The number of seconds the server waits for activity on an interactive "
2384
       "connection before closing it."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2385
   (char**) &global_system_variables.net_interactive_timeout,
2386
   (char**) &max_system_variables.net_interactive_timeout, 0,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2387
   GET_UINT32, REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2388
  { "join_buffer_size", OPT_JOIN_BUFF_SIZE,
2389
    N_("The size of the buffer that is used for full joins."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2390
   (char**) &global_system_variables.join_buff_size,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2391
   (char**) &max_system_variables.join_buff_size, 0, GET_UINT64,
1 by brian
clean slate
2392
   REQUIRED_ARG, 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ULONG_MAX,
2393
   MALLOC_OVERHEAD, IO_SIZE, 0},
2394
  {"keep_files_on_create", OPT_KEEP_FILES_ON_CREATE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2395
   N_("Don't overwrite stale .MYD and .MYI even if no directory is specified."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2396
   (char**) &global_system_variables.keep_files_on_create,
2397
   (char**) &max_system_variables.keep_files_on_create,
1 by brian
clean slate
2398
   0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
2399
  {"key_buffer_size", OPT_KEY_BUFFER_SIZE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2400
   N_("The size of the buffer used for index blocks for MyISAM tables. "
2401
      "Increase this to get better index handling (for all reads and multiple "
312.1.12 by Monty Taylor
Fixed a syntax oops.
2402
      "writes) to as much as you can afford;"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2403
   (char**) &dflt_key_cache_var.param_buff_size,
2404
   (char**) 0,
1 by brian
clean slate
2405
   0, (GET_ULL | GET_ASK_ADDR),
2406
   REQUIRED_ARG, KEY_CACHE_SIZE, MALLOC_OVERHEAD, SIZE_T_MAX, MALLOC_OVERHEAD,
2407
   IO_SIZE, 0},
2408
  {"key_cache_age_threshold", OPT_KEY_CACHE_AGE_THRESHOLD,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2409
   N_("This characterizes the number of hits a hot block has to be untouched "
2410
      "until it is considered aged enough to be downgraded to a warm block. "
2411
      "This specifies the percentage ratio of that number of hits to the "
2412
      "total number of blocks in key cache"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2413
   (char**) &dflt_key_cache_var.param_age_threshold,
2414
   (char**) 0,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2415
   0, (GET_UINT32 | GET_ASK_ADDR), REQUIRED_ARG,
1 by brian
clean slate
2416
   300, 100, ULONG_MAX, 0, 100, 0},
2417
  {"key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2418
   N_("The default size of key cache blocks"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2419
   (char**) &dflt_key_cache_var.param_block_size,
2420
   (char**) 0,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2421
   0, (GET_UINT32 | GET_ASK_ADDR), REQUIRED_ARG,
1 by brian
clean slate
2422
   KEY_CACHE_BLOCK_SIZE, 512, 1024 * 16, 0, 512, 0},
2423
  {"key_cache_division_limit", OPT_KEY_CACHE_DIVISION_LIMIT,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2424
   N_("The minimum percentage of warm blocks in key cache"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2425
   (char**) &dflt_key_cache_var.param_division_limit,
2426
   (char**) 0,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2427
   0, (GET_UINT32 | GET_ASK_ADDR) , REQUIRED_ARG, 100,
1 by brian
clean slate
2428
   1, 100, 0, 1, 0},
2429
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2430
   N_("Max packetlength to send/receive from to server."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2431
   (char**) &global_system_variables.max_allowed_packet,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2432
   (char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
1 by brian
clean slate
2433
   REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
2434
  {"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2435
   N_("If there is more than this number of interrupted connections from a "
2436
      "host this host will be blocked from further connections."),
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2437
   (char**) &max_connect_errors, (char**) &max_connect_errors, 0, GET_UINT64,
312.1.12 by Monty Taylor
Fixed a syntax oops.
2438
   REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ULONG_MAX, 0, 1, 0},
1 by brian
clean slate
2439
  {"max_error_count", OPT_MAX_ERROR_COUNT,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2440
   N_("Max number of errors/warnings to store for a statement."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2441
   (char**) &global_system_variables.max_error_count,
2442
   (char**) &max_system_variables.max_error_count,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2443
   0, GET_UINT64, REQUIRED_ARG, DEFAULT_ERROR_COUNT, 0, 65535, 0, 1, 0},
1 by brian
clean slate
2444
  {"max_heap_table_size", OPT_MAX_HEP_TABLE_SIZE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2445
   N_("Don't allow creation of heap tables bigger than this."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2446
   (char**) &global_system_variables.max_heap_table_size,
2447
   (char**) &max_system_variables.max_heap_table_size, 0, GET_ULL,
1 by brian
clean slate
2448
   REQUIRED_ARG, 16*1024*1024L, 16384, MAX_MEM_TABLE_SIZE,
2449
   MALLOC_OVERHEAD, 1024, 0},
2450
  {"max_join_size", OPT_MAX_JOIN_SIZE,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2451
   N_("Joins that are probably going to read more than max_join_size records "
2452
      "return an error."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2453
   (char**) &global_system_variables.max_join_size,
2454
   (char**) &max_system_variables.max_join_size, 0, GET_HA_ROWS, REQUIRED_ARG,
365.2.8 by Monty Taylor
More MAX macros.
2455
   INT32_MAX, 1, INT32_MAX, 0, 1, 0},
312.1.12 by Monty Taylor
Fixed a syntax oops.
2456
  {"max_length_for_sort_data", OPT_MAX_LENGTH_FOR_SORT_DATA,
2457
   N_("Max number of bytes in sorted records."),
2458
   (char**) &global_system_variables.max_length_for_sort_data,
615 by Brian Aker
Added 32bit system variable support
2459
   (char**) &max_system_variables.max_length_for_sort_data, 0, GET_ULL,
312.1.12 by Monty Taylor
Fixed a syntax oops.
2460
   REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
1 by brian
clean slate
2461
  { "max_seeks_for_key", OPT_MAX_SEEKS_FOR_KEY,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2462
    N_("Limit assumed max number of seeks when looking up rows based on a key"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2463
    (char**) &global_system_variables.max_seeks_for_key,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2464
    (char**) &max_system_variables.max_seeks_for_key, 0, GET_UINT64,
1 by brian
clean slate
2465
    REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0 },
2466
  {"max_sort_length", OPT_MAX_SORT_LENGTH,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2467
   N_("The number of bytes to use when sorting BLOB or TEXT values "
2468
      "(only the first max_sort_length bytes of each value are used; the "
2469
      "rest are ignored)."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2470
   (char**) &global_system_variables.max_sort_length,
615 by Brian Aker
Added 32bit system variable support
2471
   (char**) &max_system_variables.max_sort_length, 0, GET_UINT,
1 by brian
clean slate
2472
   REQUIRED_ARG, 1024, 4, 8192*1024L, 0, 1, 0},
2473
  {"max_tmp_tables", OPT_MAX_TMP_TABLES,
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2474
   N_("Maximum number of temporary tables a client can keep open at a time."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2475
   (char**) &global_system_variables.max_tmp_tables,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2476
   (char**) &max_system_variables.max_tmp_tables, 0, GET_UINT64,
1 by brian
clean slate
2477
   REQUIRED_ARG, 32, 1, ULONG_MAX, 0, 1, 0},
2478
  {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2479
   N_("After this many write locks, allow some read locks to run in between."),
622.1.1 by Brian Aker
32bit fixes around vars
2480
   (char**) &max_write_lock_count, (char**) &max_write_lock_count, 0, GET_ULL,
1 by brian
clean slate
2481
   REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0},
2482
  {"min_examined_row_limit", OPT_MIN_EXAMINED_ROW_LIMIT,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2483
   N_("Don't log queries which examine less than min_examined_row_limit "
2484
      "rows to file."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2485
   (char**) &global_system_variables.min_examined_row_limit,
619 by Brian Aker
Removed ulong methods from vars.
2486
   (char**) &max_system_variables.min_examined_row_limit, 0, GET_ULL,
312.1.12 by Monty Taylor
Fixed a syntax oops.
2487
   REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1L, 0},
1 by brian
clean slate
2488
  {"myisam_stats_method", OPT_MYISAM_STATS_METHOD,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2489
   N_("Specifies how MyISAM index statistics collection code should threat "
2490
      "NULLs. Possible values of name are 'nulls_unequal' "
2491
      "(default behavior), "
2492
      "'nulls_equal' (emulate MySQL 4.0 behavior), and 'nulls_ignored'."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2493
   (char**) &myisam_stats_method_str, (char**) &myisam_stats_method_str, 0,
1 by brian
clean slate
2494
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2495
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2496
   N_("Buffer length for TCP/IP and socket communication."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2497
   (char**) &global_system_variables.net_buffer_length,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2498
   (char**) &max_system_variables.net_buffer_length, 0, GET_UINT32,
1 by brian
clean slate
2499
   REQUIRED_ARG, 16384, 1024, 1024*1024L, 0, 1024, 0},
2500
  {"net_read_timeout", OPT_NET_READ_TIMEOUT,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2501
   N_("Number of seconds to wait for more data from a connection before "
2502
      "aborting the read."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2503
   (char**) &global_system_variables.net_read_timeout,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2504
   (char**) &max_system_variables.net_read_timeout, 0, GET_UINT32,
1 by brian
clean slate
2505
   REQUIRED_ARG, NET_READ_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
2506
  {"net_retry_count", OPT_NET_RETRY_COUNT,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2507
   N_("If a read on a communication port is interrupted, retry this many "
2508
      "times before giving up."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2509
   (char**) &global_system_variables.net_retry_count,
2510
   (char**) &max_system_variables.net_retry_count,0,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2511
   GET_UINT32, REQUIRED_ARG, MYSQLD_NET_RETRY_COUNT, 1, ULONG_MAX, 0, 1, 0},
1 by brian
clean slate
2512
  {"net_write_timeout", OPT_NET_WRITE_TIMEOUT,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2513
   N_("Number of seconds to wait for a block to be written to a connection "
2514
      "before aborting the write."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2515
   (char**) &global_system_variables.net_write_timeout,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2516
   (char**) &max_system_variables.net_write_timeout, 0, GET_UINT32,
1 by brian
clean slate
2517
   REQUIRED_ARG, NET_WRITE_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
2518
  {"optimizer_prune_level", OPT_OPTIMIZER_PRUNE_LEVEL,
619 by Brian Aker
Removed ulong methods from vars.
2519
    N_("Controls the heuristic(s) applied during query optimization to prune "
2520
       "less-promising partial plans from the optimizer search space. Meaning: "
2521
       "false - do not apply any heuristic, thus perform exhaustive search; "
2522
       "true - prune plans based on number of retrieved rows."),
2523
    (char**) &global_system_variables.optimizer_prune_level,
2524
    (char**) &max_system_variables.optimizer_prune_level,
2525
    0, GET_BOOL, OPT_ARG, 1, 0, 1, 0, 1, 0},
1 by brian
clean slate
2526
  {"optimizer_search_depth", OPT_OPTIMIZER_SEARCH_DEPTH,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2527
   N_("Maximum depth of search performed by the query optimizer. Values "
2528
      "larger than the number of relations in a query result in better query "
2529
      "plans, but take longer to compile a query. Smaller values than the "
2530
      "number of tables in a relation result in faster optimization, but may "
2531
      "produce very bad query plans. If set to 0, the system will "
2532
      "automatically pick a reasonable value; if set to MAX_TABLES+2, the "
2533
      "optimizer will switch to the original find_best (used for "
2534
      "testing/comparison)."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2535
   (char**) &global_system_variables.optimizer_search_depth,
2536
   (char**) &max_system_variables.optimizer_search_depth,
619 by Brian Aker
Removed ulong methods from vars.
2537
   0, GET_UINT, OPT_ARG, MAX_TABLES+1, 0, MAX_TABLES+2, 0, 1, 0},
1 by brian
clean slate
2538
  {"plugin_dir", OPT_PLUGIN_DIR,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2539
   N_("Directory for plugins."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2540
   (char**) &opt_plugin_dir_ptr, (char**) &opt_plugin_dir_ptr, 0,
1 by brian
clean slate
2541
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2542
  {"plugin_load", OPT_PLUGIN_LOAD,
573.1.3 by moriyoshi
Fix description for --plugin_load
2543
   N_("Optional colon (or semicolon) separated list of plugins to load,"
2544
      "where each plugin is identified by the name of the shared library. "
2545
      "[for example: --plugin_load=libmd5udf.so:libauth_pam.so]"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2546
   (char**) &opt_plugin_load, (char**) &opt_plugin_load, 0,
1 by brian
clean slate
2547
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2548
  {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2549
   N_("The size of the buffer that is allocated when preloading indexes"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2550
   (char**) &global_system_variables.preload_buff_size,
619 by Brian Aker
Removed ulong methods from vars.
2551
   (char**) &max_system_variables.preload_buff_size, 0, GET_ULL,
1 by brian
clean slate
2552
   REQUIRED_ARG, 32*1024L, 1024, 1024*1024*1024L, 0, 1, 0},
2553
  {"query_alloc_block_size", OPT_QUERY_ALLOC_BLOCK_SIZE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2554
   N_("Allocation block size for query parsing and execution"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2555
   (char**) &global_system_variables.query_alloc_block_size,
617 by Brian Aker
ulong fixes
2556
   (char**) &max_system_variables.query_alloc_block_size, 0, GET_UINT,
1 by brian
clean slate
2557
   REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
2558
  {"query_prealloc_size", OPT_QUERY_PREALLOC_SIZE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2559
   N_("Persistent buffer for query parsing and execution"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2560
   (char**) &global_system_variables.query_prealloc_size,
617 by Brian Aker
ulong fixes
2561
   (char**) &max_system_variables.query_prealloc_size, 0, GET_UINT,
1 by brian
clean slate
2562
   REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, QUERY_ALLOC_PREALLOC_SIZE,
2563
   ULONG_MAX, 0, 1024, 0},
2564
  {"range_alloc_block_size", OPT_RANGE_ALLOC_BLOCK_SIZE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2565
   N_("Allocation block size for storing ranges during optimization"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2566
   (char**) &global_system_variables.range_alloc_block_size,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2567
   (char**) &max_system_variables.range_alloc_block_size, 0, GET_SIZE,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
2568
   REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, SIZE_MAX,
1 by brian
clean slate
2569
   0, 1024, 0},
2570
  {"read_buffer_size", OPT_RECORD_BUFFER,
619 by Brian Aker
Removed ulong methods from vars.
2571
    N_("Each thread that does a sequential scan allocates a buffer of this "
2572
       "size for each table it scans. If you do many sequential scans, you may "
2573
       "want to increase this value."),
2574
    (char**) &global_system_variables.read_buff_size,
2575
    (char**) &max_system_variables.read_buff_size,0, GET_UINT, REQUIRED_ARG,
2576
    128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT32_MAX, MALLOC_OVERHEAD, IO_SIZE,
2577
    0},
1 by brian
clean slate
2578
  {"read_rnd_buffer_size", OPT_RECORD_RND_BUFFER,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2579
   N_("When reading rows in sorted order after a sort, the rows are read "
2580
      "through this buffer to avoid a disk seeks. If not set, then it's set "
2581
      "to the value of record_buffer."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2582
   (char**) &global_system_variables.read_rnd_buff_size,
2583
   (char**) &max_system_variables.read_rnd_buff_size, 0,
619 by Brian Aker
Removed ulong methods from vars.
2584
   GET_UINT, REQUIRED_ARG, 256*1024L, 64 /*IO_SIZE*2+MALLOC_OVERHEAD*/ ,
2585
   UINT32_MAX, MALLOC_OVERHEAD, 1 /* Small lower limit to be able to test MRR */, 0},
868 by Brian Aker
Adding Multi-threaded Scheduler into the system.
2586
  {"scheduler", OPT_SCHEDULER,
2587
   N_("Select scheduler to be used (by default pool-of-threads)."),
2588
   (char**) &opt_scheduler, (char**) &opt_scheduler, 0,
2589
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
2590
  {"sort_buffer_size", OPT_SORT_BUFFER,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2591
   N_("Each thread that needs to do a sort allocates a buffer of this size."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2592
   (char**) &global_system_variables.sortbuff_size,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2593
   (char**) &max_system_variables.sortbuff_size, 0, GET_SIZE, REQUIRED_ARG,
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
2594
   MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*2, SIZE_MAX,
1 by brian
clean slate
2595
   MALLOC_OVERHEAD, 1, 0},
2596
  {"table_definition_cache", OPT_TABLE_DEF_CACHE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2597
   N_("The number of cached table definitions."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2598
   (char**) &table_def_size, (char**) &table_def_size,
622.1.1 by Brian Aker
32bit fixes around vars
2599
   0, GET_ULL, REQUIRED_ARG, 128, 1, 512*1024L, 0, 1, 0},
1 by brian
clean slate
2600
  {"table_open_cache", OPT_TABLE_OPEN_CACHE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2601
   N_("The number of cached open tables."),
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2602
   (char**) &table_cache_size, (char**) &table_cache_size, 0, GET_UINT64,
1 by brian
clean slate
2603
   REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0},
2604
  {"table_lock_wait_timeout", OPT_TABLE_LOCK_WAIT_TIMEOUT,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2605
   N_("Timeout in seconds to wait for a table level lock before returning an "
2606
      "error. Used only if the connection has active cursors."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2607
   (char**) &table_lock_wait_timeout, (char**) &table_lock_wait_timeout,
622.1.1 by Brian Aker
32bit fixes around vars
2608
   0, GET_ULL, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
1 by brian
clean slate
2609
  {"thread_stack", OPT_THREAD_STACK,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2610
   N_("The stack size for each thread."),
2611
   (char**) &my_thread_stack_size,
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
2612
   (char**) &my_thread_stack_size, 0, GET_SIZE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2613
   REQUIRED_ARG,DEFAULT_THREAD_STACK,
629.2.7 by Monty Taylor
Fixed a couple of memory buffer size issues.
2614
   UINT32_C(1024*128), SIZE_MAX, 0, 1024, 0},
1 by brian
clean slate
2615
  {"tmp_table_size", OPT_TMP_TABLE_SIZE,
672.1.3 by Andrew Hutchings
Minor string fixes (mainly US English spelling and typos)
2616
   N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2617
      " automatically convert it to an on-disk MyISAM table."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2618
   (char**) &global_system_variables.tmp_table_size,
2619
   (char**) &max_system_variables.tmp_table_size, 0, GET_ULL,
1 by brian
clean slate
2620
   REQUIRED_ARG, 16*1024*1024L, 1024, MAX_MEM_TABLE_SIZE, 0, 1, 0},
2621
  {"transaction_alloc_block_size", OPT_TRANS_ALLOC_BLOCK_SIZE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2622
   N_("Allocation block size for transactions to be stored in binary log"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2623
   (char**) &global_system_variables.trans_alloc_block_size,
617 by Brian Aker
ulong fixes
2624
   (char**) &max_system_variables.trans_alloc_block_size, 0, GET_UINT,
1 by brian
clean slate
2625
   REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
2626
  {"transaction_prealloc_size", OPT_TRANS_PREALLOC_SIZE,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2627
   N_("Persistent buffer for transactions to be stored in binary log"),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2628
   (char**) &global_system_variables.trans_prealloc_size,
617 by Brian Aker
ulong fixes
2629
   (char**) &max_system_variables.trans_prealloc_size, 0, GET_UINT,
1 by brian
clean slate
2630
   REQUIRED_ARG, TRANS_ALLOC_PREALLOC_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
2631
  {"wait_timeout", OPT_WAIT_TIMEOUT,
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
2632
   N_("The number of seconds the server waits for activity on a connection "
2633
      "before closing it."),
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
2634
   (char**) &global_system_variables.net_wait_timeout,
617 by Brian Aker
ulong fixes
2635
   (char**) &max_system_variables.net_wait_timeout, 0, GET_UINT,
287.3.32 by Monty Taylor
Removed another useless define.
2636
   REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT,
1 by brian
clean slate
2637
   0, 1, 0},
2638
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2639
};
2640
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
2641
static int show_net_compression(Session *session,
77.1.45 by Monty Taylor
Warning fixes.
2642
                                SHOW_VAR *var,
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
2643
                                char *)
1 by brian
clean slate
2644
{
2645
  var->type= SHOW_MY_BOOL;
520.1.22 by Brian Aker
Second pass of thd cleanup
2646
  var->value= (char *)&session->net.compress;
1 by brian
clean slate
2647
  return 0;
2648
}
2649
77.1.45 by Monty Taylor
Warning fixes.
2650
static st_show_var_func_container
2651
show_net_compression_cont= { &show_net_compression };
2652
520.1.22 by Brian Aker
Second pass of thd cleanup
2653
static int show_starttime(Session *session, SHOW_VAR *var, char *buff)
1 by brian
clean slate
2654
{
2655
  var->type= SHOW_LONG;
2656
  var->value= buff;
520.1.22 by Brian Aker
Second pass of thd cleanup
2657
  *((long *)buff)= (long) (session->query_start() - server_start_time);
1 by brian
clean slate
2658
  return 0;
2659
}
2660
77.1.45 by Monty Taylor
Warning fixes.
2661
static st_show_var_func_container
2662
show_starttime_cont= { &show_starttime };
2663
520.1.22 by Brian Aker
Second pass of thd cleanup
2664
static int show_flushstatustime(Session *session, SHOW_VAR *var, char *buff)
1 by brian
clean slate
2665
{
2666
  var->type= SHOW_LONG;
2667
  var->value= buff;
520.1.22 by Brian Aker
Second pass of thd cleanup
2668
  *((long *)buff)= (long) (session->query_start() - flush_status_time);
1 by brian
clean slate
2669
  return 0;
2670
}
2671
77.1.45 by Monty Taylor
Warning fixes.
2672
static st_show_var_func_container
2673
show_flushstatustime_cont= { &show_flushstatustime };
2674
779.1.29 by Monty Taylor
Merged from trunk.
2675
static int show_open_tables(Session *, SHOW_VAR *var, char *buff)
1 by brian
clean slate
2676
{
2677
  var->type= SHOW_LONG;
2678
  var->value= buff;
2679
  *((long *)buff)= (long)cached_open_tables();
2680
  return 0;
2681
}
2682
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
2683
static int show_table_definitions(Session *,
77.1.45 by Monty Taylor
Warning fixes.
2684
                                  SHOW_VAR *var, char *buff)
1 by brian
clean slate
2685
{
2686
  var->type= SHOW_LONG;
2687
  var->value= buff;
2688
  *((long *)buff)= (long)cached_table_definitions();
2689
  return 0;
2690
}
2691
77.1.45 by Monty Taylor
Warning fixes.
2692
static st_show_var_func_container
2693
show_open_tables_cont= { &show_open_tables };
2694
static st_show_var_func_container
2695
show_table_definitions_cont= { &show_table_definitions };
2696
1 by brian
clean slate
2697
/*
2698
  Variables shown by SHOW STATUS in alphabetical order
2699
*/
2700
2701
SHOW_VAR status_vars[]= {
625 by Brian Aker
ulong/64 bit straighten out.
2702
  {"Aborted_clients",          (char*) &aborted_threads,        SHOW_LONGLONG},
2703
  {"Aborted_connects",         (char*) &aborted_connects,       SHOW_LONGLONG},
1 by brian
clean slate
2704
  {"Bytes_received",           (char*) offsetof(STATUS_VAR, bytes_received), SHOW_LONGLONG_STATUS},
2705
  {"Bytes_sent",               (char*) offsetof(STATUS_VAR, bytes_sent), SHOW_LONGLONG_STATUS},
2706
  {"Com",                      (char*) com_status_vars, SHOW_ARRAY},
77.1.45 by Monty Taylor
Warning fixes.
2707
  {"Compression",              (char*) &show_net_compression_cont, SHOW_FUNC},
1 by brian
clean slate
2708
  {"Connections",              (char*) &thread_id,              SHOW_LONG_NOFLUSH},
2709
  {"Created_tmp_disk_tables",  (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
625 by Brian Aker
ulong/64 bit straighten out.
2710
  {"Created_tmp_files",	       (char*) &my_tmp_file_created,	SHOW_INT},
1 by brian
clean slate
2711
  {"Created_tmp_tables",       (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
2712
  {"Flush_commands",           (char*) &refresh_version,        SHOW_LONG_NOFLUSH},
2713
  {"Handler_commit",           (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
2714
  {"Handler_delete",           (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
2715
  {"Handler_prepare",          (char*) offsetof(STATUS_VAR, ha_prepare_count),  SHOW_LONG_STATUS},
2716
  {"Handler_read_first",       (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS},
2717
  {"Handler_read_key",         (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS},
2718
  {"Handler_read_next",        (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS},
2719
  {"Handler_read_prev",        (char*) offsetof(STATUS_VAR, ha_read_prev_count), SHOW_LONG_STATUS},
2720
  {"Handler_read_rnd",         (char*) offsetof(STATUS_VAR, ha_read_rnd_count), SHOW_LONG_STATUS},
2721
  {"Handler_read_rnd_next",    (char*) offsetof(STATUS_VAR, ha_read_rnd_next_count), SHOW_LONG_STATUS},
2722
  {"Handler_rollback",         (char*) offsetof(STATUS_VAR, ha_rollback_count), SHOW_LONG_STATUS},
2723
  {"Handler_savepoint",        (char*) offsetof(STATUS_VAR, ha_savepoint_count), SHOW_LONG_STATUS},
2724
  {"Handler_savepoint_rollback",(char*) offsetof(STATUS_VAR, ha_savepoint_rollback_count), SHOW_LONG_STATUS},
2725
  {"Handler_update",           (char*) offsetof(STATUS_VAR, ha_update_count), SHOW_LONG_STATUS},
2726
  {"Handler_write",            (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
2727
  {"Key_blocks_not_flushed",   (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
2728
  {"Key_blocks_unused",        (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
2729
  {"Key_blocks_used",          (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
2730
  {"Key_read_requests",        (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
2731
  {"Key_reads",                (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
2732
  {"Key_write_requests",       (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
2733
  {"Key_writes",               (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
2734
  {"Last_query_cost",          (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
625 by Brian Aker
ulong/64 bit straighten out.
2735
  {"Max_used_connections",     (char*) &max_used_connections,  SHOW_INT},
1 by brian
clean slate
2736
  {"Open_files",               (char*) &my_file_opened,         SHOW_LONG_NOFLUSH},
2737
  {"Open_streams",             (char*) &my_stream_opened,       SHOW_LONG_NOFLUSH},
77.1.45 by Monty Taylor
Warning fixes.
2738
  {"Open_table_definitions",   (char*) &show_table_definitions_cont, SHOW_FUNC},
2739
  {"Open_tables",              (char*) &show_open_tables_cont,       SHOW_FUNC},
1 by brian
clean slate
2740
  {"Opened_files",             (char*) &my_file_total_opened, SHOW_LONG_NOFLUSH},
2741
  {"Opened_tables",            (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
2742
  {"Opened_table_definitions", (char*) offsetof(STATUS_VAR, opened_shares), SHOW_LONG_STATUS},
2743
  {"Questions",                (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
2744
  {"Select_full_join",         (char*) offsetof(STATUS_VAR, select_full_join_count), SHOW_LONG_STATUS},
2745
  {"Select_full_range_join",   (char*) offsetof(STATUS_VAR, select_full_range_join_count), SHOW_LONG_STATUS},
2746
  {"Select_range",             (char*) offsetof(STATUS_VAR, select_range_count), SHOW_LONG_STATUS},
2747
  {"Select_range_check",       (char*) offsetof(STATUS_VAR, select_range_check_count), SHOW_LONG_STATUS},
2748
  {"Select_scan",	       (char*) offsetof(STATUS_VAR, select_scan_count), SHOW_LONG_STATUS},
625 by Brian Aker
ulong/64 bit straighten out.
2749
  {"Slow_launch_threads",      (char*) &slow_launch_threads,    SHOW_LONGLONG},
1 by brian
clean slate
2750
  {"Slow_queries",             (char*) offsetof(STATUS_VAR, long_query_count), SHOW_LONG_STATUS},
2751
  {"Sort_merge_passes",	       (char*) offsetof(STATUS_VAR, filesort_merge_passes), SHOW_LONG_STATUS},
2752
  {"Sort_range",	       (char*) offsetof(STATUS_VAR, filesort_range_count), SHOW_LONG_STATUS},
2753
  {"Sort_rows",		       (char*) offsetof(STATUS_VAR, filesort_rows), SHOW_LONG_STATUS},
2754
  {"Sort_scan",		       (char*) offsetof(STATUS_VAR, filesort_scan_count), SHOW_LONG_STATUS},
625 by Brian Aker
ulong/64 bit straighten out.
2755
  {"Table_locks_immediate",    (char*) &locks_immediate,        SHOW_INT},
2756
  {"Table_locks_waited",       (char*) &locks_waited,           SHOW_INT},
1 by brian
clean slate
2757
  {"Threads_connected",        (char*) &connection_count,       SHOW_INT},
2758
  {"Threads_created",	       (char*) &thread_created,		SHOW_LONG_NOFLUSH},
2759
  {"Threads_running",          (char*) &thread_running,         SHOW_INT},
77.1.45 by Monty Taylor
Warning fixes.
2760
  {"Uptime",                   (char*) &show_starttime_cont,         SHOW_FUNC},
2761
  {"Uptime_since_flush_status",(char*) &show_flushstatustime_cont,   SHOW_FUNC},
625 by Brian Aker
ulong/64 bit straighten out.
2762
  {NULL, NULL, SHOW_LONGLONG}
1 by brian
clean slate
2763
};
2764
2765
static void print_version(void)
2766
{
2767
  set_server_version();
2768
  /*
2769
    Note: the instance manager keys off the string 'Ver' so it can find the
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
2770
    version from the output of 'drizzled --version', so don't change it!
1 by brian
clean slate
2771
  */
2772
  printf("%s  Ver %s for %s on %s (%s)\n",my_progname,
546 by Monty Taylor
Cleaned up version.h. (And by cleaned, I mean removed)
2773
	 server_version,SYSTEM_TYPE,MACHINE_TYPE, COMPILATION_COMMENT);
1 by brian
clean slate
2774
}
2775
2776
static void usage(void)
2777
{
862 by Brian Aker
Remove charset directory code.
2778
  if (!(default_charset_info= get_charset_by_csname(default_character_set_name, MY_CS_PRIMARY)))
1 by brian
clean slate
2779
    exit(1);
2780
  if (!default_collation_name)
2781
    default_collation_name= (char*) default_charset_info->name;
2782
  print_version();
656.1.27 by Monty Taylor
Fixed the mysqld in the drizzle.cnf thing.
2783
  puts(_("Copyright (C) 2008 Sun Microsystems\n"
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2784
         "This software comes with ABSOLUTELY NO WARRANTY. "
2785
         "This is free software,\n"
2786
         "and you are welcome to modify and redistribute it under the GPL "
2787
         "license\n\n"
2788
         "Starts the Drizzle database server\n"));
1 by brian
clean slate
2789
312.1.12 by Monty Taylor
Fixed a syntax oops.
2790
  printf(_("Usage: %s [OPTIONS]\n"), my_progname);
1 by brian
clean slate
2791
  {
259 by Brian Aker
First pass on PAM auth
2792
#ifdef FOO
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2793
  print_defaults(DRIZZLE_CONFIG_NAME,load_default_groups);
1 by brian
clean slate
2794
  puts("");
2795
  set_ports();
259 by Brian Aker
First pass on PAM auth
2796
#endif
1 by brian
clean slate
2797
2798
  /* Print out all the options including plugin supplied options */
2799
  my_print_help_inc_plugins(my_long_options, sizeof(my_long_options)/sizeof(my_option));
2800
312.1.11 by Monty Taylor
Added some strings from drizzled.cc.
2801
  puts(_("\nTo see what values a running Drizzle server is using, type\n"
2802
         "'drizzleadmin variables' instead of 'drizzled --help'."));
1 by brian
clean slate
2803
  }
2804
}
2805
2806
2807
/**
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
2808
  Initialize all Drizzle global variables to default values.
1 by brian
clean slate
2809
2810
  We don't need to set numeric variables refered to in my_long_options
2811
  as these are initialized by my_getopt.
2812
2813
  @note
2814
    The reason to set a lot of global variables to zero is to allow one to
2815
    restart the embedded server with a clean environment
2816
    It's also needed on some exotic platforms where global variables are
2817
    not set to 0 when a program starts.
2818
2819
    We don't need to set numeric variables refered to in my_long_options
2820
    as these are initialized by my_getopt.
2821
*/
2822
574.2.1 by ysano
Rename mysql to drizzle.
2823
static void drizzle_init_variables(void)
1 by brian
clean slate
2824
{
2825
  /* Things reset to zero */
2826
  opt_skip_slave_start= opt_reckless_slave = 0;
722.4.1 by Mark Atwood
integrate errmsg plugin into sql_print_* functions
2827
  drizzle_home[0]= pidfile_name[0]= 0;
1 by brian
clean slate
2828
  opt_bin_log= 0;
228 by Brian Aker
First pass on socket cleanup.
2829
  opt_skip_show_db=0;
798.2.32 by Brian Aker
Last removal of variables.
2830
  opt_logname= 0;
1 by brian
clean slate
2831
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
2832
  opt_secure_file_priv= 0;
900 by Brian Aker
Creating signal handler plugin.
2833
  segfaulted= 0;
1 by brian
clean slate
2834
  cleanup_done= 0;
2835
  defaults_argc= 0;
2836
  defaults_argv= 0;
2837
  server_id_supplied= 0;
2838
  test_flags= select_errors= dropping_tables= ha_open_options=0;
566 by Brian Aker
Clean up dead thead code.
2839
  thread_count= thread_running= wake_thread=0;
1 by brian
clean slate
2840
  slave_open_temp_tables= 0;
2841
  opt_endinfo= using_udf_functions= 0;
604 by Brian Aker
Remove lock condition needed (we do row based replication, so... lock is
2842
  opt_using_transactions= false;
909 by Brian Aker
Remove the need for unireg init
2843
  abort_loop= select_thread_in_use= false;
1 by brian
clean slate
2844
  ready_to_exit= shutdown_in_progress= 0;
2845
  aborted_threads= aborted_connects= 0;
779.3.23 by Monty Taylor
More fixy-fixes.
2846
  max_used_connections= 0;
2847
  slow_launch_threads= 0;
574.2.1 by ysano
Rename mysql to drizzle.
2848
  drizzled_user= drizzled_chroot= opt_init_file= opt_bin_logname = 0;
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
2849
  my_bind_addr_str= NULL;
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
2850
  memset(&global_status_var, 0, sizeof(global_status_var));
1 by brian
clean slate
2851
  key_map_full.set_all();
2852
2853
  /* Character sets */
2854
  system_charset_info= &my_charset_utf8_general_ci;
2855
  files_charset_info= &my_charset_utf8_general_ci;
2856
  national_charset_info= &my_charset_utf8_general_ci;
2857
  table_alias_charset= &my_charset_bin;
2858
  character_set_filesystem= &my_charset_bin;
2859
2860
  /* Things with default values that are not zero */
895 by Brian Aker
Completion (?) of uint conversion.
2861
  delay_key_write_options= (uint32_t) DELAY_KEY_WRITE_ON;
575.4.1 by ysano
Rename mysql to drizzle.
2862
  drizzle_home_ptr= drizzle_home;
1 by brian
clean slate
2863
  pidfile_name_ptr= pidfile_name;
2864
  language_ptr= language;
575.4.1 by ysano
Rename mysql to drizzle.
2865
  drizzle_data_home= drizzle_real_data_home;
818 by Brian Aker
Found a few bits to be deleted (around binlog).
2866
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
1 by brian
clean slate
2867
  refresh_version= 1L;	/* Increments on each reload */
561.1.3 by Monty Taylor
Split some more things out of common_includes.h.
2868
  thread_id= 1;
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
2869
  strcpy(server_version, VERSION);
1 by brian
clean slate
2870
  myisam_recover_options_str= "OFF";
2871
  myisam_stats_method_str= "nulls_unequal";
2872
  threads.empty();
2873
  key_caches.empty();
2874
  if (!(dflt_key_cache= get_or_create_key_cache(default_key_cache_base.str,
2875
                                                default_key_cache_base.length)))
2876
    exit(1);
2877
  /* set key_cache_hash.default_value = dflt_key_cache */
2878
  multi_keycache_init();
2879
2880
  /* Set directory paths */
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
2881
  strncpy(language, LANGUAGE, sizeof(language)-1);
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
2882
  strncpy(drizzle_real_data_home, get_relative_path(LOCALSTATEDIR),
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
2883
          sizeof(drizzle_real_data_home)-1);
575.4.3 by ysano
Rename mysql to drizzle.
2884
  drizzle_data_home_buff[0]=FN_CURLIB;	// all paths are relative from here
2885
  drizzle_data_home_buff[1]=0;
575.4.1 by ysano
Rename mysql to drizzle.
2886
  drizzle_data_home_len= 2;
1 by brian
clean slate
2887
2888
  /* Variables in libraries */
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
2889
  default_character_set_name= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
1 by brian
clean slate
2890
  default_collation_name= compiled_default_collation_name;
2891
  character_set_filesystem_name= (char*) "binary";
2892
  lc_time_names_name= (char*) "en_US";
2893
  /* Set default values for some option variables */
201 by Brian Aker
Convert default engine to Innodb
2894
  default_storage_engine_str= (char*) "innodb";
1 by brian
clean slate
2895
  global_system_variables.table_plugin= NULL;
2896
  global_system_variables.tx_isolation= ISO_REPEATABLE_READ;
151 by Brian Aker
Ulonglong to uint64_t
2897
  global_system_variables.select_limit= (uint64_t) HA_POS_ERROR;
2898
  max_system_variables.select_limit=    (uint64_t) HA_POS_ERROR;
2899
  global_system_variables.max_join_size= (uint64_t) HA_POS_ERROR;
2900
  max_system_variables.max_join_size=   (uint64_t) HA_POS_ERROR;
1 by brian
clean slate
2901
  global_system_variables.old_alter_table= 0;
2902
  /*
2903
    Default behavior for 4.1 and 5.0 is to treat NULL values as unequal
2904
    when collecting index statistics for MyISAM tables.
2905
  */
2906
  global_system_variables.myisam_stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
2907
2908
  /* Variables that depends on compile options */
2909
#ifdef HAVE_BROKEN_REALPATH
2910
  have_symlink=SHOW_OPTION_NO;
2911
#else
2912
  have_symlink=SHOW_OPTION_YES;
2913
#endif
2914
2915
  const char *tmpenv;
2916
  if (!(tmpenv = getenv("MY_BASEDIR_VERSION")))
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
2917
    tmpenv = PREFIX;
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
2918
  (void) strncpy(drizzle_home, tmpenv, sizeof(drizzle_home)-1);
1 by brian
clean slate
2919
}
2920
2921
143 by Brian Aker
Bool cleanup.
2922
bool
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
2923
drizzled_get_one_option(int optid, const struct my_option *opt,
2924
                        char *argument)
1 by brian
clean slate
2925
{
2926
  switch(optid) {
2927
  case '#':
2928
    opt_endinfo=1;				/* unireg: memory allocation */
2929
    break;
2930
  case 'a':
2931
    global_system_variables.tx_isolation= ISO_SERIALIZABLE;
2932
    break;
2933
  case 'b':
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
2934
    strncpy(drizzle_home,argument,sizeof(drizzle_home)-1);
1 by brian
clean slate
2935
    break;
2936
  case 'C':
2937
    if (default_collation_name == compiled_default_collation_name)
2938
      default_collation_name= 0;
2939
    break;
2940
  case 'h':
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
2941
    strncpy(drizzle_real_data_home,argument, sizeof(drizzle_real_data_home)-1);
1 by brian
clean slate
2942
    /* Correct pointer set by my_getopt (for embedded library) */
575.4.1 by ysano
Rename mysql to drizzle.
2943
    drizzle_data_home= drizzle_real_data_home;
2944
    drizzle_data_home_len= strlen(drizzle_data_home);
1 by brian
clean slate
2945
    break;
2946
  case 'u':
574.2.1 by ysano
Rename mysql to drizzle.
2947
    if (!drizzled_user || !strcmp(drizzled_user, argument))
2948
      drizzled_user= argument;
1 by brian
clean slate
2949
    else
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
2950
      errmsg_printf(ERRMSG_LVL_WARN, _("Ignoring user change to '%s' because the user was "
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
2951
                          "set to '%s' earlier on the command line\n"),
574.2.1 by ysano
Rename mysql to drizzle.
2952
                        argument, drizzled_user);
1 by brian
clean slate
2953
    break;
2954
  case 'L':
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
2955
    strncpy(language, argument, sizeof(language)-1);
1 by brian
clean slate
2956
    break;
2957
  case 'V':
2958
    print_version();
2959
    exit(0);
2960
  case 'W':
2961
    if (!argument)
2962
      global_system_variables.log_warnings++;
2963
    else if (argument == disabled_my_option)
2964
      global_system_variables.log_warnings= 0L;
2965
    else
2966
      global_system_variables.log_warnings= atoi(argument);
2967
    break;
2968
  case 'T':
895 by Brian Aker
Completion (?) of uint conversion.
2969
    test_flags= argument ? (uint32_t) atoi(argument) : 0;
1 by brian
clean slate
2970
    opt_endinfo=1;
2971
    break;
2972
  case (int) OPT_BIN_LOG:
2973
    opt_bin_log= test(argument != disabled_my_option);
2974
    break;
2975
  case (int) OPT_WANT_CORE:
2976
    test_flags |= TEST_CORE_ON_SIGNAL;
2977
    break;
2978
  case (int) OPT_SKIP_STACK_TRACE:
2979
    test_flags|=TEST_NO_STACKTRACE;
2980
    break;
2981
  case (int) OPT_SKIP_SYMLINKS:
2982
    my_use_symdir=0;
2983
    break;
2984
  case (int) OPT_BIND_ADDRESS:
2985
    {
236.1.40 by Monty Taylor
A few meaningless changes.
2986
      struct addrinfo *res_lst, hints;
1 by brian
clean slate
2987
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
2988
      memset(&hints, 0, sizeof(struct addrinfo));
1 by brian
clean slate
2989
      hints.ai_socktype= SOCK_STREAM;
2990
      hints.ai_protocol= IPPROTO_TCP;
2991
236.1.40 by Monty Taylor
A few meaningless changes.
2992
      if (getaddrinfo(argument, NULL, &hints, &res_lst) != 0)
1 by brian
clean slate
2993
      {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
2994
          errmsg_printf(ERRMSG_LVL_ERROR, _("Can't start server: cannot resolve hostname!"));
1 by brian
clean slate
2995
        exit(1);
2996
      }
2997
2998
      if (res_lst->ai_next)
2999
      {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
3000
          errmsg_printf(ERRMSG_LVL_ERROR, _("Can't start server: bind-address refers to "
312.1.10 by Monty Taylor
Added some strings from drizzled.cc.
3001
                          "multiple interfaces!"));
1 by brian
clean slate
3002
        exit(1);
3003
      }
3004
      freeaddrinfo(res_lst);
3005
    }
3006
    break;
3007
  case (int) OPT_PID_FILE:
629.5.4 by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls
3008
    strncpy(pidfile_name, argument, sizeof(pidfile_name)-1);
1 by brian
clean slate
3009
    break;
3010
  case OPT_SERVER_ID:
3011
    server_id_supplied = 1;
3012
    break;
3013
  case OPT_DELAY_KEY_WRITE_ALL:
3014
    if (argument != disabled_my_option)
3015
      argument= (char*) "ALL";
3016
    /* Fall through */
3017
  case OPT_DELAY_KEY_WRITE:
3018
    if (argument == disabled_my_option)
895 by Brian Aker
Completion (?) of uint conversion.
3019
      delay_key_write_options= (uint32_t) DELAY_KEY_WRITE_NONE;
1 by brian
clean slate
3020
    else if (! argument)
895 by Brian Aker
Completion (?) of uint conversion.
3021
      delay_key_write_options= (uint32_t) DELAY_KEY_WRITE_ON;
1 by brian
clean slate
3022
    else
3023
    {
3024
      int type;
3025
      type= find_type_or_exit(argument, &delay_key_write_typelib, opt->name);
895 by Brian Aker
Completion (?) of uint conversion.
3026
      delay_key_write_options= (uint32_t) type-1;
1 by brian
clean slate
3027
    }
3028
    break;
3029
  case OPT_TX_ISOLATION:
224.2.2 by Brian Aker
Second pass cleanup around filesystem type.
3030
    {
3031
      int type;
3032
      type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
3033
      global_system_variables.tx_isolation= (type-1);
3034
      break;
3035
    }
1 by brian
clean slate
3036
  case OPT_MYISAM_RECOVER:
224.2.2 by Brian Aker
Second pass cleanup around filesystem type.
3037
    {
3038
      if (!argument)
3039
      {
3040
        myisam_recover_options=    HA_RECOVER_DEFAULT;
3041
        myisam_recover_options_str= myisam_recover_typelib.type_names[0];
3042
      }
3043
      else if (!argument[0])
3044
      {
3045
        myisam_recover_options= HA_RECOVER_NONE;
3046
        myisam_recover_options_str= "OFF";
3047
      }
3048
      else
3049
      {
3050
        myisam_recover_options_str=argument;
3051
        myisam_recover_options=
3052
          find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
3053
      }
3054
      ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
3055
      break;
3056
    }
1 by brian
clean slate
3057
  case OPT_TC_HEURISTIC_RECOVER:
3058
    tc_heuristic_recover= find_type_or_exit(argument,
3059
                                            &tc_heuristic_recover_typelib,
3060
                                            opt->name);
3061
    break;
3062
  case OPT_MYISAM_STATS_METHOD:
224.2.2 by Brian Aker
Second pass cleanup around filesystem type.
3063
    {
366 by Patrick Galbraith
Ulong conversion
3064
      uint32_t method_conv;
224.2.2 by Brian Aker
Second pass cleanup around filesystem type.
3065
      int method;
1 by brian
clean slate
3066
224.2.2 by Brian Aker
Second pass cleanup around filesystem type.
3067
      myisam_stats_method_str= argument;
3068
      method= find_type_or_exit(argument, &myisam_stats_method_typelib,
3069
                                opt->name);
3070
      switch (method-1) {
3071
      case 2:
3072
        method_conv= MI_STATS_METHOD_IGNORE_NULLS;
3073
        break;
3074
      case 1:
3075
        method_conv= MI_STATS_METHOD_NULLS_EQUAL;
3076
        break;
3077
      case 0:
3078
      default:
3079
        method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
3080
        break;
3081
      }
3082
      global_system_variables.myisam_stats_method= method_conv;
1 by brian
clean slate
3083
      break;
3084
    }
3085
  }
3086
  return 0;
3087
}
3088
3089
3090
/** Handle arguments for multiple key caches. */
3091
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
3092
extern "C" char **drizzle_getopt_value(const char *keyname, uint32_t key_length,
590.2.19 by Super-User
Yay! Compiles on Solaris.
3093
                                       const struct my_option *option);
1 by brian
clean slate
3094
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
3095
char**
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
3096
drizzle_getopt_value(const char *keyname, uint32_t key_length,
590.2.19 by Super-User
Yay! Compiles on Solaris.
3097
		    const struct my_option *option)
1 by brian
clean slate
3098
{
3099
  switch (option->id) {
3100
  case OPT_KEY_BUFFER_SIZE:
3101
  case OPT_KEY_CACHE_BLOCK_SIZE:
3102
  case OPT_KEY_CACHE_DIVISION_LIMIT:
3103
  case OPT_KEY_CACHE_AGE_THRESHOLD:
3104
  {
3105
    KEY_CACHE *key_cache;
3106
    if (!(key_cache= get_or_create_key_cache(keyname, key_length)))
3107
      exit(1);
3108
    switch (option->id) {
3109
    case OPT_KEY_BUFFER_SIZE:
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
3110
      return (char**) &key_cache->param_buff_size;
1 by brian
clean slate
3111
    case OPT_KEY_CACHE_BLOCK_SIZE:
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
3112
      return (char**) &key_cache->param_block_size;
1 by brian
clean slate
3113
    case OPT_KEY_CACHE_DIVISION_LIMIT:
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
3114
      return (char**) &key_cache->param_division_limit;
1 by brian
clean slate
3115
    case OPT_KEY_CACHE_AGE_THRESHOLD:
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
3116
      return (char**) &key_cache->param_age_threshold;
1 by brian
clean slate
3117
    }
3118
  }
3119
  }
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
3120
  return (char **)option->value;
1 by brian
clean slate
3121
}
3122
3123
3124
extern "C" void option_error_reporter(enum loglevel level, const char *format, ...);
3125
3126
void option_error_reporter(enum loglevel level, const char *format, ...)
3127
{
3128
  va_list args;
3129
  va_start(args, format);
3130
3131
  /* Don't print warnings for --loose options during bootstrap */
228 by Brian Aker
First pass on socket cleanup.
3132
  if (level == ERROR_LEVEL || global_system_variables.log_warnings)
1 by brian
clean slate
3133
  {
612.1.1 by Mark Atwood
remove some errmsg dead code, use more of the errmsg plugin
3134
    errmsg_vprintf (current_session, ERROR_LEVEL, format, args);
1 by brian
clean slate
3135
  }
3136
  va_end(args);
3137
}
3138
3139
3140
/**
3141
  @todo
3142
  - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code?
3143
*/
3144
static void get_options(int *argc,char **argv)
3145
{
3146
  int ho_error;
3147
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
3148
  my_getopt_register_get_addr(drizzle_getopt_value);
1 by brian
clean slate
3149
  my_getopt_error_reporter= option_error_reporter;
3150
3151
  /* Skip unknown options so that they may be processed later by plugins */
163 by Brian Aker
Merge Monty's code.
3152
  my_getopt_skip_unknown= true;
1 by brian
clean slate
3153
3154
  if ((ho_error= handle_options(argc, &argv, my_long_options,
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
3155
                                drizzled_get_one_option)))
1 by brian
clean slate
3156
    exit(ho_error);
3157
  (*argc)++; /* add back one for the progname handle_options removes */
3158
             /* no need to do this for argv as we are discarding it. */
3159
3160
#if defined(HAVE_BROKEN_REALPATH)
3161
  my_use_symdir=0;
3162
  my_disable_symlinks=1;
3163
  have_symlink=SHOW_OPTION_NO;
3164
#else
3165
  if (!my_use_symdir)
3166
  {
3167
    my_disable_symlinks=1;
3168
    have_symlink=SHOW_OPTION_DISABLED;
3169
  }
3170
#endif
3171
  if (opt_debugging)
3172
  {
3173
    /* Allow break with SIGINT, no core or stack trace */
3174
    test_flags|= TEST_SIGINT | TEST_NO_STACKTRACE;
3175
    test_flags&= ~TEST_CORE_ON_SIGNAL;
3176
  }
3177
  /* Set global MyISAM variables from delay_key_write_options */
520.1.21 by Brian Aker
THD -> Session rename
3178
  fix_delay_key_write((Session*) 0, OPT_GLOBAL);
1 by brian
clean slate
3179
574.2.1 by ysano
Rename mysql to drizzle.
3180
  if (drizzled_chroot)
3181
    set_root(drizzled_chroot);
1 by brian
clean slate
3182
  fix_paths();
3183
3184
  /*
3185
    Set some global variables from the global_system_variables
3186
    In most cases the global variables will not be used
3187
  */
3188
  my_default_record_cache_size=global_system_variables.read_buff_size;
788 by Brian Aker
Move MyISAM bits to myisam plugin
3189
  myisam_max_temp_length= INT32_MAX;
1 by brian
clean slate
3190
}
3191
3192
/*
575.4.4 by Yoshinori Sano
Rename mysql to drizzle.
3193
  Create version name for running drizzled version
1 by brian
clean slate
3194
  We automaticly add suffixes -debug, -embedded and -log to the version
3195
  name to make the version more descriptive.
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
3196
  (DRIZZLE_SERVER_SUFFIX is set by the compilation environment)
1 by brian
clean slate
3197
*/
3198
390.1.1 by Monty Taylor
Removed mysqld_suffix. Pointless.
3199
#ifdef DRIZZLE_SERVER_SUFFIX
3200
#define DRIZZLE_SERVER_SUFFIX_STR STRINGIFY_ARG(DRIZZLE_SERVER_SUFFIX)
3201
#else
546 by Monty Taylor
Cleaned up version.h. (And by cleaned, I mean removed)
3202
#define DRIZZLE_SERVER_SUFFIX_STR ""
390.1.1 by Monty Taylor
Removed mysqld_suffix. Pointless.
3203
#endif
3204
1 by brian
clean slate
3205
static void set_server_version(void)
3206
{
673.2.1 by Toru Maesaka
First pass of replacing MySQL's strxmov with libc alternatives
3207
  char *end= server_version;
3208
  end+= sprintf(server_version, "%s%s", VERSION, 
3209
                DRIZZLE_SERVER_SUFFIX_STR);
438.1.1 by Brian Aker
First pass of removing historical logging.
3210
  if (opt_bin_log)
673.2.1 by Toru Maesaka
First pass of replacing MySQL's strxmov with libc alternatives
3211
    strcpy(end, "-log"); // This may slow down system
1 by brian
clean slate
3212
}
3213
3214
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
3215
static const char *get_relative_path(const char *path)
1 by brian
clean slate
3216
{
3217
  if (test_if_hard_path(path) &&
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
3218
      is_prefix(path,PREFIX) &&
3219
      strcmp(PREFIX,FN_ROOTDIR))
1 by brian
clean slate
3220
  {
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
3221
    if (strlen(PREFIX) < strlen(path))
3222
      path+=(size_t) strlen(PREFIX);
1 by brian
clean slate
3223
    while (*path == FN_LIBCHAR)
3224
      path++;
3225
  }
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
3226
  return path;
1 by brian
clean slate
3227
}
3228
3229
3230
static void fix_paths(void)
3231
{
3232
  char buff[FN_REFLEN],*pos;
575.4.1 by ysano
Rename mysql to drizzle.
3233
  convert_dirname(drizzle_home,drizzle_home,NULL);
3234
  /* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */
3235
  my_realpath(drizzle_home,drizzle_home,MYF(0));
3236
  /* Ensure that drizzle_home ends in FN_LIBCHAR */
3237
  pos= strchr(drizzle_home, '\0');
1 by brian
clean slate
3238
  if (pos[-1] != FN_LIBCHAR)
3239
  {
3240
    pos[0]= FN_LIBCHAR;
3241
    pos[1]= 0;
3242
  }
575.4.1 by ysano
Rename mysql to drizzle.
3243
  convert_dirname(drizzle_real_data_home,drizzle_real_data_home,NULL);
3244
  (void) fn_format(buff, drizzle_real_data_home, "", "",
1 by brian
clean slate
3245
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
575.4.1 by ysano
Rename mysql to drizzle.
3246
  (void) unpack_dirname(drizzle_unpacked_real_data_home, buff);
461 by Monty Taylor
Removed NullS. bu-bye.
3247
  convert_dirname(language,language,NULL);
856 by Brian Aker
Remove dead code around charset variable/directory.
3248
  (void) my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
3249
  (void) my_load_path(drizzle_real_data_home, drizzle_real_data_home,drizzle_home);
3250
  (void) my_load_path(pidfile_name, pidfile_name,drizzle_real_data_home);
1 by brian
clean slate
3251
  (void) my_load_path(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr :
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
3252
                                      get_relative_path(PKGPLUGINDIR),
3253
                                      drizzle_home);
1 by brian
clean slate
3254
  opt_plugin_dir_ptr= opt_plugin_dir;
3255
856 by Brian Aker
Remove dead code around charset variable/directory.
3256
  const char *sharedir= get_relative_path(PKGDATADIR);
1 by brian
clean slate
3257
  if (test_if_hard_path(sharedir))
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
3258
    strncpy(buff,sharedir,sizeof(buff)-1);		/* purecov: tested */
1 by brian
clean slate
3259
  else
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
3260
  {
575.4.1 by ysano
Rename mysql to drizzle.
3261
    strcpy(buff, drizzle_home);
3262
    strncat(buff, sharedir, sizeof(buff)-strlen(drizzle_home)-1);
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
3263
  }
461 by Monty Taylor
Removed NullS. bu-bye.
3264
  convert_dirname(buff,buff,NULL);
1 by brian
clean slate
3265
  (void) my_load_path(language,language,buff);
3266
680 by Brian Aker
Remove locks around temp tables for searching tmp directory path.
3267
  {
3268
    char *tmp_string;
3269
    struct stat buf;
3270
3271
    tmp_string= getenv("TMPDIR");
3272
3273
    if (opt_drizzle_tmpdir)
3274
      drizzle_tmpdir= strdup(opt_drizzle_tmpdir);
3275
    else if (tmp_string == NULL)
3276
      drizzle_tmpdir= strdup(P_tmpdir);
3277
    else
3278
      drizzle_tmpdir= strdup(tmp_string);
3279
3280
    assert(drizzle_tmpdir);
3281
3282
    if (stat(drizzle_tmpdir, &buf) || (S_ISDIR(buf.st_mode) == false))
3283
    {
3284
      exit(1);
3285
    }
3286
  }
3287
1 by brian
clean slate
3288
  /*
3289
    Convert the secure-file-priv option to system format, allowing
3290
    a quick strcmp to check if read or write is in an allowed dir
3291
   */
3292
  if (opt_secure_file_priv)
3293
  {
461 by Monty Taylor
Removed NullS. bu-bye.
3294
    convert_dirname(buff, opt_secure_file_priv, NULL);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
3295
    free(opt_secure_file_priv);
656.1.19 by Monty Taylor
Removed my_strdup from drizzled/
3296
    opt_secure_file_priv= strdup(buff);
656.1.52 by Monty Taylor
Added more return value checks.
3297
    if (opt_secure_file_priv == NULL)
3298
      exit(1);
1 by brian
clean slate
3299
  }
3300
}
3301
3302
366 by Patrick Galbraith
Ulong conversion
3303
static uint32_t find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
909 by Brian Aker
Remove the need for unireg init
3304
                                      const char *option)
1 by brian
clean slate
3305
{
366 by Patrick Galbraith
Ulong conversion
3306
  uint32_t res;
1 by brian
clean slate
3307
3308
  const char **ptr;
236.1.40 by Monty Taylor
A few meaningless changes.
3309
366 by Patrick Galbraith
Ulong conversion
3310
  if ((res= find_bit_type(x, bit_lib)) == ~(uint32_t) 0)
1 by brian
clean slate
3311
  {
3312
    ptr= bit_lib->type_names;
3313
    if (!*x)
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
3314
      fprintf(stderr, _("No option given to %s\n"), option);
1 by brian
clean slate
3315
    else
312.1.15 by Monty Taylor
Finished marking strings in drizzled.cc.
3316
      fprintf(stderr, _("Wrong option to %s. Option(s) given: %s\n"),
3317
              option, x);
3318
    fprintf(stderr, _("Alternatives are: '%s'"), *ptr);
1 by brian
clean slate
3319
    while (*++ptr)
3320
      fprintf(stderr, ",'%s'", *ptr);
3321
    fprintf(stderr, "\n");
3322
    exit(1);
3323
  }
3324
  return res;
3325
}
3326
3327
3328
/**
3329
  @return
3330
    a bitfield from a string of substrings separated by ','
3331
    or
366 by Patrick Galbraith
Ulong conversion
3332
    ~(uint32_t) 0 on error.
1 by brian
clean slate
3333
*/
3334
366 by Patrick Galbraith
Ulong conversion
3335
static uint32_t find_bit_type(const char *x, TYPELIB *bit_lib)
1 by brian
clean slate
3336
{
3337
  bool found_end;
3338
  int  found_count;
3339
  const char *end,*i,*j;
3340
  const char **array, *pos;
366 by Patrick Galbraith
Ulong conversion
3341
  uint32_t found,found_int,bit;
1 by brian
clean slate
3342
3343
  found=0;
3344
  found_end= 0;
3345
  pos=(char *) x;
3346
  while (*pos == ' ') pos++;
3347
  found_end= *pos == 0;
3348
  while (!found_end)
3349
  {
266.1.14 by Monty Taylor
Removed strcend.
3350
    if ((end=strrchr(pos,',')) != NULL)		/* Let end point at fieldend */
1 by brian
clean slate
3351
    {
3352
      while (end > pos && end[-1] == ' ')
3353
	end--;					/* Skip end-space */
3354
      found_end=1;
3355
    }
266.1.18 by Monty Taylor
Merged. Plus a few fixes.
3356
    else
3357
    {
3358
        end=pos+strlen(pos);
3359
        found_end=1;
3360
    }
1 by brian
clean slate
3361
    found_int=0; found_count=0;
3362
    for (array=bit_lib->type_names, bit=1 ; (i= *array++) ; bit<<=1)
3363
    {
3364
      j=pos;
3365
      while (j != end)
3366
      {
3367
	if (my_toupper(mysqld_charset,*i++) !=
3368
            my_toupper(mysqld_charset,*j++))
3369
	  goto skip;
3370
      }
3371
      found_int=bit;
3372
      if (! *i)
3373
      {
3374
	found_count=1;
3375
	break;
3376
      }
3377
      else if (j != pos)			// Half field found
3378
      {
3379
	found_count++;				// Could be one of two values
3380
      }
3381
skip: ;
3382
    }
3383
    if (found_count != 1)
366 by Patrick Galbraith
Ulong conversion
3384
      return(~(uint32_t) 0);				// No unique value
1 by brian
clean slate
3385
    found|=found_int;
3386
    pos=end+1;
3387
  }
3388
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
3389
  return(found);
1 by brian
clean slate
3390
} /* find_bit_type */
3391
3392
722.2.12 by Monty Taylor
Removed assert(0); Added function ptr in libdrizzle.
3393
bool safe_read_error_impl(NET *net)
3394
{
3395
  if (net->vio)
840.1.19 by Monty Taylor
Renamed vio.
3396
    return drizzleclient_vio_was_interrupted(net->vio);
722.2.12 by Monty Taylor
Removed assert(0); Added function ptr in libdrizzle.
3397
  return false;
3398
}
3399
1 by brian
clean slate
3400
3401
/*****************************************************************************
3402
  Instantiate templates
3403
*****************************************************************************/
3404
3405
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3406
/* Used templates */
520.1.21 by Brian Aker
THD -> Session rename
3407
template class I_List<Session>;
3408
template class I_List_iterator<Session>;
1 by brian
clean slate
3409
template class I_List<i_string>;
3410
template class I_List<i_string_pair>;
3411
template class I_List<NAMED_LIST>;
3412
template class I_List<Statement>;
3413
template class I_List_iterator<Statement>;
3414
#endif