~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20
15
 
21
16
#include <drizzled/server_includes.h>
22
 
 
23
 
#include <netdb.h>
 
17
#include <mysys/my_bit.h>
 
18
#include "slave.h"
 
19
#include "rpl_mi.h"
 
20
#include "sql_repl.h"
 
21
#include "rpl_filter.h"
 
22
#include "repl_failsafe.h"
 
23
#include "stacktrace.h"
 
24
#include "mysqld_suffix.h"
 
25
#include <mysys/mysys_err.h>
24
26
#include <sys/poll.h>
25
27
#include <netinet/tcp.h>
26
 
#include <signal.h>
27
 
 
28
 
#include <mysys/my_bit.h>
29
 
#include <drizzled/slave.h>
30
 
#include <drizzled/rpl_mi.h>
31
 
#include <drizzled/sql_repl.h>
32
 
#include <drizzled/rpl_filter.h>
33
 
#include <drizzled/stacktrace.h>
34
 
#include <mysys/mysys_err.h>
35
 
#include <drizzled/error.h>
36
 
#include <drizzled/tztime.h>
37
 
 
38
 
#if TIME_WITH_SYS_TIME
39
 
# include <sys/time.h>
40
 
# include <time.h>
41
 
#else
42
 
# if HAVE_SYS_TIME_H
43
 
#  include <sys/time.h>
44
 
# else
45
 
#  include <time.h>
46
 
# endif
47
 
#endif
 
28
#include <drizzled/drizzled_error_messages.h>
48
29
 
49
30
#include <storage/myisam/ha_myisam.h>
50
31
 
68
49
#define IF_PURIFY(A,B) (B)
69
50
#endif
70
51
 
71
 
#define MAX_MEM_TABLE_SIZE SIZE_MAX
 
52
#if SIZEOF_CHARP == 4
 
53
#define MAX_MEM_TABLE_SIZE ~(uint32_t) 0
 
54
#else
 
55
#define MAX_MEM_TABLE_SIZE ~(uint64_t) 0
 
56
#endif
72
57
 
73
58
/* We have HAVE_purify below as this speeds up the shutdown of MySQL */
74
59
 
79
64
extern "C" {                                    // Because of SCO 3.2V4.2
80
65
#include <errno.h>
81
66
#include <sys/stat.h>
 
67
#ifndef __GNU_LIBRARY__
 
68
#define __GNU_LIBRARY__                         // Skip warnings in getopt.h
 
69
#endif
82
70
#include <mysys/my_getopt.h>
83
71
#ifdef HAVE_SYSENT_H
84
72
#include <sysent.h>
160
148
 
161
149
#include <mysys/my_pthread.h>                   // For thr_setconcurency()
162
150
 
163
 
#include <drizzled/gettext.h>
 
151
#include <libdrizzle/gettext.h>
164
152
 
165
153
#ifdef SOLARIS
166
154
extern "C" int gethostname(char *name, int namelen);
167
155
#endif
168
156
 
169
 
extern "C" RETSIGTYPE handle_segfault(int sig);
 
157
extern "C" sig_handler handle_segfault(int sig);
170
158
 
171
159
/* Constants */
172
160
 
179
167
static const char *optimizer_switch_names[]=
180
168
{
181
169
  "no_materialization", "no_semijoin",
182
 
  NULL
 
170
  NullS
183
171
};
184
172
 
185
173
/* Corresponding defines are named OPTIMIZER_SWITCH_XXX */
195
183
 
196
184
static const char *tc_heuristic_recover_names[]=
197
185
{
198
 
  "COMMIT", "ROLLBACK", NULL
 
186
  "COMMIT", "ROLLBACK", NullS
199
187
};
200
188
static TYPELIB tc_heuristic_recover_typelib=
201
189
{
205
193
 
206
194
const char *first_keyword= "first", *binary_keyword= "BINARY";
207
195
const char *my_localhost= "localhost";
 
196
#if SIZEOF_OFF_T > 4 && defined(BIG_TABLES)
208
197
#define GET_HA_ROWS GET_ULL
 
198
#else
 
199
#define GET_HA_ROWS GET_ULONG
 
200
#endif
209
201
 
210
202
/*
211
203
  Used with --help for detailed option
219
211
 {&Arg_comparator::compare_row,        &Arg_comparator::compare_e_row},
220
212
 {&Arg_comparator::compare_decimal,    &Arg_comparator::compare_e_decimal}};
221
213
 
222
 
const char *log_output_names[] = { "NONE", "FILE", NULL};
 
214
const char *log_output_names[] = { "NONE", "FILE", NullS};
223
215
static const unsigned int log_output_names_len[]= { 4, 4, 0 };
224
216
TYPELIB log_output_typelib= {array_elements(log_output_names)-1,"",
225
217
                             log_output_names,
231
223
static bool volatile select_thread_in_use, signal_thread_in_use;
232
224
static bool volatile ready_to_exit;
233
225
static bool opt_debugging= 0, opt_console= 0;
234
 
static uint32_t wake_thread;
 
226
static uint kill_cached_threads, wake_thread;
235
227
static uint32_t killed_threads, thread_created;
236
228
static uint32_t max_used_connections;
237
 
static char *drizzled_user, *drizzled_chroot, *log_error_file_ptr;
 
229
static volatile uint32_t cached_thread_count= 0;
 
230
static char *mysqld_user, *mysqld_chroot, *log_error_file_ptr;
238
231
static char *opt_init_slave, *language_ptr, *opt_init_connect;
239
232
static char *default_character_set_name;
240
233
static char *character_set_filesystem_name;
243
236
static char *default_collation_name;
244
237
static char *default_storage_engine_str;
245
238
static char compiled_default_collation_name[]= DRIZZLE_DEFAULT_COLLATION_NAME;
246
 
static I_List<Session> thread_cache;
 
239
static I_List<THD> thread_cache;
 
240
static double long_query_time;
 
241
 
 
242
static pthread_cond_t COND_thread_cache, COND_flush_thread_cache;
247
243
 
248
244
/* Global variables */
249
245
 
250
246
bool opt_bin_log;
 
247
bool opt_log;
 
248
bool opt_slow_log;
251
249
ulong log_output_options;
252
250
bool opt_log_queries_not_using_indexes= false;
253
251
bool opt_error_log= 0;
279
277
bool opt_readonly;
280
278
bool use_temp_pool;
281
279
bool relay_log_purge;
 
280
bool opt_secure_auth= false;
282
281
char* opt_secure_file_priv= 0;
 
282
bool opt_log_slow_admin_statements= 0;
 
283
bool opt_log_slow_slave_statements= 0;
 
284
bool opt_old_style_user_limits= 0;
 
285
bool trust_function_creators= 0;
283
286
/*
284
287
  True if there is at least one per-hour limit for some user, so we should
285
288
  check them before each query (and possibly reset counters when hour is
288
291
bool opt_noacl;
289
292
 
290
293
ulong opt_binlog_rows_event_max_size;
291
 
const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NULL};
 
294
const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NullS};
292
295
TYPELIB binlog_format_typelib=
293
296
  { array_elements(binlog_format_names) - 1, "",
294
297
    binlog_format_names, NULL };
297
300
#ifdef HAVE_INITGROUPS
298
301
static bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
299
302
#endif
300
 
uint32_t drizzled_port, test_flags, select_errors, dropping_tables, ha_open_options;
301
 
uint32_t drizzled_port_timeout;
302
 
uint32_t delay_key_write_options, protocol_version;
303
 
uint32_t lower_case_table_names= 1;
304
 
uint32_t tc_heuristic_recover= 0;
305
 
uint32_t volatile thread_count, thread_running;
306
 
uint64_t session_startup_options;
307
 
ulong back_log, connect_timeout;
308
 
uint32_t server_id;
 
303
uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options;
 
304
uint mysqld_port_timeout;
 
305
uint delay_key_write_options, protocol_version;
 
306
uint lower_case_table_names= 1;
 
307
uint tc_heuristic_recover= 0;
 
308
uint volatile thread_count, thread_running;
 
309
uint64_t thd_startup_options;
 
310
ulong back_log, connect_timeout, server_id;
309
311
ulong table_cache_size, table_def_size;
310
312
ulong what_to_log;
311
313
ulong slow_launch_time, slave_open_temp_tables;
322
324
ulong binlog_cache_size= 0;
323
325
ulong max_binlog_cache_size= 0;
324
326
uint32_t refresh_version;  /* Increments on each reload */
 
327
query_id_t global_query_id;
325
328
ulong aborted_threads;
326
329
ulong aborted_connects;
327
330
ulong specialflag= 0;
329
332
ulong binlog_cache_disk_use= 0;
330
333
ulong max_connections;
331
334
ulong max_connect_errors;
332
 
uint32_t  max_user_connections= 0;
 
335
uint  max_user_connections= 0;
333
336
ulong thread_id=1L;
334
337
ulong current_pid;
335
338
ulong slow_launch_threads = 0;
381
384
     language[FN_REFLEN], reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN],
382
385
     *opt_init_file, *opt_tc_log_file;
383
386
char mysql_unpacked_real_data_home[FN_REFLEN];
384
 
uint32_t reg_ext_length;
 
387
uint reg_ext_length;
385
388
const key_map key_map_empty(0);
386
389
key_map key_map_full(0);                        // Will be initialized later
387
390
 
388
391
const char *opt_date_time_formats[3];
389
392
 
390
 
uint32_t mysql_data_home_len;
 
393
uint mysql_data_home_len;
391
394
char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home;
392
395
char server_version[SERVER_VERSION_LENGTH];
393
396
char *opt_mysql_tmpdir;
411
414
 
412
415
FILE *stderror_file=0;
413
416
 
414
 
I_List<Session> threads;
 
417
I_List<THD> threads;
415
418
I_List<NAMED_LIST> key_caches;
416
419
Rpl_filter* rpl_filter;
417
420
Rpl_filter* binlog_filter;
434
437
 
435
438
/* Thread specific variables */
436
439
 
437
 
pthread_key_t THR_MALLOC;
438
 
pthread_key_t THR_Session;
 
440
pthread_key(MEM_ROOT**,THR_MALLOC);
 
441
pthread_key(THD*, THR_THD);
439
442
pthread_mutex_t LOCK_mysql_create_db, LOCK_open, LOCK_thread_count,
440
 
                LOCK_status,
441
 
                LOCK_global_read_lock,
442
 
                LOCK_error_log,
443
 
                LOCK_global_system_variables,
444
 
                LOCK_slave_list, 
445
 
                LOCK_active_mi,
 
443
                LOCK_status, LOCK_global_read_lock,
 
444
                LOCK_error_log, LOCK_uuid_generator,
 
445
                LOCK_global_system_variables,
 
446
                LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
446
447
                LOCK_connection_count;
447
448
 
448
449
rw_lock_t       LOCK_sys_init_connect, LOCK_sys_init_slave;
453
454
pthread_cond_t  COND_server_started;
454
455
 
455
456
/* replication parameters, if master_host is not NULL, we are a slave */
456
 
uint32_t report_port= DRIZZLE_PORT;
 
457
uint report_port= DRIZZLE_PORT;
457
458
uint32_t master_retry_count= 0;
458
459
char *master_info_file;
459
 
char *relay_log_info_file;
460
 
char *report_host;
 
460
char *relay_log_info_file, *report_user, *report_password, *report_host;
461
461
char *opt_relay_logname = 0, *opt_relaylog_index_name=0;
462
 
char *opt_logname;
 
462
char *opt_logname, *opt_slow_logname;
463
463
 
464
464
/* Static variables */
465
465
 
471
471
static uint32_t opt_myisam_block_size;
472
472
static char *opt_binlog_index_name;
473
473
static char *opt_tc_heuristic_recover;
474
 
static char *drizzle_home_ptr, *pidfile_name_ptr;
 
474
static char *mysql_home_ptr, *pidfile_name_ptr;
475
475
static int defaults_argc;
476
476
static char **defaults_argv;
477
477
static char *opt_bin_logname;
478
478
 
479
 
struct rand_struct sql_rand; ///< used by sql_class.cc:Session::Session()
 
479
struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD()
480
480
 
481
481
struct passwd *user_info;
482
482
static pthread_t select_thread;
483
 
static uint32_t thr_kill_signal;
 
483
static uint thr_kill_signal;
484
484
 
485
485
/* OS specific variables */
486
486
 
492
492
  Number of currently active user connections. The variable is protected by
493
493
  LOCK_connection_count.
494
494
*/
495
 
uint32_t connection_count= 0;
 
495
uint connection_count= 0;
496
496
 
497
497
/* Function declarations */
498
498
 
499
499
pthread_handler_t signal_hand(void *arg);
500
 
static void drizzle_init_variables(void);
 
500
static void mysql_init_variables(void);
501
501
static void get_options(int *argc,char **argv);
502
502
extern "C" bool mysqld_get_one_option(int, const struct my_option *, char *);
503
503
static void set_server_version(void);
518
518
static void clean_up_mutexes(void);
519
519
static void wait_for_signal_thread_to_end(void);
520
520
static void create_pid_file();
521
 
static void drizzled_exit(int exit_code) __attribute__((noreturn));
 
521
static void mysqld_exit(int exit_code) __attribute__((noreturn));
522
522
 
523
523
/****************************************************************************
524
524
** Code to end mysqld
530
530
  int count=0;
531
531
#endif
532
532
 
 
533
  /* Clear thread cache */
 
534
  kill_cached_threads++;
 
535
  flush_thread_cache();
 
536
 
533
537
  /* kill connection thread */
534
538
  (void) pthread_mutex_lock(&LOCK_thread_count);
535
539
 
543
547
      break;                                    // allready dead
544
548
#endif
545
549
    set_timespec(abstime, 2);
546
 
    for (uint32_t tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
 
550
    for (uint tmp=0 ; tmp < 10 && select_thread_in_use; tmp++)
547
551
    {
548
552
      error=pthread_cond_timedwait(&COND_thread_count,&LOCK_thread_count,
549
553
                                   &abstime);
582
586
    statements and inform their clients that the server is about to die.
583
587
  */
584
588
 
585
 
  Session *tmp;
 
589
  THD *tmp;
586
590
  (void) pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
587
591
 
588
 
  I_List_iterator<Session> it(threads);
 
592
  I_List_iterator<THD> it(threads);
589
593
  while ((tmp=it++))
590
594
  {
591
595
    /* We skip slave threads & scheduler on this first loop through. */
592
596
    if (tmp->slave_thread)
593
597
      continue;
594
598
 
595
 
    tmp->killed= Session::KILL_CONNECTION;
 
599
    tmp->killed= THD::KILL_CONNECTION;
596
600
    thread_scheduler.post_kill_notification(tmp);
597
601
    if (tmp->mysys_var)
598
602
    {
600
604
      pthread_mutex_lock(&tmp->mysys_var->mutex);
601
605
      if (tmp->mysys_var->current_cond)
602
606
      {
603
 
        pthread_mutex_lock(tmp->mysys_var->current_mutex);
604
 
        pthread_cond_broadcast(tmp->mysys_var->current_cond);
605
 
        pthread_mutex_unlock(tmp->mysys_var->current_mutex);
 
607
        pthread_mutex_lock(tmp->mysys_var->current_mutex);
 
608
        pthread_cond_broadcast(tmp->mysys_var->current_cond);
 
609
        pthread_mutex_unlock(tmp->mysys_var->current_mutex);
606
610
      }
607
611
      pthread_mutex_unlock(&tmp->mysys_var->mutex);
608
612
    }
756
760
#endif
757
761
 
758
762
 
759
 
extern "C" RETSIGTYPE print_signal_warning(int sig)
 
763
extern "C" sig_handler print_signal_warning(int sig)
760
764
{
761
765
  if (global_system_variables.log_warnings)
762
 
    sql_print_warning(_("Got signal %d from thread %"PRIu64), sig,my_thread_id());
763
 
#ifndef HAVE_BSD_SIGNALS
 
766
    sql_print_warning(_("Got signal %d from thread %ld"), sig,my_thread_id());
 
767
#ifdef DONT_REMEMBER_SIGNAL
764
768
  my_sigset(sig,print_signal_warning);          /* int. thread system calls */
765
769
#endif
766
770
  if (sig == SIGALRM)
797
801
  else if (opt_help)
798
802
    usage();
799
803
  clean_up(!opt_help && (exit_code)); /* purecov: inspected */
800
 
  drizzled_exit(exit_code);
 
804
  mysqld_exit(exit_code);
801
805
}
802
806
 
803
807
 
804
 
static void drizzled_exit(int exit_code)
 
808
static void mysqld_exit(int exit_code)
805
809
{
806
810
  wait_for_signal_thread_to_end();
807
811
  clean_up_mutexes();
815
819
  if (cleanup_done++)
816
820
    return; /* purecov: inspected */
817
821
 
 
822
  /*
 
823
    make sure that handlers finish up
 
824
    what they have that is dependent on the binlog
 
825
  */
 
826
  ha_binlog_end(current_thd);
 
827
 
818
828
  logger.cleanup_base();
819
829
 
820
830
  mysql_bin_log.cleanup();
834
844
  if (tc_log)
835
845
    tc_log->close();
836
846
  xid_cache_free();
837
 
  delete_elements(&key_caches, (void (*)(const char*, unsigned char*)) free_key_cache);
 
847
  delete_elements(&key_caches, (void (*)(const char*, uchar*)) free_key_cache);
838
848
  multi_keycache_free();
839
849
  free_status_vars();
840
850
  end_thr_alarm(1);                     /* Free allocated memory */
841
851
  my_free_open_file_info();
842
 
  free((char*) global_system_variables.date_format);
843
 
  free((char*) global_system_variables.time_format);
844
 
  free((char*) global_system_variables.datetime_format);
 
852
  my_free((char*) global_system_variables.date_format,
 
853
          MYF(MY_ALLOW_ZERO_PTR));
 
854
  my_free((char*) global_system_variables.time_format,
 
855
          MYF(MY_ALLOW_ZERO_PTR));
 
856
  my_free((char*) global_system_variables.datetime_format,
 
857
          MYF(MY_ALLOW_ZERO_PTR));
845
858
  if (defaults_argv)
846
859
    free_defaults(defaults_argv);
847
 
  free(sys_init_connect.value);
848
 
  free(sys_init_slave.value);
 
860
  my_free(sys_init_connect.value, MYF(MY_ALLOW_ZERO_PTR));
 
861
  my_free(sys_init_slave.value, MYF(MY_ALLOW_ZERO_PTR));
 
862
  my_free(sys_var_general_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
 
863
  my_free(sys_var_slow_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
849
864
  free_tmpdir(&mysql_tmpdir_list);
850
 
  free(slave_load_tmpdir);
851
 
  if (opt_bin_logname)
852
 
    free(opt_bin_logname);
853
 
  if (opt_relay_logname)
854
 
    free(opt_relay_logname);
855
 
  if (opt_secure_file_priv)
856
 
    free(opt_secure_file_priv);
 
865
  my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR));
 
866
  x_free(opt_bin_logname);
 
867
  x_free(opt_relay_logname);
 
868
  x_free(opt_secure_file_priv);
857
869
  bitmap_free(&temp_pool);
 
870
  end_slave_list();
858
871
  delete binlog_filter;
859
872
  delete rpl_filter;
860
873
 
868
881
  (void *)my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST);
869
882
  // TODO!!!! EPIC FAIL!!!! This sefaults if uncommented.
870
883
/*  if (freeme != NULL)
871
 
    free(freeme);  */
 
884
    my_free(freeme, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));  */
872
885
  /* Tell main we are ready */
873
886
  logger.cleanup_end();
874
887
  (void) pthread_mutex_lock(&LOCK_thread_count);
890
903
*/
891
904
static void wait_for_signal_thread_to_end()
892
905
{
893
 
  uint32_t i;
 
906
  uint i;
894
907
  /*
895
908
    Wait up to 10 seconds for signal thread to die. We use this mainly to
896
909
    avoid getting warnings that my_thread_end has not been called
912
925
  (void) pthread_mutex_destroy(&LOCK_thread_count);
913
926
  (void) pthread_mutex_destroy(&LOCK_status);
914
927
  (void) pthread_mutex_destroy(&LOCK_error_log);
 
928
  (void) pthread_mutex_destroy(&LOCK_user_conn);
915
929
  (void) pthread_mutex_destroy(&LOCK_connection_count);
 
930
  (void) pthread_mutex_destroy(&LOCK_rpl_status);
 
931
  (void) pthread_cond_destroy(&COND_rpl_status);
916
932
  (void) pthread_mutex_destroy(&LOCK_active_mi);
917
933
  (void) rwlock_destroy(&LOCK_sys_init_connect);
918
934
  (void) rwlock_destroy(&LOCK_sys_init_slave);
919
935
  (void) pthread_mutex_destroy(&LOCK_global_system_variables);
920
936
  (void) rwlock_destroy(&LOCK_system_variables_hash);
921
937
  (void) pthread_mutex_destroy(&LOCK_global_read_lock);
 
938
  (void) pthread_mutex_destroy(&LOCK_uuid_generator);
922
939
  (void) pthread_cond_destroy(&COND_thread_count);
923
940
  (void) pthread_cond_destroy(&COND_refresh);
924
941
  (void) pthread_cond_destroy(&COND_global_read_lock);
 
942
  (void) pthread_cond_destroy(&COND_thread_cache);
 
943
  (void) pthread_cond_destroy(&COND_flush_thread_cache);
925
944
}
926
945
 
927
946
 
932
951
static void set_ports()
933
952
{
934
953
  char  *env;
935
 
  if (!drizzled_port)
 
954
  if (!mysqld_port)
936
955
  {                                     // Get port if not from commandline
937
 
    drizzled_port= DRIZZLE_PORT;
 
956
    mysqld_port= DRIZZLE_PORT;
938
957
 
939
958
    /*
940
959
      if builder specifically requested a default port, use that
948
967
 
949
968
    struct  servent *serv_ptr;
950
969
    if ((serv_ptr= getservbyname("drizzle", "tcp")))
951
 
      drizzled_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
 
970
      mysqld_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
952
971
 
953
972
    if ((env = getenv("DRIZZLE_TCP_PORT")))
954
 
      drizzled_port= (uint) atoi(env);          /* purecov: inspected */
 
973
      mysqld_port= (uint) atoi(env);            /* purecov: inspected */
955
974
 
956
 
    assert(drizzled_port);
 
975
    assert(mysqld_port);
957
976
  }
958
977
}
959
978
 
1081
1100
static void network_init(void)
1082
1101
{
1083
1102
  int   ret;
1084
 
  uint32_t  waited;
1085
 
  uint32_t  this_wait;
1086
 
  uint32_t  retry;
 
1103
  uint  waited;
 
1104
  uint  this_wait;
 
1105
  uint  retry;
1087
1106
  char port_buf[NI_MAXSERV];
1088
1107
  struct addrinfo *ai;
1089
1108
  struct addrinfo *next;
1100
1119
  hints.ai_flags= AI_PASSIVE;
1101
1120
  hints.ai_socktype= SOCK_STREAM;
1102
1121
 
1103
 
  snprintf(port_buf, NI_MAXSERV, "%d", drizzled_port);
 
1122
  snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1104
1123
  error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1105
1124
  if (error != 0)
1106
1125
  {
1173
1192
      on busy Linux systems. Retry to bind the address at these intervals:
1174
1193
      Sleep intervals: 1, 2, 4,  6,  9, 13, 17, 22, ...
1175
1194
      Retry at second: 1, 3, 7, 13, 22, 35, 52, 74, ...
1176
 
      Limit the sequence by drizzled_port_timeout (set --port-open-timeout=#).
 
1195
      Limit the sequence by mysqld_port_timeout (set --port-open-timeout=#).
1177
1196
    */
1178
1197
    for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
1179
1198
    {
1180
1199
      if (((ret= bind(ip_sock, next->ai_addr, next->ai_addrlen)) >= 0 ) ||
1181
 
          (errno != EADDRINUSE) ||
1182
 
          (waited >= drizzled_port_timeout))
 
1200
          (socket_errno != SOCKET_EADDRINUSE) ||
 
1201
          (waited >= mysqld_port_timeout))
1183
1202
        break;
1184
 
      sql_print_information(_("Retrying bind on TCP/IP port %u"), drizzled_port);
 
1203
      sql_print_information(_("Retrying bind on TCP/IP port %u"), mysqld_port);
1185
1204
      this_wait= retry * retry / 3 + 1;
1186
1205
      sleep(this_wait);
1187
1206
    }
1189
1208
    {
1190
1209
      sql_perror(_("Can't start server: Bind on TCP/IP port"));
1191
1210
      sql_print_error(_("Do you already have another drizzled server running "
1192
 
                        "on port: %d ?"),drizzled_port);
 
1211
                        "on port: %d ?"),mysqld_port);
1193
1212
      unireg_abort(1);
1194
1213
    }
1195
1214
    if (listen(ip_sock,(int) back_log) < 0)
1196
1215
    {
1197
1216
      sql_perror(_("Can't start server: listen() on TCP/IP port"));
1198
1217
      sql_print_error(_("listen() on TCP/IP failed with error %d"),
1199
 
                      errno);
 
1218
                      socket_errno);
1200
1219
      unireg_abort(1);
1201
1220
    }
1202
1221
  }
1208
1227
/**
1209
1228
  Close a connection.
1210
1229
 
1211
 
  @param session                Thread handle
 
1230
  @param thd            Thread handle
1212
1231
  @param errcode        Error code to print to console
1213
1232
  @param lock           1 if we have have to lock LOCK_thread_count
1214
1233
 
1215
1234
  @note
1216
1235
    For the connection that is doing shutdown, this is called twice
1217
1236
*/
1218
 
void close_connection(Session *session, uint32_t errcode, bool lock)
 
1237
void close_connection(THD *thd, uint errcode, bool lock)
1219
1238
{
1220
1239
  st_vio *vio;
1221
1240
  if (lock)
1222
1241
    (void) pthread_mutex_lock(&LOCK_thread_count);
1223
 
  session->killed= Session::KILL_CONNECTION;
1224
 
  if ((vio= session->net.vio) != 0)
 
1242
  thd->killed= THD::KILL_CONNECTION;
 
1243
  if ((vio= thd->net.vio) != 0)
1225
1244
  {
1226
1245
    if (errcode)
1227
 
      net_send_error(session, errcode, ER(errcode)); /* purecov: inspected */
1228
 
    net_close(&(session->net));         /* vio is freed in delete session */
 
1246
      net_send_error(thd, errcode, ER(errcode)); /* purecov: inspected */
 
1247
    net_close(&(thd->net));             /* vio is freed in delete thd */
1229
1248
  }
1230
1249
  if (lock)
1231
1250
    (void) pthread_mutex_unlock(&LOCK_thread_count);
1235
1254
 
1236
1255
/** Called when a thread is aborted. */
1237
1256
/* ARGSUSED */
1238
 
extern "C" RETSIGTYPE end_thread_signal(int sig __attribute__((unused)))
 
1257
extern "C" sig_handler end_thread_signal(int sig __attribute__((unused)))
1239
1258
{
1240
 
  Session *session=current_session;
1241
 
  if (session)
 
1259
  THD *thd=current_thd;
 
1260
  if (thd && ! thd->bootstrap)
1242
1261
  {
1243
1262
    statistic_increment(killed_threads, &LOCK_status);
1244
 
    thread_scheduler.end_thread(session,0);             /* purecov: inspected */
 
1263
    thread_scheduler.end_thread(thd,0);         /* purecov: inspected */
1245
1264
  }
1246
1265
  return;;                              /* purecov: deadcode */
1247
1266
}
1248
1267
 
1249
1268
 
1250
1269
/*
1251
 
  Unlink session from global list of available connections and free session
 
1270
  Unlink thd from global list of available connections and free thd
1252
1271
 
1253
1272
  SYNOPSIS
1254
 
    unlink_session()
1255
 
    session              Thread handler
 
1273
    unlink_thd()
 
1274
    thd          Thread handler
1256
1275
 
1257
1276
  NOTES
1258
1277
    LOCK_thread_count is locked and left locked
1259
1278
*/
1260
1279
 
1261
 
void unlink_session(Session *session)
 
1280
void unlink_thd(THD *thd)
1262
1281
{
1263
 
  session->cleanup();
 
1282
  thd->cleanup();
1264
1283
 
1265
1284
  pthread_mutex_lock(&LOCK_connection_count);
1266
1285
  --connection_count;
1268
1287
 
1269
1288
  (void) pthread_mutex_lock(&LOCK_thread_count);
1270
1289
  thread_count--;
1271
 
  delete session;
 
1290
  delete thd;
1272
1291
  return;;
1273
1292
}
1274
1293
 
1275
1294
 
 
1295
/*
 
1296
  Store thread in cache for reuse by new connections
 
1297
 
 
1298
  SYNOPSIS
 
1299
    cache_thread()
 
1300
 
 
1301
  NOTES
 
1302
    LOCK_thread_count has to be locked
 
1303
 
 
1304
  RETURN
 
1305
    0  Thread was not put in cache
 
1306
    1  Thread is to be reused by new connection.
 
1307
       (ie, caller should return, not abort with pthread_exit())
 
1308
*/
 
1309
 
 
1310
 
 
1311
static bool cache_thread()
 
1312
{
 
1313
  safe_mutex_assert_owner(&LOCK_thread_count);
 
1314
  if (cached_thread_count < thread_cache_size &&
 
1315
      ! abort_loop && !kill_cached_threads)
 
1316
  {
 
1317
    /* Don't kill the thread, just put it in cache for reuse */
 
1318
    cached_thread_count++;
 
1319
    while (!abort_loop && ! wake_thread && ! kill_cached_threads)
 
1320
      (void) pthread_cond_wait(&COND_thread_cache, &LOCK_thread_count);
 
1321
    cached_thread_count--;
 
1322
    if (kill_cached_threads)
 
1323
      pthread_cond_signal(&COND_flush_thread_cache);
 
1324
    if (wake_thread)
 
1325
    {
 
1326
      THD *thd;
 
1327
      wake_thread--;
 
1328
      thd= thread_cache.get();
 
1329
      thd->thread_stack= (char*) &thd;          // For store_globals
 
1330
      (void) thd->store_globals();
 
1331
      /*
 
1332
        THD::mysys_var::abort is associated with physical thread rather
 
1333
        than with THD object. So we need to reset this flag before using
 
1334
        this thread for handling of new THD object/connection.
 
1335
      */
 
1336
      thd->mysys_var->abort= 0;
 
1337
      thd->thr_create_utime= my_micro_time();
 
1338
      threads.append(thd);
 
1339
      return(1);
 
1340
    }
 
1341
  }
 
1342
  return(0);
 
1343
}
 
1344
 
 
1345
 
 
1346
/*
 
1347
  End thread for the current connection
 
1348
 
 
1349
  SYNOPSIS
 
1350
    one_thread_per_connection_end()
 
1351
    thd           Thread handler
 
1352
    put_in_cache  Store thread in cache, if there is room in it
 
1353
                  Normally this is true in all cases except when we got
 
1354
                  out of resources initializing the current thread
 
1355
 
 
1356
  NOTES
 
1357
    If thread is cached, we will wait until thread is scheduled to be
 
1358
    reused and then we will return.
 
1359
    If thread is not cached, we end the thread.
 
1360
 
 
1361
  RETURN
 
1362
    0    Signal to handle_one_connection to reuse connection
 
1363
*/
 
1364
 
 
1365
bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
 
1366
{
 
1367
  unlink_thd(thd);
 
1368
  if (put_in_cache)
 
1369
    put_in_cache= cache_thread();
 
1370
  pthread_mutex_unlock(&LOCK_thread_count);
 
1371
  if (put_in_cache)
 
1372
    return(0);                             // Thread is reused
 
1373
 
 
1374
  /* It's safe to broadcast outside a lock (COND... is not deleted here) */
 
1375
  my_thread_end();
 
1376
  (void) pthread_cond_broadcast(&COND_thread_count);
 
1377
 
 
1378
  pthread_exit(0);
 
1379
  return(0);                               // Impossible
 
1380
}
 
1381
 
 
1382
 
 
1383
void flush_thread_cache()
 
1384
{
 
1385
  (void) pthread_mutex_lock(&LOCK_thread_count);
 
1386
  kill_cached_threads++;
 
1387
  while (cached_thread_count)
 
1388
  {
 
1389
    pthread_cond_broadcast(&COND_thread_cache);
 
1390
    pthread_cond_wait(&COND_flush_thread_cache,&LOCK_thread_count);
 
1391
  }
 
1392
  kill_cached_threads--;
 
1393
  (void) pthread_mutex_unlock(&LOCK_thread_count);
 
1394
}
 
1395
 
 
1396
 
1276
1397
#ifdef THREAD_SPECIFIC_SIGPIPE
1277
1398
/**
1278
1399
  Aborts a thread nicely. Comes here on SIGPIPE.
1280
1401
  @todo
1281
1402
    One should have to fix that thr_alarm know about this thread too.
1282
1403
*/
1283
 
extern "C" RETSIGTYPE abort_thread(int sig __attribute__((unused)))
 
1404
extern "C" sig_handler abort_thread(int sig __attribute__((unused)))
1284
1405
{
1285
 
  Session *session=current_session;
1286
 
  if (session)
1287
 
    session->killed= Session::KILL_CONNECTION;
 
1406
  THD *thd=current_thd;
 
1407
  if (thd)
 
1408
    thd->killed= THD::KILL_CONNECTION;
1288
1409
  return;;
1289
1410
}
1290
1411
#endif
1291
1412
 
1292
 
#if defined(BACKTRACE_DEMANGLE)
 
1413
#if BACKTRACE_DEMANGLE
1293
1414
#include <cxxabi.h>
1294
1415
extern "C" char *my_demangle(const char *mangled_name, int *status)
1295
1416
{
1298
1419
#endif
1299
1420
 
1300
1421
 
1301
 
extern "C" RETSIGTYPE handle_segfault(int sig)
 
1422
extern "C" sig_handler handle_segfault(int sig)
1302
1423
{
1303
1424
  time_t curr_time;
1304
1425
  struct tm tm;
1350
1471
                     (global_system_variables.read_buff_size +
1351
1472
                      global_system_variables.sortbuff_size) *
1352
1473
                     thread_scheduler.max_threads +
1353
 
                     max_connections * sizeof(Session)) / 1024);
 
1474
                     max_connections * sizeof(THD)) / 1024);
1354
1475
 
1355
1476
#ifdef HAVE_STACKTRACE
1356
 
  Session *session= current_session;
 
1477
  THD *thd= current_thd;
1357
1478
 
1358
1479
  if (!(test_flags & TEST_NO_STACKTRACE))
1359
1480
  {
1360
 
    fprintf(stderr,"session: 0x%lx\n",(long) session);
 
1481
    fprintf(stderr,"thd: 0x%lx\n",(long) thd);
1361
1482
    fprintf(stderr,_("Attempting backtrace. You can use the following "
1362
1483
                     "information to find out\n"
1363
1484
                     "where mysqld died. If you see no messages after this, "
1364
1485
                     "something went\n"
1365
1486
                     "terribly wrong...\n"));
1366
 
    print_stacktrace(session ? (unsigned char*) session->thread_stack : (unsigned char*) 0,
 
1487
    print_stacktrace(thd ? (uchar*) thd->thread_stack : (uchar*) 0,
1367
1488
                     my_thread_stack_size);
1368
1489
  }
1369
 
  if (session)
 
1490
  if (thd)
1370
1491
  {
1371
1492
    const char *kreason= "UNKNOWN";
1372
 
    switch (session->killed) {
1373
 
    case Session::NOT_KILLED:
 
1493
    switch (thd->killed) {
 
1494
    case THD::NOT_KILLED:
1374
1495
      kreason= "NOT_KILLED";
1375
1496
      break;
1376
 
    case Session::KILL_BAD_DATA:
 
1497
    case THD::KILL_BAD_DATA:
1377
1498
      kreason= "KILL_BAD_DATA";
1378
1499
      break;
1379
 
    case Session::KILL_CONNECTION:
 
1500
    case THD::KILL_CONNECTION:
1380
1501
      kreason= "KILL_CONNECTION";
1381
1502
      break;
1382
 
    case Session::KILL_QUERY:
 
1503
    case THD::KILL_QUERY:
1383
1504
      kreason= "KILL_QUERY";
1384
1505
      break;
1385
 
    case Session::KILLED_NO_VALUE:
 
1506
    case THD::KILLED_NO_VALUE:
1386
1507
      kreason= "KILLED_NO_VALUE";
1387
1508
      break;
1388
1509
    }
1389
1510
    fprintf(stderr, _("Trying to get some variables.\n"
1390
1511
                      "Some pointers may be invalid and cause the "
1391
1512
                      "dump to abort...\n"));
1392
 
    safe_print_str("session->query", session->query, 1024);
1393
 
    fprintf(stderr, "session->thread_id=%"PRIu32"\n", (uint32_t) session->thread_id);
1394
 
    fprintf(stderr, "session->killed=%s\n", kreason);
 
1513
    safe_print_str("thd->query", thd->query, 1024);
 
1514
    fprintf(stderr, "thd->thread_id=%"PRIu32"\n", (uint32_t) thd->thread_id);
 
1515
    fprintf(stderr, "thd->killed=%s\n", kreason);
1395
1516
  }
1396
1517
  fflush(stderr);
1397
1518
#endif /* HAVE_STACKTRACE */
1647
1768
      sql_print_information(_("Got signal %d to shutdown mysqld"),sig);
1648
1769
#endif
1649
1770
      /* switch to the old log message processing */
 
1771
      logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
 
1772
                          opt_log ? LOG_FILE:LOG_NONE);
1650
1773
      if (!abort_loop)
1651
1774
      {
1652
1775
        abort_loop=1;                           // mark abort for threads
1671
1794
      if (!abort_loop)
1672
1795
      {
1673
1796
        bool not_used;
1674
 
        reload_cache((Session*) 0,
 
1797
        reload_cache((THD*) 0,
1675
1798
                     (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST |
1676
 
                      REFRESH_HOSTS),
 
1799
                      REFRESH_GRANT |
 
1800
                      REFRESH_THREADS | REFRESH_HOSTS),
1677
1801
                     (TableList*) 0, &not_used); // Flush logs
1678
1802
      }
 
1803
      logger.set_handlers(LOG_FILE,
 
1804
                          opt_slow_log ? log_output_options : LOG_NONE,
 
1805
                          opt_log ? log_output_options : LOG_NONE);
1679
1806
      break;
1680
1807
#ifdef USE_ONE_SIGNAL_HAND
1681
1808
    case THR_SERVER_ALARM:
1703
1830
  for the client.
1704
1831
*/
1705
1832
/* ARGSUSED */
1706
 
extern "C" void my_message_sql(uint32_t error, const char *str, myf MyFlags);
 
1833
extern "C" void my_message_sql(uint error, const char *str, myf MyFlags);
1707
1834
 
1708
 
void my_message_sql(uint32_t error, const char *str, myf MyFlags)
 
1835
void my_message_sql(uint error, const char *str, myf MyFlags)
1709
1836
{
1710
 
  Session *session;
 
1837
  THD *thd;
1711
1838
  /*
1712
1839
    Put here following assertion when situation with EE_* error codes
1713
1840
    will be fixed
1714
1841
  */
1715
 
  if ((session= current_session))
 
1842
  if ((thd= current_thd))
1716
1843
  {
1717
1844
    if (MyFlags & ME_FATALERROR)
1718
 
      session->is_fatal_error= 1;
 
1845
      thd->is_fatal_error= 1;
 
1846
 
 
1847
#ifdef BUG_36098_FIXED
 
1848
    mysql_audit_general(thd,DRIZZLE_AUDIT_GENERAL_ERROR,error,my_time(0),
 
1849
                        0,0,str,str ? strlen(str) : 0,
 
1850
                        thd->query,thd->query_length,
 
1851
                        thd->variables.character_set_client,
 
1852
                        thd->row_count);
 
1853
#endif
 
1854
 
1719
1855
 
1720
1856
    /*
1721
 
      TODO: There are two exceptions mechanism (Session and sp_rcontext),
 
1857
      TODO: There are two exceptions mechanism (THD and sp_rcontext),
1722
1858
      this could be improved by having a common stack of handlers.
1723
1859
    */
1724
 
    if (session->handle_error(error, str,
 
1860
    if (thd->handle_error(error, str,
1725
1861
                          DRIZZLE_ERROR::WARN_LEVEL_ERROR))
1726
1862
      return;;
1727
1863
 
1728
 
    session->is_slave_error=  1; // needed to catch query errors during replication
 
1864
    thd->is_slave_error=  1; // needed to catch query errors during replication
1729
1865
 
1730
1866
    /*
1731
 
      session->lex->current_select == 0 if lex structure is not inited
 
1867
      thd->lex->current_select == 0 if lex structure is not inited
1732
1868
      (not query command (COM_QUERY))
1733
1869
    */
1734
 
    if (! (session->lex->current_select &&
1735
 
        session->lex->current_select->no_error && !session->is_fatal_error))
 
1870
    if (! (thd->lex->current_select &&
 
1871
        thd->lex->current_select->no_error && !thd->is_fatal_error))
1736
1872
    {
1737
 
      if (! session->main_da.is_error())            // Return only first message
 
1873
      if (! thd->main_da.is_error())            // Return only first message
1738
1874
      {
1739
1875
        if (error == 0)
1740
1876
          error= ER_UNKNOWN_ERROR;
1741
1877
        if (str == NULL)
1742
1878
          str= ER(error);
1743
 
        session->main_da.set_error_status(session, error, str);
 
1879
        thd->main_da.set_error_status(thd, error, str);
1744
1880
      }
1745
1881
    }
1746
1882
 
1747
 
    if (!session->no_warnings_for_error && !session->is_fatal_error)
 
1883
    if (!thd->no_warnings_for_error && !thd->is_fatal_error)
1748
1884
    {
1749
1885
      /*
1750
1886
        Suppress infinite recursion if there a memory allocation error
1751
1887
        inside push_warning.
1752
1888
      */
1753
 
      session->no_warnings_for_error= true;
1754
 
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
1755
 
      session->no_warnings_for_error= false;
 
1889
      thd->no_warnings_for_error= true;
 
1890
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
 
1891
      thd->no_warnings_for_error= false;
1756
1892
    }
1757
1893
  }
1758
 
  if (!session || MyFlags & ME_NOREFRESH)
 
1894
  if (!thd || MyFlags & ME_NOREFRESH)
1759
1895
    sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */
1760
1896
  return;;
1761
1897
}
1772
1908
 
1773
1909
void my_str_free_mysqld(void *ptr)
1774
1910
{
1775
 
  free((unsigned char*)ptr);
 
1911
  my_free((uchar*)ptr, MYF(MY_FAE));
1776
1912
}
1777
1913
 
1778
1914
 
1796
1932
    1 error
1797
1933
*/
1798
1934
 
1799
 
static bool init_global_datetime_format(enum enum_drizzle_timestamp_type format_type,
 
1935
static bool init_global_datetime_format(timestamp_type format_type,
1800
1936
                                        DATE_TIME_FORMAT **var_ptr)
1801
1937
{
1802
1938
  /* Get command line option */
1862
1998
  {"savepoint",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SAVEPOINT]), SHOW_LONG_STATUS},
1863
1999
  {"select",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SELECT]), SHOW_LONG_STATUS},
1864
2000
  {"set_option",           (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SET_OPTION]), SHOW_LONG_STATUS},
 
2001
  {"show_binlog_events",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOG_EVENTS]), SHOW_LONG_STATUS},
1865
2002
  {"show_binlogs",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_BINLOGS]), SHOW_LONG_STATUS},
 
2003
  {"show_charsets",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CHARSETS]), SHOW_LONG_STATUS},
 
2004
  {"show_collations",      (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_COLLATIONS]), SHOW_LONG_STATUS},
1866
2005
  {"show_create_db",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE_DB]), SHOW_LONG_STATUS},
1867
2006
  {"show_create_table",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_CREATE]), SHOW_LONG_STATUS},
1868
2007
  {"show_databases",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_DATABASES]), SHOW_LONG_STATUS},
1874
2013
  {"show_open_tables",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS},
1875
2014
  {"show_plugins",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PLUGINS]), SHOW_LONG_STATUS},
1876
2015
  {"show_processlist",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS},
 
2016
  {"show_slave_hosts",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS},
1877
2017
  {"show_slave_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
1878
2018
  {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
1879
2019
  {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
1886
2026
  {"unlock_tables",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UNLOCK_TABLES]), SHOW_LONG_STATUS},
1887
2027
  {"update",               (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE]), SHOW_LONG_STATUS},
1888
2028
  {"update_multi",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_UPDATE_MULTI]), SHOW_LONG_STATUS},
1889
 
  {NULL, NULL, SHOW_LONG}
 
2029
  {NullS, NullS, SHOW_LONG}
1890
2030
};
1891
2031
 
1892
2032
static int init_common_variables(const char *conf_file_name, int argc,
1893
2033
                                 char **argv, const char **groups)
1894
2034
{
 
2035
  char buff[FN_REFLEN], *s;
1895
2036
  umask(((~my_umask) & 0666));
1896
2037
  my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
1897
2038
  tzset();                      // Set tzname
1908
2049
 
1909
2050
  if (init_thread_environment())
1910
2051
    return 1;
1911
 
  drizzle_init_variables();
 
2052
  mysql_init_variables();
1912
2053
 
1913
2054
#ifdef HAVE_TZNAME
1914
2055
  {
1944
2085
  }
1945
2086
  else
1946
2087
  strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
1947
 
  my_stpcpy(fn_ext(pidfile_name),".pid");               // Add proper extension
 
2088
  stpcpy(fn_ext(pidfile_name),".pid");          // Add proper extension
1948
2089
 
1949
2090
  /*
1950
2091
    Add server status variables to the dynamic list of
1964
2105
 
1965
2106
  /* connections and databases needs lots of files */
1966
2107
  {
1967
 
    uint32_t files, wanted_files, max_open_files;
 
2108
    uint files, wanted_files, max_open_files;
1968
2109
 
1969
2110
    /* MyISAM requires two file handles per table. */
1970
2111
    wanted_files= 10+max_connections+table_cache_size*2;
1978
2119
      can't get max_connections*5 but still got no less than was
1979
2120
      requested (value of wanted_files).
1980
2121
    */
1981
 
    max_open_files= cmax(cmax((uint32_t)wanted_files, max_connections*5),
1982
 
                         open_files_limit);
 
2122
    max_open_files= max(max((uint32_t)wanted_files, max_connections*5),
 
2123
                        open_files_limit);
1983
2124
    files= my_set_max_open_files(max_open_files);
1984
2125
 
1985
2126
    if (files < wanted_files)
1990
2131
          If we have requested too much file handles than we bring
1991
2132
          max_connections in supported bounds.
1992
2133
        */
1993
 
        max_connections= (uint32_t) cmin((uint32_t)files-10-TABLE_OPEN_CACHE_MIN*2,
 
2134
        max_connections= (uint32_t) min((uint32_t)files-10-TABLE_OPEN_CACHE_MIN*2,
1994
2135
                                     max_connections);
1995
2136
        /*
1996
2137
          Decrease table_cache_size according to max_connections, but
1997
 
          not below TABLE_OPEN_CACHE_MIN.  Outer cmin() ensures that we
 
2138
          not below TABLE_OPEN_CACHE_MIN.  Outer min() ensures that we
1998
2139
          never increase table_cache_size automatically (that could
1999
2140
          happen if max_connections is decreased above).
2000
2141
        */
2001
 
        table_cache_size= (uint32_t) cmin(cmax((files-10-max_connections)/2,
 
2142
        table_cache_size= (uint32_t) min(max((files-10-max_connections)/2,
2002
2143
                                          (uint32_t)TABLE_OPEN_CACHE_MIN),
2003
2144
                                      table_cache_size);
2004
2145
        if (global_system_variables.log_warnings)
2105
2246
  else
2106
2247
    sys_init_slave.value=my_strdup("",MYF(0));
2107
2248
 
 
2249
  /* check log options and issue warnings if needed */
 
2250
  if (opt_log && opt_logname && !(log_output_options & LOG_FILE) &&
 
2251
      !(log_output_options & LOG_NONE))
 
2252
    sql_print_warning(_("Although a path was specified for the "
 
2253
                        "--log option, log tables are used. "
 
2254
                        "To enable logging to files use the "
 
2255
                        "--log-output option."));
 
2256
 
 
2257
  if (opt_slow_log && opt_slow_logname && !(log_output_options & LOG_FILE)
 
2258
      && !(log_output_options & LOG_NONE))
 
2259
    sql_print_warning(_("Although a path was specified for the "
 
2260
                        "--log-slow-queries option, log tables are used. "
 
2261
                        "To enable logging to files use the "
 
2262
                        "--log-output=file option."));
 
2263
 
 
2264
  s= opt_logname ? opt_logname : make_default_log_name(buff, ".log");
 
2265
  sys_var_general_log_path.value= my_strdup(s, MYF(0));
 
2266
  sys_var_general_log_path.value_length= strlen(s);
 
2267
 
 
2268
  s= opt_slow_logname ? opt_slow_logname : make_default_log_name(buff, "-slow.log");
 
2269
  sys_var_slow_log_path.value= my_strdup(s, MYF(0));
 
2270
  sys_var_slow_log_path.value_length= strlen(s);
 
2271
 
2108
2272
  if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
2109
2273
    return 1;
2110
2274
  if (my_database_names_init())
2127
2291
  (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
2128
2292
  (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST);
2129
2293
  (void) pthread_mutex_init(&LOCK_error_log,MY_MUTEX_INIT_FAST);
 
2294
  (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
2130
2295
  (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
2131
2296
  (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
2132
2297
  (void) my_rwlock_init(&LOCK_system_variables_hash, NULL);
2133
2298
  (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST);
 
2299
  (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST);
2134
2300
  (void) pthread_mutex_init(&LOCK_connection_count, MY_MUTEX_INIT_FAST);
2135
2301
  (void) my_rwlock_init(&LOCK_sys_init_connect, NULL);
2136
2302
  (void) my_rwlock_init(&LOCK_sys_init_slave, NULL);
2137
2303
  (void) pthread_cond_init(&COND_thread_count,NULL);
2138
2304
  (void) pthread_cond_init(&COND_refresh,NULL);
2139
2305
  (void) pthread_cond_init(&COND_global_read_lock,NULL);
 
2306
  (void) pthread_cond_init(&COND_thread_cache,NULL);
 
2307
  (void) pthread_cond_init(&COND_flush_thread_cache,NULL);
 
2308
  (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
 
2309
  (void) pthread_cond_init(&COND_rpl_status, NULL);
2140
2310
 
2141
2311
  /* Parameter for threads created for connections */
2142
2312
  (void) pthread_attr_init(&connection_attrib);
2151
2321
    (void)pthread_attr_setschedparam(&connection_attrib, &tmp_sched_param);
2152
2322
  }
2153
2323
 
2154
 
  if (pthread_key_create(&THR_Session,NULL) ||
 
2324
  if (pthread_key_create(&THR_THD,NULL) ||
2155
2325
      pthread_key_create(&THR_MALLOC,NULL))
2156
2326
  {
2157
2327
    sql_print_error(_("Can't create thread-keys"));
2173
2343
  randominit(&sql_rand,(uint32_t) server_start_time,(uint32_t) server_start_time/2);
2174
2344
  setup_fpu();
2175
2345
  init_thr_lock();
 
2346
  init_slave_list();
2176
2347
 
2177
2348
  /* Setup logs */
2178
2349
 
2193
2364
      opt_error_log= 1;                         // Too long file name
2194
2365
    else
2195
2366
    {
2196
 
      if (freopen(log_error_file, "a+", stdout)==NULL)
2197
 
        sql_print_error(_("Unable to reopen stdout"));
2198
 
      else
2199
 
        if(freopen(log_error_file, "a+", stderr)==NULL)
2200
 
          sql_print_error(_("Unable to reopen stderr"));
 
2367
      if (freopen(log_error_file, "a+", stdout))
 
2368
        freopen(log_error_file, "a+", stderr);
2201
2369
    }
2202
2370
  }
2203
2371
 
2260
2428
    }
2261
2429
    if (ln == buf)
2262
2430
    {
2263
 
      free(opt_bin_logname);
 
2431
      my_free(opt_bin_logname, MYF(MY_ALLOW_ZERO_PTR));
2264
2432
      opt_bin_logname=my_strdup(buf, MYF(0));
2265
2433
    }
2266
2434
    if (mysql_bin_log.open_index_file(opt_binlog_index_name, ln))
2331
2499
    unireg_abort(1);
2332
2500
  }
2333
2501
 
 
2502
  logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
 
2503
                      opt_log ? LOG_FILE:LOG_NONE);
 
2504
 
2334
2505
  /*
2335
2506
    Check that the default storage engine is actually available.
2336
2507
  */
2411
2582
      locked_in_memory= 0;
2412
2583
    }
2413
2584
    if (user_info)
2414
 
      set_user(drizzled_user, user_info);
 
2585
      set_user(mysqld_user, user_info);
2415
2586
  }
2416
2587
  else
2417
2588
#endif
2424
2595
 
2425
2596
int main(int argc, char **argv)
2426
2597
{
 
2598
 
2427
2599
#if defined(ENABLE_NLS)
2428
2600
# if defined(HAVE_LOCALE_H)
2429
2601
  setlocale(LC_ALL, "");
2475
2647
      if (global_system_variables.log_warnings)
2476
2648
      {
2477
2649
        /* %zu is not yet in C++ */
2478
 
        uint64_t size_tmp= (uint64_t)stack_size;
2479
 
        sql_print_warning(_("Asked for %u thread stack, but got %"PRIu64),
 
2650
        unsigned long long size_tmp= (uint64_t)stack_size;
 
2651
        sql_print_warning(_("Asked for %u thread stack, but got %llu"),
2480
2652
                          my_thread_stack_size, size_tmp);
2481
2653
      }
2482
2654
      my_thread_stack_size= stack_size;
2498
2670
  mysql_data_home[1]=0;
2499
2671
  mysql_data_home_len= 2;
2500
2672
 
2501
 
  if ((user_info= check_user(drizzled_user)))
 
2673
  if ((user_info= check_user(mysqld_user)))
2502
2674
  {
2503
2675
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
2504
2676
    if (locked_in_memory) // getuid() == 0 here
2505
2677
      set_effective_user(user_info);
2506
2678
    else
2507
2679
#endif
2508
 
      set_user(drizzled_user, user_info);
 
2680
      set_user(mysqld_user, user_info);
2509
2681
  }
2510
2682
 
2511
2683
  if (opt_bin_log && !server_id)
2537
2709
  error_handler_hook= my_message_sql;
2538
2710
  start_signal_handler();                               // Creates pidfile
2539
2711
 
2540
 
  if (mysql_rm_tmp_tables() || my_tz_init((Session *)0, default_tz_name))
 
2712
  if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, false))
2541
2713
  {
2542
2714
    abort_loop=1;
2543
2715
    select_thread_in_use=0;
2561
2733
  }
2562
2734
 
2563
2735
  sql_print_information(_(ER(ER_STARTUP)),my_progname,server_version,
2564
 
                        "", drizzled_port, COMPILATION_COMMENT);
 
2736
                        "", mysqld_port, DRIZZLE_COMPILATION_COMMENT);
2565
2737
 
2566
2738
 
2567
2739
  handle_connections_sockets();
2587
2759
  (void) pthread_mutex_unlock(&LOCK_thread_count);
2588
2760
 
2589
2761
  clean_up(1);
2590
 
  drizzled_exit(0);
 
2762
  mysqld_exit(0);
2591
2763
}
2592
2764
 
2593
2765
 
2596
2768
 
2597
2769
    This function will create new thread to handle the incoming
2598
2770
    connection.  If there are idle cached threads one will be used.
2599
 
    'session' will be pushed into 'threads'.
 
2771
    'thd' will be pushed into 'threads'.
2600
2772
 
2601
2773
    In single-threaded mode (\#define ONE_THREAD) connection will be
2602
2774
    handled inside this function.
2603
2775
 
2604
 
  @param[in,out] session    Thread handle of future thread.
 
2776
  @param[in,out] thd    Thread handle of future thread.
2605
2777
*/
2606
2778
 
2607
 
static void create_new_thread(Session *session)
 
2779
static void create_new_thread(THD *thd)
2608
2780
{
2609
2781
 
2610
2782
  /*
2618
2790
  {
2619
2791
    pthread_mutex_unlock(&LOCK_connection_count);
2620
2792
 
2621
 
    close_connection(session, ER_CON_COUNT_ERROR, 1);
2622
 
    delete session;
 
2793
    close_connection(thd, ER_CON_COUNT_ERROR, 1);
 
2794
    delete thd;
2623
2795
    return;;
2624
2796
  }
2625
2797
 
2635
2807
  pthread_mutex_lock(&LOCK_thread_count);
2636
2808
 
2637
2809
  /*
2638
 
    The initialization of thread_id is done in create_embedded_session() for
 
2810
    The initialization of thread_id is done in create_embedded_thd() for
2639
2811
    the embedded library.
2640
2812
    TODO: refactor this to avoid code duplication there
2641
2813
  */
2642
 
  session->thread_id= session->variables.pseudo_thread_id= thread_id++;
 
2814
  thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
2643
2815
 
2644
2816
  thread_count++;
2645
2817
 
2646
 
  thread_scheduler.add_connection(session);
 
2818
  thread_scheduler.add_connection(thd);
2647
2819
 
2648
2820
  return;;
2649
2821
}
2671
2843
{
2672
2844
  int x;
2673
2845
  int sock,new_sock;
2674
 
  uint32_t error_count=0;
2675
 
  Session *session;
 
2846
  uint error_count=0;
 
2847
  THD *thd;
2676
2848
  struct sockaddr_storage cAddr;
2677
2849
 
2678
2850
  MAYBE_BROKEN_SYSCALL;
2682
2854
 
2683
2855
    if ((number_of= poll(fds, pollfd_count, -1)) == -1)
2684
2856
    {
2685
 
      if (errno != EINTR)
 
2857
      if (socket_errno != SOCKET_EINTR)
2686
2858
      {
2687
2859
        if (!select_errors++ && !abort_loop)    /* purecov: inspected */
2688
2860
          sql_print_error(_("drizzled: Got error %d from select"),
2689
 
                          errno); /* purecov: inspected */
 
2861
                          socket_errno); /* purecov: inspected */
2690
2862
      }
2691
2863
      MAYBE_BROKEN_SYSCALL
2692
2864
      continue;
2714
2886
    }
2715
2887
    assert(sock != -1);
2716
2888
 
2717
 
    for (uint32_t retry=0; retry < MAX_ACCEPT_RETRY; retry++)
 
2889
    for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
2718
2890
    {
2719
 
      SOCKET_SIZE_TYPE length= sizeof(struct sockaddr_storage);
 
2891
      size_socket length= sizeof(struct sockaddr_storage);
2720
2892
      new_sock= accept(sock, (struct sockaddr *)(&cAddr),
2721
2893
                       &length);
2722
 
      if (new_sock != -1 || (errno != EINTR && errno != EAGAIN))
 
2894
      if (new_sock != -1 || (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
2723
2895
        break;
2724
2896
    }
2725
2897
 
2729
2901
      if ((error_count++ & 255) == 0)           // This can happen often
2730
2902
        sql_perror("Error in accept");
2731
2903
      MAYBE_BROKEN_SYSCALL;
2732
 
      if (errno == ENFILE || errno == EMFILE)
 
2904
      if (socket_errno == SOCKET_ENFILE || socket_errno == SOCKET_EMFILE)
2733
2905
        sleep(1);                               // Give other threads some time
2734
2906
      continue;
2735
2907
    }
2736
2908
 
2737
2909
    {
2738
 
      SOCKET_SIZE_TYPE dummyLen;
 
2910
      size_socket dummyLen;
2739
2911
      struct sockaddr_storage dummy;
2740
2912
      dummyLen = sizeof(dummy);
2741
2913
      if (  getsockname(new_sock,(struct sockaddr *)&dummy,
2761
2933
    ** Don't allow too many connections
2762
2934
    */
2763
2935
 
2764
 
    if (!(session= new Session))
 
2936
    if (!(thd= new THD))
2765
2937
    {
2766
2938
      (void) shutdown(new_sock, SHUT_RDWR);
2767
 
      close(new_sock);
 
2939
      VOID(close(new_sock));
2768
2940
      continue;
2769
2941
    }
2770
 
    if (net_init_sock(&session->net, new_sock, sock == 0))
 
2942
    if (net_init_sock(&thd->net, new_sock, sock == 0))
2771
2943
    {
2772
 
      delete session;
 
2944
      delete thd;
2773
2945
      continue;
2774
2946
    }
2775
2947
 
2776
 
    create_new_thread(session);
 
2948
    create_new_thread(thd);
2777
2949
  }
2778
2950
}
2779
2951
 
2797
2969
  OPT_SHORT_LOG_FORMAT,
2798
2970
  OPT_FLUSH,                   OPT_SAFE,
2799
2971
  OPT_STORAGE_ENGINE,          OPT_INIT_FILE,
2800
 
  OPT_DELAY_KEY_WRITE_ALL,
 
2972
  OPT_DELAY_KEY_WRITE_ALL,     OPT_SLOW_QUERY_LOG,
2801
2973
  OPT_DELAY_KEY_WRITE,         OPT_CHARSETS_DIR,
2802
2974
  OPT_MASTER_INFO_FILE,
2803
2975
  OPT_MASTER_RETRY_COUNT,      OPT_LOG_TC, OPT_LOG_TC_SIZE,
2815
2987
  OPT_REPLICATE_WILD_IGNORE_TABLE, OPT_REPLICATE_SAME_SERVER_ID,
2816
2988
  OPT_DISCONNECT_SLAVE_EVENT_COUNT, OPT_TC_HEURISTIC_RECOVER,
2817
2989
  OPT_ABORT_SLAVE_EVENT_COUNT,
 
2990
  OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
2818
2991
  OPT_ENGINE_CONDITION_PUSHDOWN,
2819
2992
  OPT_TEMP_POOL, OPT_TX_ISOLATION, OPT_COMPLETION_TYPE,
2820
2993
  OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS,
2887
3060
  OPT_DATE_FORMAT,
2888
3061
  OPT_TIME_FORMAT,
2889
3062
  OPT_DATETIME_FORMAT,
 
3063
  OPT_LOG_QUERIES_NOT_USING_INDEXES,
2890
3064
  OPT_DEFAULT_TIME_ZONE,
2891
3065
  OPT_SYSDATE_IS_NOW,
2892
3066
  OPT_OPTIMIZER_SEARCH_DEPTH,
2896
3070
  OPT_ENABLE_LARGE_PAGES,
2897
3071
  OPT_TIMED_MUTEXES,
2898
3072
  OPT_OLD_STYLE_USER_LIMITS,
 
3073
  OPT_LOG_SLOW_ADMIN_STATEMENTS,
2899
3074
  OPT_TABLE_LOCK_WAIT_TIMEOUT,
2900
3075
  OPT_PLUGIN_LOAD,
2901
3076
  OPT_PLUGIN_DIR,
 
3077
  OPT_LOG_OUTPUT,
2902
3078
  OPT_PORT_OPEN_TIMEOUT,
2903
3079
  OPT_PROFILING,
2904
3080
  OPT_KEEP_FILES_ON_CREATE,
2905
3081
  OPT_GENERAL_LOG,
 
3082
  OPT_SLOW_LOG,
2906
3083
  OPT_THREAD_HANDLING,
2907
3084
  OPT_INNODB_ROLLBACK_ON_TIMEOUT,
2908
3085
  OPT_SECURE_FILE_PRIV,
2909
3086
  OPT_MIN_EXAMINED_ROW_LIMIT,
 
3087
  OPT_LOG_SLOW_SLAVE_STATEMENTS,
2910
3088
  OPT_OLD_MODE,
2911
3089
  OPT_POOL_OF_THREADS,
2912
3090
  OPT_SLAVE_EXEC_MODE
2938
3116
  {"basedir", 'b',
2939
3117
   N_("Path to installation directory. All paths are usually resolved "
2940
3118
      "relative to this."),
2941
 
   (char**) &drizzle_home_ptr, (char**) &drizzle_home_ptr, 0, GET_STR, REQUIRED_ARG,
 
3119
   (char**) &mysql_home_ptr, (char**) &mysql_home_ptr, 0, GET_STR, REQUIRED_ARG,
2942
3120
   0, 0, 0, 0, 0, 0},
2943
3121
  {"bind-address", OPT_BIND_ADDRESS, N_("IP address to bind to."),
2944
3122
   (char**) &my_bind_addr_str, (char**) &my_bind_addr_str, 0, GET_STR,
2991
3169
   (char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2992
3170
  {"chroot", 'r',
2993
3171
   N_("Chroot mysqld daemon during startup."),
2994
 
   (char**) &drizzled_chroot, (char**) &drizzled_chroot, 0, GET_STR, REQUIRED_ARG,
 
3172
   (char**) &mysqld_chroot, (char**) &mysqld_chroot, 0, GET_STR, REQUIRED_ARG,
2995
3173
   0, 0, 0, 0, 0, 0},
2996
3174
  {"collation-server", OPT_DEFAULT_COLLATION,
2997
3175
   N_("Set the default collation."),
3014
3192
   N_("Path to the database root."),
3015
3193
   (char**) &mysql_data_home,
3016
3194
   (char**) &mysql_data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3195
  {"default-character-set", 'C',
 
3196
   N_("Set the default character set (deprecated option, use "
 
3197
      "--character-set-server instead)."),
 
3198
   (char**) &default_character_set_name, (char**) &default_character_set_name,
 
3199
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
3200
  {"default-collation", OPT_DEFAULT_COLLATION,
 
3201
   N_("Set the default collation (deprecated option, use --collation-server "
 
3202
      "instead)."),
 
3203
   (char**) &default_collation_name, (char**) &default_collation_name,
 
3204
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
3017
3205
  {"default-storage-engine", OPT_STORAGE_ENGINE,
3018
3206
   N_("Set the default storage engine (table type) for tables."),
3019
3207
   (char**)&default_storage_engine_str, (char**)&default_storage_engine_str,
3025
3213
  {"delay-key-write", OPT_DELAY_KEY_WRITE,
3026
3214
   N_("Type of DELAY_KEY_WRITE."),
3027
3215
   0,0,0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3216
  {"delay-key-write-for-all-tables", OPT_DELAY_KEY_WRITE_ALL,
 
3217
   N_("Don't flush key buffers between writes for any MyISAM table "
 
3218
      "(Deprecated option, use --delay-key-write=all instead)."),
 
3219
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
3028
3220
  {"disconnect-slave-event-count", OPT_DISCONNECT_SLAVE_EVENT_COUNT,
3029
3221
   N_("Option used by mysql-test for debugging and testing of replication."),
3030
3222
   (char**) &disconnect_slave_event_count,
3041
3233
   N_("Push supported query conditions to the storage engine."),
3042
3234
   (char**) &global_system_variables.engine_condition_pushdown,
3043
3235
   (char**) &global_system_variables.engine_condition_pushdown,
3044
 
   0, GET_BOOL, NO_ARG, false, 0, 0, 0, 0, 0},
 
3236
   0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
3045
3237
  /* See how it's handled in get_one_option() */
3046
3238
  {"exit-info", 'T',
3047
3239
   N_("Used for debugging;  Use at your own risk!"),
3055
3247
   N_("Set up signals usable for debugging"),
3056
3248
   (char**) &opt_debugging, (char**) &opt_debugging,
3057
3249
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3250
  {"general-log", OPT_GENERAL_LOG,
 
3251
   N_("Enable general query log"),
 
3252
   (char**) &opt_log,
 
3253
   (char**) &opt_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
3058
3254
  {"init-connect", OPT_INIT_CONNECT,
3059
3255
   N_("Command(s) that are executed for each new connection"),
3060
3256
   (char**) &opt_init_connect, (char**) &opt_init_connect, 0, GET_STR_ALLOC,
3096
3292
   N_("File that holds the names for last binary log files."),
3097
3293
   (char**) &opt_binlog_index_name, (char**) &opt_binlog_index_name, 0, GET_STR,
3098
3294
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3295
  /*
 
3296
    This option starts with "log-bin" to emphasize that it is specific of
 
3297
    binary logging.
 
3298
  */
 
3299
  {"log-bin-trust-function-creators", OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
 
3300
   N_("If equal to 0 (the default), then when --log-bin is used, creation of "
 
3301
      "a stored function (or trigger) is allowed only to users having the "
 
3302
      "SUPER privilege and only if this stored function (trigger) may not "
 
3303
      "break binary logging. Note that if ALL connections to this server "
 
3304
      "ALWAYS use row-based binary logging, the security issues do not exist "
 
3305
      "and the binary logging cannot break, so you can safely set this to 1.")
 
3306
   ,(char**) &trust_function_creators, (char**) &trust_function_creators, 0,
 
3307
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3099
3308
  {"log-error", OPT_ERROR_LOG_FILE,
3100
3309
   N_("Error log file."),
3101
3310
   (char**) &log_error_file_ptr, (char**) &log_error_file_ptr, 0, GET_STR,
3104
3313
   N_("Log all MyISAM changes to file."),
3105
3314
   (char**) &myisam_log_filename, (char**) &myisam_log_filename, 0, GET_STR,
3106
3315
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3316
  {"log-long-format", '0',
 
3317
   N_("Log some extra information to update log. Please note that this option "
 
3318
      "is deprecated; see --log-queries-not-using-indexes option."),
 
3319
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3320
#ifdef WITH_CSV_STORAGE_ENGINE
 
3321
  {"log-output", OPT_LOG_OUTPUT,
 
3322
   N_("Syntax: log-output[=value[,value...]], where \"value\" could be TABLE, "
 
3323
      "FILE or NONE."),
 
3324
   (char**) &log_output_str, (char**) &log_output_str, 0,
 
3325
   GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
3326
#endif
 
3327
  {"log-queries-not-using-indexes", OPT_LOG_QUERIES_NOT_USING_INDEXES,
 
3328
   N_("Log queries that are executed without benefit of any index to the "
 
3329
      "slow log if it is open."),
 
3330
   (char**) &opt_log_queries_not_using_indexes,
 
3331
   (char**) &opt_log_queries_not_using_indexes,
 
3332
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3107
3333
  {"log-slave-updates", OPT_LOG_SLAVE_UPDATES,
3108
3334
   N_("Tells the slave to log the updates from the slave thread to the binary "
3109
3335
      "log. You will need to turn it on if you plan to "
3111
3337
   (char**) &opt_log_slave_updates, (char**) &opt_log_slave_updates,
3112
3338
   0, GET_BOOL,
3113
3339
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
3340
  {"log-slow-admin-statements", OPT_LOG_SLOW_ADMIN_STATEMENTS,
 
3341
   N_("Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements "
 
3342
      "to the slow log if it is open."),
 
3343
   (char**) &opt_log_slow_admin_statements,
 
3344
   (char**) &opt_log_slow_admin_statements,
 
3345
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3346
 {"log-slow-slave-statements", OPT_LOG_SLOW_SLAVE_STATEMENTS,
 
3347
  N_("Log slow statements executed by slave thread to the slow log if it is "
 
3348
     "open."),
 
3349
  (char**) &opt_log_slow_slave_statements,
 
3350
  (char**) &opt_log_slow_slave_statements,
 
3351
  0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
3352
  {"log-slow-queries", OPT_SLOW_QUERY_LOG,
 
3353
   N_("Log slow queries to a table or log file. Defaults logging to table "
 
3354
      "mysql.slow_log or hostname-slow.log if --log-output=file is used. "
 
3355
      "Must be enabled to activate other slow log options."),
 
3356
   (char**) &opt_slow_logname, (char**) &opt_slow_logname, 0, GET_STR, OPT_ARG,
 
3357
   0, 0, 0, 0, 0, 0},
3114
3358
  {"log-tc", OPT_LOG_TC,
3115
3359
   N_("Path to transaction coordinator log (used for transactions that affect "
3116
3360
      "more than one storage engine, when binary log is disabled)"),
3166
3410
   (char**) &global_system_variables.old_alter_table,
3167
3411
   (char**) &max_system_variables.old_alter_table, 0, GET_BOOL, NO_ARG,
3168
3412
   0, 0, 0, 0, 0, 0},
 
3413
  {"old-style-user-limits", OPT_OLD_STYLE_USER_LIMITS,
 
3414
   N_("Enable old-style user limits (before 5.0.3 user resources were counted "
 
3415
      "per each user+host vs. per account)"),
 
3416
   (char**) &opt_old_style_user_limits, (char**) &opt_old_style_user_limits,
 
3417
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3169
3418
  {"pid-file", OPT_PID_FILE,
3170
3419
   N_("Pid file used by safe_mysqld."),
3171
3420
   (char**) &pidfile_name_ptr, (char**) &pidfile_name_ptr, 0, GET_STR,
3172
3421
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3173
3422
  {"port", 'P',
3174
3423
   N_("Port number to use for connection or 0 for default to, in "
3175
 
      "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
 
3424
      "order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
3176
3425
      "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ")."),
3177
 
   (char**) &drizzled_port,
3178
 
   (char**) &drizzled_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3426
   (char**) &mysqld_port,
 
3427
   (char**) &mysqld_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3179
3428
  {"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
3180
3429
   N_("Maximum time in seconds to wait for the port to become free. "
3181
3430
      "(Default: no wait)"),
3182
 
   (char**) &drizzled_port_timeout,
3183
 
   (char**) &drizzled_port_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3431
   (char**) &mysqld_port_timeout,
 
3432
   (char**) &mysqld_port_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3184
3433
  {"relay-log", OPT_RELAY_LOG,
3185
3434
   N_("The location and name to use for relay logs."),
3186
3435
   (char**) &opt_relay_logname, (char**) &opt_relay_logname, 0,
3261
3510
      "the slave from the master or other hosts."),
3262
3511
   (char**) &report_host, (char**) &report_host, 0, GET_STR, REQUIRED_ARG, 0, 0,
3263
3512
   0, 0, 0, 0},
 
3513
  {"report-password", OPT_REPORT_PASSWORD, "Undocumented.",
 
3514
   (char**) &report_password, (char**) &report_password, 0, GET_STR,
 
3515
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3516
  {"report-port", OPT_REPORT_PORT,
 
3517
   N_("Port for connecting to slave reported to the master during slave "
 
3518
      "registration. Set it only if the slave is listening on a non-default "
 
3519
      "port or if you have a special tunnel from the master or other clients "
 
3520
      "to the slave. If not sure, leave this option unset."),
 
3521
   (char**) &report_port, (char**) &report_port, 0, GET_UINT, REQUIRED_ARG,
 
3522
   DRIZZLE_PORT, 0, 0, 0, 0, 0},
3264
3523
  {"safe-mode", OPT_SAFE,
3265
3524
   N_("Skip some optimize stages (for testing)."),
3266
3525
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
3274
3533
      "replication partners."),
3275
3534
   (char**) &server_id, (char**) &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0,
3276
3535
   0, 0, 0},
 
3536
  {"set-variable", 'O',
 
3537
   N_("Change the value of a variable. Please note that this option is "
 
3538
      "deprecated;you can set variables directly with --variable-name=value."),
 
3539
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3277
3540
  {"skip-new", OPT_SKIP_NEW,
3278
3541
   N_("Don't use new, possible wrong routines."),
3279
3542
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
3285
3548
   N_("Don't print a stack trace on failure."),
3286
3549
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
3287
3550
   0, 0, 0, 0},
 
3551
  {"skip-symlink", OPT_SKIP_SYMLINKS,
 
3552
   N_("Don't allow symlinking of tables. Deprecated option.  Use "
 
3553
      "--skip-symbolic-links instead."),
 
3554
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
3288
3555
  {"skip-thread-priority", OPT_SKIP_PRIOR,
3289
3556
   N_("Don't give threads different priorities."),
3290
3557
   0, 0, 0, GET_NO_ARG, NO_ARG,
3306
3573
      "and the slave."),
3307
3574
   (char**) &slave_exec_mode_str, (char**) &slave_exec_mode_str,
3308
3575
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
3576
  {"slow-query-log", OPT_SLOW_LOG,
 
3577
   N_("Enable|disable slow query log"),
 
3578
   (char**) &opt_slow_log,
 
3579
   (char**) &opt_slow_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
3309
3580
  {"sql-bin-update-same", OPT_SQL_BIN_UPDATE_SAME,
3310
3581
   N_("(INGORED)"),
3311
3582
   0, 0, 0, GET_DISABLED, NO_ARG, 0, 0, 0, 0, 0, 0},
3348
3619
   N_("Default transaction isolation level."),
3349
3620
   0, 0, 0, GET_STR, REQUIRED_ARG, 0,
3350
3621
   0, 0, 0, 0, 0},
 
3622
  {"use-symbolic-links", 's',
 
3623
   N_("Enable symbolic link support. Deprecated option; use --symbolic-links "
 
3624
      "instead."),
 
3625
   (char**) &my_use_symdir, (char**) &my_use_symdir, 0, GET_BOOL, NO_ARG,
 
3626
   IF_PURIFY(0,1), 0, 0, 0, 0, 0},
3351
3627
  {"user", 'u',
3352
 
   N_("Run drizzled daemon as user."),
 
3628
   N_("Run mysqld daemon as user."),
3353
3629
   0, 0, 0, GET_STR, REQUIRED_ARG,
3354
3630
   0, 0, 0, 0, 0, 0},
3355
3631
  {"version", 'V',
3356
3632
   N_("Output version information and exit."),
3357
3633
   0, 0, 0, GET_NO_ARG,
3358
3634
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
3635
  {"warnings", 'W',
 
3636
   N_("Deprecated; use --log-warnings instead."),
 
3637
   (char**) &global_system_variables.log_warnings,
 
3638
   (char**) &max_system_variables.log_warnings, 0, GET_ULONG, OPT_ARG,
 
3639
   1, 0, ULONG_MAX, 0, 0, 0},
3359
3640
  {"back_log", OPT_BACK_LOG,
3360
3641
   N_("The number of outstanding connection requests MySQL can have. This "
3361
3642
      "comes into play when the main MySQL thread gets very many connection "
3458
3739
   (char**) 0,
3459
3740
   0, (GET_ULONG | GET_ASK_ADDR) , REQUIRED_ARG, 100,
3460
3741
   1, 100, 0, 1, 0},
 
3742
  {"long_query_time", OPT_LONG_QUERY_TIME,
 
3743
   N_("Log all queries that have taken more than long_query_time seconds to "
 
3744
      "execute to file. The argument will be treated as a decimal value with "
 
3745
      "microsecond precission."),
 
3746
   (char**) &long_query_time, (char**) &long_query_time, 0, GET_DOUBLE,
 
3747
   REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0},
3461
3748
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
3462
3749
   N_("Max packetlength to send/receive from to server."),
3463
3750
   (char**) &global_system_variables.max_allowed_packet,
3553
3840
   (char**) &myisam_data_pointer_size,
3554
3841
   (char**) &myisam_data_pointer_size, 0, GET_ULONG, REQUIRED_ARG,
3555
3842
   6, 2, 7, 0, 1, 0},
 
3843
  {"myisam_max_extra_sort_file_size", OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
 
3844
   N_("(Deprecated option)"),
 
3845
   (char**) &global_system_variables.myisam_max_extra_sort_file_size,
 
3846
   (char**) &max_system_variables.myisam_max_extra_sort_file_size,
 
3847
   0, GET_ULL, REQUIRED_ARG, (uint64_t) MI_MAX_TEMP_LENGTH,
 
3848
   0, (uint64_t) MAX_FILE_SIZE, 0, 1, 0},
3556
3849
  {"myisam_max_sort_file_size", OPT_MYISAM_MAX_SORT_FILE_SIZE,
3557
3850
   N_("Don't use the fast sort index method to created index if the "
3558
3851
      "temporary file would get bigger than this."),
3639
3932
   (char**) &opt_plugin_dir_ptr, (char**) &opt_plugin_dir_ptr, 0,
3640
3933
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3641
3934
  {"plugin_load", OPT_PLUGIN_LOAD,
3642
 
   N_("Optional colon (or semicolon) separated list of plugins to load,"
3643
 
      "where each plugin is identified by the name of the shared library. "
3644
 
      "[for example: --plugin_load=libmd5udf.so:libauth_pam.so]"),
 
3935
   N_("Optional comma separated list of plugins to load, where each plugin is "
 
3936
      "identified by the name of the shared library. "
 
3937
      "[for example: --plugin_load=libmd5udf.so]"),
3645
3938
   (char**) &opt_plugin_load, (char**) &opt_plugin_load, 0,
3646
3939
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3647
3940
  {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
3741
4034
      "Use 0 (default) to disable synchronous flushing."),
3742
4035
   (char**) &sync_binlog_period, (char**) &sync_binlog_period, 0, GET_ULONG,
3743
4036
   REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1, 0},
 
4037
  {"table_cache", OPT_TABLE_OPEN_CACHE,
 
4038
   N_("Deprecated; use --table_open_cache instead."),
 
4039
   (char**) &table_cache_size, (char**) &table_cache_size, 0, GET_ULONG,
 
4040
   REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0},
3744
4041
  {"table_definition_cache", OPT_TABLE_DEF_CACHE,
3745
4042
   N_("The number of cached table definitions."),
3746
4043
   (char**) &table_def_size, (char**) &table_def_size,
3762
4059
   N_("How many threads we should create to handle query requests in case of "
3763
4060
      "'thread_handling=pool-of-threads'"),
3764
4061
   (char**) &thread_pool_size, (char**) &thread_pool_size, 0, GET_ULONG,
3765
 
   REQUIRED_ARG, 8, 1, 16384, 0, 1, 0},
 
4062
   REQUIRED_ARG, 20, 1, 16384, 0, 1, 0},
3766
4063
  {"thread_stack", OPT_THREAD_STACK,
3767
4064
   N_("The stack size for each thread."),
3768
4065
   (char**) &my_thread_stack_size,
3800
4097
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
3801
4098
};
3802
4099
 
3803
 
static int show_net_compression(Session *session __attribute__((unused)),
 
4100
static int show_net_compression(THD *thd __attribute__((unused)),
3804
4101
                                SHOW_VAR *var,
3805
4102
                                char *buff __attribute__((unused)))
3806
4103
{
3807
4104
  var->type= SHOW_MY_BOOL;
3808
 
  var->value= (char *)&session->net.compress;
 
4105
  var->value= (char *)&thd->net.compress;
3809
4106
  return 0;
3810
4107
}
3811
4108
 
3812
4109
static st_show_var_func_container
3813
4110
show_net_compression_cont= { &show_net_compression };
3814
4111
 
3815
 
static int show_starttime(Session *session, SHOW_VAR *var, char *buff)
 
4112
static int show_starttime(THD *thd, SHOW_VAR *var, char *buff)
3816
4113
{
3817
4114
  var->type= SHOW_LONG;
3818
4115
  var->value= buff;
3819
 
  *((long *)buff)= (long) (session->query_start() - server_start_time);
 
4116
  *((long *)buff)= (long) (thd->query_start() - server_start_time);
3820
4117
  return 0;
3821
4118
}
3822
4119
 
3823
4120
static st_show_var_func_container
3824
4121
show_starttime_cont= { &show_starttime };
3825
4122
 
3826
 
static int show_flushstatustime(Session *session, SHOW_VAR *var, char *buff)
 
4123
static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff)
3827
4124
{
3828
4125
  var->type= SHOW_LONG;
3829
4126
  var->value= buff;
3830
 
  *((long *)buff)= (long) (session->query_start() - flush_status_time);
 
4127
  *((long *)buff)= (long) (thd->query_start() - flush_status_time);
3831
4128
  return 0;
3832
4129
}
3833
4130
 
3834
4131
static st_show_var_func_container
3835
4132
show_flushstatustime_cont= { &show_flushstatustime };
3836
4133
 
3837
 
static int show_slave_running(Session *session __attribute__((unused)),
 
4134
static int show_slave_running(THD *thd __attribute__((unused)),
3838
4135
                              SHOW_VAR *var, char *buff)
3839
4136
{
3840
4137
  var->type= SHOW_MY_BOOL;
3849
4146
static st_show_var_func_container
3850
4147
show_slave_running_cont= { &show_slave_running };
3851
4148
 
3852
 
static int show_slave_retried_trans(Session *session __attribute__((unused)),
 
4149
static int show_slave_retried_trans(THD *thd __attribute__((unused)),
3853
4150
                                    SHOW_VAR *var, char *buff)
3854
4151
{
3855
4152
  /*
3874
4171
static st_show_var_func_container
3875
4172
show_slave_retried_trans_cont= { &show_slave_retried_trans };
3876
4173
 
3877
 
static int show_slave_received_heartbeats(Session *session __attribute__((unused)),
 
4174
static int show_slave_received_heartbeats(THD *thd __attribute__((unused)),
3878
4175
                                          SHOW_VAR *var, char *buff)
3879
4176
{
3880
4177
  pthread_mutex_lock(&LOCK_active_mi);
3895
4192
static st_show_var_func_container
3896
4193
show_slave_received_heartbeats_cont= { &show_slave_received_heartbeats };
3897
4194
 
3898
 
static int show_heartbeat_period(Session *session __attribute__((unused)),
 
4195
static int show_heartbeat_period(THD *thd __attribute__((unused)),
3899
4196
                                 SHOW_VAR *var, char *buff)
3900
4197
{
3901
4198
  pthread_mutex_lock(&LOCK_active_mi);
3914
4211
static st_show_var_func_container
3915
4212
show_heartbeat_period_cont= { &show_heartbeat_period};
3916
4213
 
3917
 
static int show_open_tables(Session *session __attribute__((unused)),
 
4214
static int show_open_tables(THD *thd __attribute__((unused)),
3918
4215
                            SHOW_VAR *var, char *buff)
3919
4216
{
3920
4217
  var->type= SHOW_LONG;
3923
4220
  return 0;
3924
4221
}
3925
4222
 
3926
 
static int show_table_definitions(Session *session __attribute__((unused)),
 
4223
static int show_table_definitions(THD *thd __attribute__((unused)),
3927
4224
                                  SHOW_VAR *var, char *buff)
3928
4225
{
3929
4226
  var->type= SHOW_LONG;
4010
4307
  {"Tc_log_page_size",         (char*) &tc_log_page_size,       SHOW_LONG},
4011
4308
  {"Tc_log_page_waits",        (char*) &tc_log_page_waits,      SHOW_LONG},
4012
4309
#endif
 
4310
  {"Threads_cached",           (char*) &cached_thread_count,    SHOW_LONG_NOFLUSH},
4013
4311
  {"Threads_connected",        (char*) &connection_count,       SHOW_INT},
4014
4312
  {"Threads_created",          (char*) &thread_created,         SHOW_LONG_NOFLUSH},
4015
4313
  {"Threads_running",          (char*) &thread_running,         SHOW_INT},
4016
4314
  {"Uptime",                   (char*) &show_starttime_cont,         SHOW_FUNC},
4017
4315
  {"Uptime_since_flush_status",(char*) &show_flushstatustime_cont,   SHOW_FUNC},
4018
 
  {NULL, NULL, SHOW_LONG}
 
4316
  {NullS, NullS, SHOW_LONG}
4019
4317
};
4020
4318
 
4021
4319
static void print_version(void)
4026
4324
    version from the output of 'mysqld --version', so don't change it!
4027
4325
  */
4028
4326
  printf("%s  Ver %s for %s on %s (%s)\n",my_progname,
4029
 
         server_version,SYSTEM_TYPE,MACHINE_TYPE, COMPILATION_COMMENT);
 
4327
         server_version,SYSTEM_TYPE,MACHINE_TYPE, DRIZZLE_COMPILATION_COMMENT);
4030
4328
}
4031
4329
 
4032
4330
static void usage(void)
4078
4376
    as these are initialized by my_getopt.
4079
4377
*/
4080
4378
 
4081
 
static void drizzle_init_variables(void)
 
4379
static void mysql_init_variables(void)
4082
4380
{
4083
4381
  /* Things reset to zero */
4084
4382
  opt_skip_slave_start= opt_reckless_slave = 0;
4085
4383
  mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0;
 
4384
  opt_log= opt_slow_log= 0;
4086
4385
  log_output_options= find_bit_type(log_output_str, &log_output_typelib);
4087
4386
  opt_bin_log= 0;
4088
4387
  opt_skip_show_db=0;
4089
 
  opt_logname= opt_binlog_index_name= 0;
 
4388
  opt_logname= opt_binlog_index_name= opt_slow_logname= 0;
4090
4389
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
 
4390
  opt_secure_auth= 0;
4091
4391
  opt_secure_file_priv= 0;
4092
4392
  segfaulted= kill_in_progress= 0;
4093
4393
  cleanup_done= 0;
4095
4395
  defaults_argv= 0;
4096
4396
  server_id_supplied= 0;
4097
4397
  test_flags= select_errors= dropping_tables= ha_open_options=0;
4098
 
  thread_count= thread_running= wake_thread=0;
 
4398
  thread_count= thread_running= kill_cached_threads= wake_thread=0;
4099
4399
  slave_open_temp_tables= 0;
 
4400
  cached_thread_count= 0;
4100
4401
  opt_endinfo= using_udf_functions= 0;
4101
4402
  opt_using_transactions= using_update_log= 0;
4102
4403
  abort_loop= select_thread_in_use= signal_thread_in_use= 0;
4105
4406
  specialflag= 0;
4106
4407
  binlog_cache_use=  binlog_cache_disk_use= 0;
4107
4408
  max_used_connections= slow_launch_threads = 0;
4108
 
  drizzled_user= drizzled_chroot= opt_init_file= opt_bin_logname = 0;
4109
 
  opt_mysql_tmpdir= my_bind_addr_str= NULL;
 
4409
  mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
 
4410
  opt_mysql_tmpdir= my_bind_addr_str= NullS;
4110
4411
  memset(&mysql_tmpdir_list, 0, sizeof(mysql_tmpdir_list));
4111
4412
  memset(&global_status_var, 0, sizeof(global_status_var));
4112
4413
  key_map_full.set_all();
4125
4426
  slave_exec_mode_options= 0;
4126
4427
  slave_exec_mode_options= (uint)
4127
4428
    find_bit_type_or_exit(slave_exec_mode_str, &slave_exec_mode_typelib, NULL);
4128
 
  drizzle_home_ptr= mysql_home;
 
4429
  mysql_home_ptr= mysql_home;
4129
4430
  pidfile_name_ptr= pidfile_name;
4130
4431
  log_error_file_ptr= log_error_file;
4131
4432
  language_ptr= language;
4132
4433
  mysql_data_home= mysql_real_data_home;
4133
 
  session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_BIN_LOG |
 
4434
  thd_startup_options= (OPTION_AUTO_IS_NULL | OPTION_BIN_LOG |
4134
4435
                        OPTION_QUOTE_SHOW_CREATE | OPTION_SQL_NOTES);
4135
4436
  protocol_version= PROTOCOL_VERSION;
4136
4437
  what_to_log= ~ (1L << (uint) COM_TIME);
4137
4438
  refresh_version= 1L;  /* Increments on each reload */
4138
 
  thread_id= 1;
4139
 
  my_stpcpy(server_version, VERSION);
 
4439
  global_query_id= thread_id= 1L;
 
4440
  stpcpy(server_version, DRIZZLE_SERVER_VERSION);
4140
4441
  myisam_recover_options_str= "OFF";
4141
4442
  myisam_stats_method_str= "nulls_unequal";
4142
4443
  threads.empty();
4159
4460
  /* Replication parameters */
4160
4461
  master_info_file= (char*) "master.info",
4161
4462
    relay_log_info_file= (char*) "relay-log.info";
4162
 
  report_host= 0;       /* TO BE DELETED */
 
4463
  report_user= report_password = report_host= 0;        /* TO BE DELETED */
4163
4464
  opt_relay_logname= opt_relaylog_index_name= 0;
4164
4465
 
4165
4466
  /* Variables in libraries */
4166
4467
  charsets_dir= 0;
4167
4468
  default_character_set_name= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
4168
4469
  default_collation_name= compiled_default_collation_name;
 
4470
  sys_charset_system.set((char*) system_charset_info->csname);
4169
4471
  character_set_filesystem_name= (char*) "binary";
4170
4472
  lc_time_names_name= (char*) "en_US";
4171
4473
  /* Set default values for some option variables */
4223
4525
    if (default_collation_name == compiled_default_collation_name)
4224
4526
      default_collation_name= 0;
4225
4527
    break;
 
4528
  case 'l':
 
4529
    opt_log=1;
 
4530
    break;
4226
4531
  case 'h':
4227
4532
    strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1);
4228
4533
    /* Correct pointer set by my_getopt (for embedded library) */
4230
4535
    mysql_data_home_len= strlen(mysql_data_home);
4231
4536
    break;
4232
4537
  case 'u':
4233
 
    if (!drizzled_user || !strcmp(drizzled_user, argument))
4234
 
      drizzled_user= argument;
 
4538
    if (!mysqld_user || !strcmp(mysqld_user, argument))
 
4539
      mysqld_user= argument;
4235
4540
    else
4236
4541
      sql_print_warning(_("Ignoring user change to '%s' because the user was "
4237
4542
                          "set to '%s' earlier on the command line\n"),
4238
 
                        argument, drizzled_user);
 
4543
                        argument, mysqld_user);
4239
4544
    break;
4240
4545
  case 'L':
4241
4546
    strmake(language, argument, sizeof(language)-1);
4365
4670
      }
4366
4671
      break;
4367
4672
    }
 
4673
  case (int) OPT_SLOW_QUERY_LOG:
 
4674
    opt_slow_log= 1;
 
4675
    break;
 
4676
#ifdef WITH_CSV_STORAGE_ENGINE
 
4677
  case  OPT_LOG_OUTPUT:
 
4678
    {
 
4679
      if (!argument || !argument[0])
 
4680
      {
 
4681
        log_output_options= LOG_FILE;
 
4682
        log_output_str= log_output_typelib.type_names[1];
 
4683
      }
 
4684
      else
 
4685
      {
 
4686
        log_output_str= argument;
 
4687
        log_output_options=
 
4688
          find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
 
4689
      }
 
4690
      break;
 
4691
    }
 
4692
#endif
4368
4693
  case (int) OPT_WANT_CORE:
4369
4694
    test_flags |= TEST_CORE_ON_SIGNAL;
4370
4695
    break;
4494
4819
 
4495
4820
/** Handle arguments for multiple key caches. */
4496
4821
 
4497
 
extern "C" char **mysql_getopt_value(const char *keyname, uint32_t key_length,
 
4822
extern "C" char **mysql_getopt_value(const char *keyname, uint key_length,
4498
4823
                                      const struct my_option *option);
4499
4824
 
4500
4825
char**
4501
 
mysql_getopt_value(const char *keyname, uint32_t key_length,
 
4826
mysql_getopt_value(const char *keyname, uint key_length,
4502
4827
                   const struct my_option *option)
4503
4828
{
4504
4829
  switch (option->id) {
4562
4887
  (*argc)++; /* add back one for the progname handle_options removes */
4563
4888
             /* no need to do this for argv as we are discarding it. */
4564
4889
 
 
4890
  if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes ||
 
4891
       opt_log_slow_slave_statements) &&
 
4892
      !opt_slow_log)
 
4893
    sql_print_warning(_("options --log-slow-admin-statements, "
 
4894
                        "--log-queries-not-using-indexes and "
 
4895
                        "--log-slow-slave-statements have no effect if "
 
4896
                        "--log-slow-queries is not set"));
 
4897
 
4565
4898
#if defined(HAVE_BROKEN_REALPATH)
4566
4899
  my_use_symdir=0;
4567
4900
  my_disable_symlinks=1;
4580
4913
    test_flags&= ~TEST_CORE_ON_SIGNAL;
4581
4914
  }
4582
4915
  /* Set global MyISAM variables from delay_key_write_options */
4583
 
  fix_delay_key_write((Session*) 0, OPT_GLOBAL);
 
4916
  fix_delay_key_write((THD*) 0, OPT_GLOBAL);
4584
4917
  /* Set global slave_exec_mode from its option */
4585
4918
  fix_slave_exec_mode(OPT_GLOBAL);
4586
4919
 
4587
 
  if (drizzled_chroot)
4588
 
    set_root(drizzled_chroot);
 
4920
  if (mysqld_chroot)
 
4921
    set_root(mysqld_chroot);
4589
4922
  fix_paths();
4590
4923
 
4591
4924
  /*
4599
4932
  /* Set global variables based on startup options */
4600
4933
  myisam_block_size=(uint) 1 << my_bit_log2(opt_myisam_block_size);
4601
4934
 
 
4935
  /* long_query_time is in microseconds */
 
4936
  global_system_variables.long_query_time= max_system_variables.long_query_time=
 
4937
    (int64_t) (long_query_time * 1000000.0);
 
4938
 
4602
4939
  if (init_global_datetime_format(DRIZZLE_TIMESTAMP_DATE,
4603
4940
                                  &global_system_variables.date_format) ||
4604
4941
      init_global_datetime_format(DRIZZLE_TIMESTAMP_TIME,
4618
4955
  (DRIZZLE_SERVER_SUFFIX is set by the compilation environment)
4619
4956
*/
4620
4957
 
4621
 
#ifdef DRIZZLE_SERVER_SUFFIX
4622
 
#define DRIZZLE_SERVER_SUFFIX_STR STRINGIFY_ARG(DRIZZLE_SERVER_SUFFIX)
4623
 
#else
4624
 
#define DRIZZLE_SERVER_SUFFIX_STR ""
4625
 
#endif
4626
 
 
4627
4958
static void set_server_version(void)
4628
4959
{
4629
 
  char *end= strxmov(server_version, VERSION,
4630
 
                     DRIZZLE_SERVER_SUFFIX_STR, NULL);
4631
 
  if (opt_bin_log)
4632
 
    my_stpcpy(end, "-log");                        // This may slow down system
 
4960
  char *end= strxmov(server_version, DRIZZLE_SERVER_VERSION,
 
4961
                     DRIZZLE_SERVER_SUFFIX_STR, NullS);
 
4962
  if (opt_log || opt_slow_log || opt_bin_log)
 
4963
    stpcpy(end, "-log");                        // This may slow down system
4633
4964
}
4634
4965
 
4635
4966
 
4647
4978
}
4648
4979
 
4649
4980
 
 
4981
/**
 
4982
  Fix filename and replace extension where 'dir' is relative to
 
4983
  mysql_real_data_home.
 
4984
  @return
 
4985
    1 if len(path) > FN_REFLEN
 
4986
*/
 
4987
 
 
4988
bool
 
4989
fn_format_relative_to_data_home(char * to, const char *name,
 
4990
                                const char *dir, const char *extension)
 
4991
{
 
4992
  char tmp_path[FN_REFLEN];
 
4993
  if (!test_if_hard_path(dir))
 
4994
  {
 
4995
    strxnmov(tmp_path,sizeof(tmp_path)-1, mysql_real_data_home,
 
4996
             dir, NullS);
 
4997
    dir=tmp_path;
 
4998
  }
 
4999
  return !fn_format(to, name, dir, extension,
 
5000
                    MY_APPEND_EXT | MY_UNPACK_FILENAME | MY_SAFE_PATH);
 
5001
}
 
5002
 
 
5003
 
4650
5004
static void fix_paths(void)
4651
5005
{
4652
5006
  char buff[FN_REFLEN],*pos;
4653
 
  convert_dirname(mysql_home,mysql_home,NULL);
 
5007
  convert_dirname(mysql_home,mysql_home,NullS);
4654
5008
  /* Resolve symlinks to allow 'mysql_home' to be a relative symlink */
4655
5009
  my_realpath(mysql_home,mysql_home,MYF(0));
4656
5010
  /* Ensure that mysql_home ends in FN_LIBCHAR */
4660
5014
    pos[0]= FN_LIBCHAR;
4661
5015
    pos[1]= 0;
4662
5016
  }
4663
 
  convert_dirname(mysql_real_data_home,mysql_real_data_home,NULL);
 
5017
  convert_dirname(mysql_real_data_home,mysql_real_data_home,NullS);
4664
5018
  (void) fn_format(buff, mysql_real_data_home, "", "",
4665
5019
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
4666
5020
  (void) unpack_dirname(mysql_unpacked_real_data_home, buff);
4667
 
  convert_dirname(language,language,NULL);
 
5021
  convert_dirname(language,language,NullS);
4668
5022
  (void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir
4669
5023
  (void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
4670
5024
  (void) my_load_path(pidfile_name,pidfile_name,mysql_real_data_home);
4674
5028
 
4675
5029
  char *sharedir=get_relative_path(SHAREDIR);
4676
5030
  if (test_if_hard_path(sharedir))
4677
 
    strncpy(buff,sharedir,sizeof(buff)-1);              /* purecov: tested */
 
5031
    strmake(buff,sharedir,sizeof(buff)-1);              /* purecov: tested */
4678
5032
  else
4679
 
  {
4680
 
    strcpy(buff, mysql_home);
4681
 
    strncat(buff, sharedir, sizeof(buff)-strlen(mysql_home)-1);
4682
 
  }
4683
 
  convert_dirname(buff,buff,NULL);
 
5033
    strxnmov(buff,sizeof(buff)-1,mysql_home,sharedir,NullS);
 
5034
  convert_dirname(buff,buff,NullS);
4684
5035
  (void) my_load_path(language,language,buff);
4685
5036
 
4686
5037
  /* If --character-sets-dir isn't given, use shared library dir */
4687
5038
  if (charsets_dir != mysql_charsets_dir)
4688
5039
  {
4689
 
    strcpy(mysql_charsets_dir, buff);
4690
 
    strncat(mysql_charsets_dir, CHARSET_DIR,
4691
 
            sizeof(mysql_charsets_dir)-strlen(buff)-1);
 
5040
    strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir)-1, buff,
 
5041
             CHARSET_DIR, NullS);
4692
5042
  }
4693
5043
  (void) my_load_path(mysql_charsets_dir, mysql_charsets_dir, buff);
4694
 
  convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NULL);
 
5044
  convert_dirname(mysql_charsets_dir, mysql_charsets_dir, NullS);
4695
5045
  charsets_dir=mysql_charsets_dir;
4696
5046
 
4697
5047
  if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir))
4707
5057
   */
4708
5058
  if (opt_secure_file_priv)
4709
5059
  {
4710
 
    convert_dirname(buff, opt_secure_file_priv, NULL);
4711
 
    free(opt_secure_file_priv);
 
5060
    convert_dirname(buff, opt_secure_file_priv, NullS);
 
5061
    my_free(opt_secure_file_priv, MYF(0));
4712
5062
    opt_secure_file_priv= my_strdup(buff, MYF(MY_FAE));
4713
5063
  }
4714
5064
}
4816
5166
    char buff[21], *end;
4817
5167
    end= int10_to_str((long) getpid(), buff, 10);
4818
5168
    *end++= '\n';
4819
 
    if (!my_write(file, (unsigned char*) buff, (uint) (end-buff), MYF(MY_WME | MY_NABP)))
 
5169
    if (!my_write(file, (uchar*) buff, (uint) (end-buff), MYF(MY_WME | MY_NABP)))
4820
5170
    {
4821
5171
      (void) my_close(file, MYF(0));
4822
5172
      return;
4828
5178
}
4829
5179
 
4830
5180
/** Clear most status variables. */
4831
 
void refresh_status(Session *session)
 
5181
void refresh_status(THD *thd)
4832
5182
{
4833
5183
  pthread_mutex_lock(&LOCK_status);
4834
5184
 
4835
5185
  /* Add thread's status variabes to global status */
4836
 
  add_to_status(&global_status_var, &session->status_var);
 
5186
  add_to_status(&global_status_var, &thd->status_var);
4837
5187
 
4838
5188
  /* Reset thread's status variables */
4839
 
  memset(&session->status_var, 0, sizeof(session->status_var));
 
5189
  memset(&thd->status_var, 0, sizeof(thd->status_var));
4840
5190
 
4841
5191
  /* Reset some global variables */
4842
5192
  reset_status_vars();
4864
5214
 
4865
5215
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
4866
5216
/* Used templates */
4867
 
template class I_List<Session>;
4868
 
template class I_List_iterator<Session>;
 
5217
template class I_List<THD>;
 
5218
template class I_List_iterator<THD>;
4869
5219
template class I_List<i_string>;
4870
5220
template class I_List<i_string_pair>;
4871
5221
template class I_List<NAMED_LIST>;