~atcurtis/drizzle/experimental1

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Antony Curtis
  • Date: 2008-07-30 20:09:32 UTC
  • mfrom: (134.1.105 drizzle)
  • Revision ID: atcurtis@dhcp-172-29-58-124.smo.corp.google.com-20080730200932-t6sop64d2jryozy3
merge from main development

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include "mysql_priv.h"
17
17
#include <m_ctype.h>
18
 
#include <my_dir.h>
19
 
#include <my_bit.h>
 
18
#include <mysys/my_bit.h>
20
19
#include "slave.h"
21
20
#include "rpl_mi.h"
22
21
#include "sql_repl.h"
24
23
#include "repl_failsafe.h"
25
24
#include "stacktrace.h"
26
25
#include "mysqld_suffix.h"
27
 
#include "mysys_err.h"
28
26
#include "protocol.h"
 
27
#include <mysys/mysys_err.h>
 
28
#include <sys/poll.h>
 
29
#include <netinet/tcp.h>
29
30
 
30
 
#include "../storage/myisam/ha_myisam.h"
 
31
#include <storage/myisam/ha_myisam.h>
31
32
 
32
33
#ifdef HAVE_SYS_PRCTL_H
33
34
#include <sys/prctl.h>
37
38
#define DEFAULT_SKIP_THREAD_PRIORITY 0
38
39
#endif
39
40
 
40
 
#include <thr_alarm.h>
41
 
#include <errmsg.h>
 
41
#include <mysys/thr_alarm.h>
 
42
#include <libdrizzle/errmsg.h>
42
43
 
43
44
#define mysqld_charset &my_charset_latin1
44
45
 
66
67
#ifndef __GNU_LIBRARY__
67
68
#define __GNU_LIBRARY__                         // Skip warnings in getopt.h
68
69
#endif
69
 
#include <my_getopt.h>
 
70
#include <mysys/my_getopt.h>
70
71
#ifdef HAVE_SYSENT_H
71
72
#include <sysent.h>
72
73
#endif
76
77
#ifdef HAVE_GRP_H
77
78
#include <grp.h>
78
79
#endif
79
 
#include <my_net.h>
80
80
 
81
81
#include <sys/resource.h>
82
82
 
146
146
 
147
147
#define MYSQL_KILL_SIGNAL SIGTERM
148
148
 
149
 
#include <my_pthread.h>                 // For thr_setconcurency()
 
149
#include <mysys/my_pthread.h>                   // For thr_setconcurency()
150
150
 
151
151
#ifdef SOLARIS
152
152
extern "C" int gethostname(char *name, int namelen);
218
218
/* static variables */
219
219
 
220
220
/* the default log output is log tables */
221
 
static bool lower_case_table_names_used= 0;
222
221
static bool volatile select_thread_in_use, signal_thread_in_use;
223
222
static bool volatile ready_to_exit;
224
223
static bool opt_debugging= 0, opt_console= 0;
249
248
ulong log_output_options;
250
249
bool opt_log_queries_not_using_indexes= false;
251
250
bool opt_error_log= IF_WIN(1,0);
252
 
bool opt_disable_networking= false;
253
251
bool opt_skip_show_db= false;
254
252
bool opt_character_set_client_handshake= 1;
255
253
bool server_id_supplied = 0;
266
264
bool opt_safe_user_create = 0;
267
265
bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
268
266
bool opt_log_slave_updates= 0;
 
267
static struct pollfd fds[UINT8_MAX];
 
268
static uint8_t pollfd_count= 0;
269
269
 
270
270
/*
271
271
  Legacy global handlerton. These will be removed (please do not add more).
281
281
char* opt_secure_file_priv= 0;
282
282
bool opt_log_slow_admin_statements= 0;
283
283
bool opt_log_slow_slave_statements= 0;
284
 
bool lower_case_file_system= 0;
285
284
bool opt_old_style_user_limits= 0;
286
285
bool trust_function_creators= 0;
287
286
/*
304
303
uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options;
305
304
uint mysqld_port_timeout;
306
305
uint delay_key_write_options, protocol_version;
307
 
uint lower_case_table_names;
 
306
uint lower_case_table_names= 1;
308
307
uint tc_heuristic_recover= 0;
309
308
uint volatile thread_count, thread_running;
310
309
uint64_t thd_startup_options;
404
403
Ge_creator ge_creator;
405
404
Le_creator le_creator;
406
405
 
407
 
FILE *bootstrap_file;
408
 
int bootstrap_error;
409
406
FILE *stderror_file=0;
410
407
 
411
408
I_List<THD> threads;
463
460
#ifdef HAVE_STACK_TRACE_ON_SEGV
464
461
static bool opt_do_pstack;
465
462
#endif /* HAVE_STACK_TRACE_ON_SEGV */
466
 
static bool opt_bootstrap, opt_myisam_log;
 
463
static bool opt_myisam_log;
467
464
static int cleanup_done;
468
465
static ulong opt_specialflag, opt_myisam_block_size;
469
466
static char *opt_binlog_index_name;
473
470
static char **defaults_argv;
474
471
static char *opt_bin_logname;
475
472
 
476
 
static my_socket ip_sock;
477
473
struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD()
478
474
 
479
475
struct passwd *user_info;
509
505
static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
510
506
                                   const char *option);
511
507
static void clean_up(bool print_message);
512
 
static int test_if_case_insensitive(const char *dir_name);
513
508
 
514
509
static void usage(void);
515
510
static void start_signal_handler(void);
563
558
 
564
559
 
565
560
  /* Abort listening to new connections */
566
 
  if (!opt_disable_networking )
567
561
  {
568
 
    if (ip_sock != INVALID_SOCKET)
 
562
    int x;
 
563
    
 
564
    for (x= 0; x < pollfd_count; x++)
569
565
    {
570
 
      (void) shutdown(ip_sock, SHUT_RDWR);
571
 
      (void) closesocket(ip_sock);
572
 
      ip_sock= INVALID_SOCKET;
 
566
      if (fds[x].fd != INVALID_SOCKET)
 
567
      {
 
568
        (void) shutdown(fds[x].fd, SHUT_RDWR);
 
569
        (void) closesocket(fds[x].fd);
 
570
        fds[x].fd= INVALID_SOCKET;
 
571
      }
573
572
    }
574
573
  }
 
574
 
575
575
  end_thr_alarm(0);                      // Abort old alarms.
576
576
 
577
577
  /*
652
652
static void close_server_sock()
653
653
{
654
654
#ifdef HAVE_CLOSE_SERVER_SOCK
655
 
  my_socket tmp_sock;
656
 
  tmp_sock=ip_sock;
657
 
  if (tmp_sock != INVALID_SOCKET)
658
655
  {
659
 
    ip_sock=INVALID_SOCKET;
660
 
    VOID(shutdown(tmp_sock, SHUT_RDWR));
 
656
    int x;
 
657
    
 
658
    for (x= 0; x < pollfd_count; x++)
 
659
    {
 
660
      if (fds[x].fd != INVALID_SOCKET)
 
661
      {
 
662
        (void) shutdown(fds[x].fd, SHUT_RDWR);
 
663
        (void) closesocket(fds[x].fd);
 
664
        fds[x].fd= INVALID_SOCKET;
 
665
      }
 
666
    }
661
667
  }
662
 
  return;;
663
668
#endif
664
669
}
665
670
 
789
794
    sql_print_error("Aborting\n");
790
795
  else if (opt_help)
791
796
    usage();
792
 
  clean_up(!opt_help && (exit_code || !opt_bootstrap)); /* purecov: inspected */
 
797
  clean_up(!opt_help && (exit_code)); /* purecov: inspected */
793
798
  mysqld_exit(exit_code);
794
799
}
795
800
 
861
866
  delete rpl_filter;
862
867
  vio_end();
863
868
 
864
 
  if (!opt_bootstrap)
865
 
    (void) my_delete(pidfile_name,MYF(0));      // This may not always exist
 
869
  (void) my_delete(pidfile_name,MYF(0));        // This may not always exist
 
870
 
866
871
  if (print_message && errmesg && server_start_time)
867
872
    sql_print_information(ER(ER_SHUTDOWN_COMPLETE),my_progname);
868
873
  thread_scheduler.end();
940
945
static void set_ports()
941
946
{
942
947
  char  *env;
943
 
  if (!mysqld_port && !opt_disable_networking)
 
948
  if (!mysqld_port)
944
949
  {                                     // Get port if not from commandline
945
950
    mysqld_port= MYSQL_PORT;
946
951
 
954
959
      line options.
955
960
    */
956
961
 
957
 
#if MYSQL_PORT_DEFAULT == 0
958
962
    struct  servent *serv_ptr;
959
963
    if ((serv_ptr= getservbyname("mysql", "tcp")))
960
964
      mysqld_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
961
 
#endif
 
965
 
962
966
    if ((env = getenv("MYSQL_TCP_PORT")))
963
967
      mysqld_port= (uint) atoi(env);            /* purecov: inspected */
 
968
 
 
969
    assert(mysqld_port);
964
970
  }
965
971
}
966
972
 
989
995
  }
990
996
  if (!user)
991
997
  {
992
 
    if (!opt_bootstrap)
993
 
    {
994
 
      sql_print_error("Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!\n");
995
 
      unireg_abort(1);
996
 
    }
 
998
    sql_print_error("Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!\n");
 
999
    unireg_abort(1);
 
1000
 
997
1001
    return NULL;
998
1002
  }
999
1003
  /* purecov: begin tested */
1087
1091
 
1088
1092
static void network_init(void)
1089
1093
{
1090
 
  int   arg;
1091
1094
  int   ret;
1092
1095
  uint  waited;
1093
1096
  uint  this_wait;
1094
1097
  uint  retry;
1095
1098
  char port_buf[NI_MAXSERV];
 
1099
  struct addrinfo *ai;
 
1100
  struct addrinfo *next;
 
1101
  struct addrinfo hints;
 
1102
  int error;
1096
1103
 
1097
1104
  if (thread_scheduler.init())
1098
1105
    unireg_abort(1);                    /* purecov: inspected */
1099
1106
 
1100
1107
  set_ports();
1101
1108
 
1102
 
  if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
1103
 
  {
1104
 
    struct addrinfo *ai;
1105
 
    struct addrinfo hints;
1106
 
    int error;
1107
 
 
1108
 
    bzero(&hints, sizeof (hints));
1109
 
    hints.ai_flags= AI_PASSIVE;
1110
 
    hints.ai_socktype= SOCK_STREAM;
1111
 
    hints.ai_family= AF_UNSPEC;
1112
 
 
1113
 
    snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1114
 
    error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1115
 
    if (error != 0)
1116
 
    {
1117
 
      sql_perror(ER(ER_IPSOCK_ERROR));          /* purecov: tested */
1118
 
      unireg_abort(1);                          /* purecov: tested */
1119
 
    }
1120
 
 
1121
 
 
1122
 
    ip_sock= socket(ai->ai_family, ai->ai_socktype,
1123
 
                    ai->ai_protocol);
 
1109
  memset(fds, 0, sizeof(struct pollfd) * UINT8_MAX);
 
1110
  memset(&hints, 0, sizeof (hints));
 
1111
  hints.ai_flags= AI_PASSIVE;
 
1112
  hints.ai_socktype= SOCK_STREAM;
 
1113
  hints.ai_family= AF_INET;
 
1114
  hints.ai_protocol= IPPROTO_TCP;
 
1115
 
 
1116
  snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
 
1117
  error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
 
1118
  if (error != 0)
 
1119
  {
 
1120
    sql_perror(ER(ER_IPSOCK_ERROR));            /* purecov: tested */
 
1121
    unireg_abort(1);                            /* purecov: tested */
 
1122
  }
 
1123
 
 
1124
  for (next= ai, pollfd_count= 0; next; next= next->ai_next, pollfd_count++)
 
1125
  {
 
1126
    int ip_sock;
 
1127
 
 
1128
    ip_sock= socket(next->ai_family, next->ai_socktype, next->ai_protocol);
1124
1129
 
1125
1130
    if (ip_sock == INVALID_SOCKET)
1126
1131
    {
1128
1133
      unireg_abort(1);                          /* purecov: tested */
1129
1134
    }
1130
1135
 
1131
 
    /*
1132
 
      We should not use SO_REUSEADDR on windows as this would enable a
1133
 
      user to open two mysqld servers with the same TCP/IP port.
1134
 
    */
1135
 
    arg= 1;
1136
 
    (void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
 
1136
    fds[pollfd_count].fd= ip_sock;
 
1137
    fds[pollfd_count].events= POLLIN | POLLERR;
1137
1138
 
1138
 
#ifdef IPV6_V6ONLY
1139
 
     /*
1140
 
       For interoperability with older clients, IPv6 socket should
1141
 
       listen on both IPv6 and IPv4 wildcard addresses.
1142
 
       Turn off IPV6_V6ONLY option.
1143
 
     */
1144
 
    if (ai->ai_family == AF_INET6)
 
1139
    /* Add options for our listening socket */
1145
1140
    {
1146
 
      arg= 0;      
1147
 
      (void) setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
1148
 
                sizeof(arg));
 
1141
      struct linger ling = {0, 0};
 
1142
      int flags =1;
 
1143
 
 
1144
      (void) setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&flags, sizeof(flags));
 
1145
      (void) setsockopt(ip_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
 
1146
      (void) setsockopt(ip_sock, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling));
 
1147
      (void) setsockopt(ip_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
1149
1148
    }
1150
 
#endif
 
1149
 
 
1150
 
1151
1151
    /*
1152
1152
      Sometimes the port is not released fast enough when stopping and
1153
1153
      restarting the server. This happens quite often with the test suite
1158
1158
    */
1159
1159
    for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
1160
1160
    {
1161
 
      if (((ret= bind(ip_sock, ai->ai_addr, ai->ai_addrlen)) >= 0 ) ||
 
1161
      if (((ret= bind(ip_sock, next->ai_addr, next->ai_addrlen)) >= 0 ) ||
1162
1162
          (socket_errno != SOCKET_EADDRINUSE) ||
1163
1163
          (waited >= mysqld_port_timeout))
1164
1164
        break;
1170
1170
    if (ret < 0)
1171
1171
    {
1172
1172
      sql_perror("Can't start server: Bind on TCP/IP port");
1173
 
      sql_print_error("Do you already have another mysqld server running on port: %d ?",mysqld_port);
 
1173
      sql_print_error("Do you already have another drizzled server running on port: %d ?",mysqld_port);
1174
1174
      unireg_abort(1);
1175
1175
    }
1176
1176
    if (listen(ip_sock,(int) back_log) < 0)
1182
1182
    }
1183
1183
  }
1184
1184
 
1185
 
  return;;
 
1185
  return;
1186
1186
}
1187
1187
 
1188
1188
/**
1667
1667
  (void) sigaddset(&set,SIGTSTP);
1668
1668
 
1669
1669
  /* Save pid to this process (or thread on Linux) */
1670
 
  if (!opt_bootstrap)
1671
 
    create_pid_file();
 
1670
  create_pid_file();
1672
1671
 
1673
1672
#ifdef HAVE_STACK_TRACE_ON_SEGV
1674
1673
  if (opt_do_pstack)
2218
2217
  if (my_database_names_init())
2219
2218
    return 1;
2220
2219
 
2221
 
  /*
2222
 
    Ensure that lower_case_table_names is set on system where we have case
2223
 
    insensitive names.  If this is not done the users MyISAM tables will
2224
 
    get corrupted if accesses with names of different case.
2225
 
  */
2226
 
  lower_case_file_system= test_if_case_insensitive(mysql_real_data_home);
2227
 
  if (!lower_case_table_names && lower_case_file_system == 1)
2228
 
  {
2229
 
    if (lower_case_table_names_used)
2230
 
    {
2231
 
      if (global_system_variables.log_warnings)
2232
 
        sql_print_warning("\
2233
 
You have forced lower_case_table_names to 0 through a command-line \
2234
 
option, even though your file system '%s' is case insensitive.  This means \
2235
 
that you can corrupt a MyISAM table by accessing it with different cases. \
2236
 
You should consider changing lower_case_table_names to 1 or 2",
2237
 
                        mysql_real_data_home);
2238
 
    }
2239
 
    else
2240
 
    {
2241
 
      if (global_system_variables.log_warnings)
2242
 
        sql_print_warning("Setting lower_case_table_names=2 because file system for %s is case insensitive", mysql_real_data_home);
2243
 
      lower_case_table_names= 2;
2244
 
    }
2245
 
  }
2246
 
  else if (lower_case_table_names == 2 &&
2247
 
           !(lower_case_file_system=
2248
 
             (test_if_case_insensitive(mysql_real_data_home) == 1)))
2249
 
  {
2250
 
    if (global_system_variables.log_warnings)
2251
 
      sql_print_warning("lower_case_table_names was set to 2, even though your "
2252
 
                        "the file system '%s' is case sensitive.  Now setting "
2253
 
                        "lower_case_table_names to 0 to avoid future problems.",
2254
 
                        mysql_real_data_home);
2255
 
    lower_case_table_names= 0;
2256
 
  }
2257
 
  else
2258
 
  {
2259
 
    lower_case_file_system=
2260
 
      (test_if_case_insensitive(mysql_real_data_home) == 1);
2261
 
  }
2262
2220
 
2263
2221
  /* Reset table_alias_charset, now that lower_case_table_names is set. */
2264
 
  table_alias_charset= (lower_case_table_names ?
2265
 
                        files_charset_info :
2266
 
                        &my_charset_bin);
 
2222
  lower_case_table_names= 1; /* This we need to look at */
 
2223
  table_alias_charset= files_charset_info;
2267
2224
 
2268
2225
  return 0;
2269
2226
}
2515
2472
    }
2516
2473
    if (!ha_storage_engine_is_enabled(hton))
2517
2474
    {
2518
 
      if (!opt_bootstrap)
2519
 
      {
2520
 
        sql_print_error("Default storage engine (%s) is not available",
2521
 
                        default_storage_engine_str);
2522
 
        unireg_abort(1);
2523
 
      }
 
2475
      sql_print_error("Default storage engine (%s) is not available",
 
2476
                      default_storage_engine_str);
 
2477
      unireg_abort(1);
2524
2478
      assert(global_system_variables.table_plugin);
2525
2479
    }
2526
2480
    else
2693
2647
  error_handler_hook= my_message_sql;
2694
2648
  start_signal_handler();                               // Creates pidfile
2695
2649
 
2696
 
  if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
 
2650
  if (mysql_rm_tmp_tables() || my_tz_init((THD *)0, default_tz_name, false))
2697
2651
  {
2698
2652
    abort_loop=1;
2699
2653
    select_thread_in_use=0;
2700
2654
    (void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
2701
2655
 
2702
 
    if (!opt_bootstrap)
2703
 
      (void) my_delete(pidfile_name,MYF(MY_WME));       // Not needed anymore
 
2656
    (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
2704
2657
 
2705
2658
    exit(1);
2706
2659
  }
2707
2660
 
2708
2661
  init_status_vars();
2709
 
  if (opt_bootstrap) /* If running with bootstrap, do not start replication. */
2710
 
    opt_skip_slave_start= 1;
2711
2662
  /*
2712
2663
    init_slave() must be called after the thread keys are created.
2713
2664
    Some parts of the code (e.g. SHOW STATUS LIKE 'slave_running' and other
2812
2763
inline void kill_broken_server()
2813
2764
{
2814
2765
  /* hack to get around signals ignored in syscalls for problem OS's */
2815
 
  if ((!opt_disable_networking && ip_sock == INVALID_SOCKET))
 
2766
  if ((ip_sock == INVALID_SOCKET))
2816
2767
  {
2817
2768
    select_thread_in_use = 0;
2818
2769
    /* The following call will never return */
2828
2779
 
2829
2780
void handle_connections_sockets()
2830
2781
{
 
2782
  int x;
2831
2783
  my_socket sock,new_sock;
2832
2784
  uint error_count=0;
2833
 
  uint max_used_connection= (uint)ip_sock+1;
2834
 
  fd_set readFDs,clientFDs;
2835
2785
  THD *thd;
2836
2786
  struct sockaddr_storage cAddr;
2837
 
  int ip_flags=0, flags;
2838
2787
  st_vio *vio_tmp;
2839
2788
 
2840
 
  FD_ZERO(&clientFDs);
2841
 
  if (ip_sock != INVALID_SOCKET)
2842
 
  {
2843
 
    FD_SET(ip_sock,&clientFDs);
2844
 
    ip_flags = fcntl(ip_sock, F_GETFL, 0);
2845
 
  }
2846
2789
  MAYBE_BROKEN_SYSCALL;
2847
2790
  while (!abort_loop)
2848
2791
  {
2849
 
    readFDs=clientFDs;
2850
 
    if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
 
2792
    int number_of;
 
2793
 
 
2794
    if ((number_of= poll(fds, pollfd_count, -1)) == -1)
2851
2795
    {
2852
2796
      if (socket_errno != SOCKET_EINTR)
2853
2797
      {
2857
2801
      MAYBE_BROKEN_SYSCALL
2858
2802
      continue;
2859
2803
    }
 
2804
    if (number_of == 0)
 
2805
      continue;
 
2806
    
 
2807
#ifdef FIXME_IF_WE_WERE_KEEPING_THIS
 
2808
    assert(number_of > 1); /* Not handling this at the moment */
 
2809
#endif
 
2810
 
2860
2811
    if (abort_loop)
2861
2812
    {
2862
2813
      MAYBE_BROKEN_SYSCALL;
2863
2814
      break;
2864
2815
    }
2865
2816
 
2866
 
    /* Is this a new connection request ? */
 
2817
    for (x= 0, sock= -1; x < pollfd_count; x++)
2867
2818
    {
2868
 
      sock = ip_sock;
2869
 
      flags= ip_flags;
 
2819
      if (fds[x].revents == POLLIN)
 
2820
      {
 
2821
        sock= fds[x].fd;
 
2822
        break;
 
2823
      }
2870
2824
    }
 
2825
    assert(sock != -1);
2871
2826
 
2872
 
#if !defined(NO_FCNTL_NONBLOCK)
2873
 
    if (!(test_flags & TEST_BLOCKING))
2874
 
    {
2875
 
#if defined(O_NONBLOCK)
2876
 
      fcntl(sock, F_SETFL, flags | O_NONBLOCK);
2877
 
#elif defined(O_NDELAY)
2878
 
      fcntl(sock, F_SETFL, flags | O_NDELAY);
2879
 
#endif
2880
 
    }
2881
 
#endif /* NO_FCNTL_NONBLOCK */
2882
2827
    for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
2883
2828
    {
2884
2829
      size_socket length= sizeof(struct sockaddr_storage);
2885
2830
      new_sock= accept(sock, (struct sockaddr *)(&cAddr),
2886
2831
                       &length);
2887
 
      if (new_sock != INVALID_SOCKET ||
2888
 
          (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
 
2832
      if (new_sock != INVALID_SOCKET || (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
2889
2833
        break;
2890
 
      MAYBE_BROKEN_SYSCALL;
2891
 
#if !defined(NO_FCNTL_NONBLOCK)
2892
 
      if (!(test_flags & TEST_BLOCKING))
2893
 
      {
2894
 
        if (retry == MAX_ACCEPT_RETRY - 1)
2895
 
          fcntl(sock, F_SETFL, flags);          // Try without O_NONBLOCK
2896
 
      }
2897
 
#endif
2898
2834
    }
2899
 
#if !defined(NO_FCNTL_NONBLOCK)
2900
 
    if (!(test_flags & TEST_BLOCKING))
2901
 
      fcntl(sock, F_SETFL, flags);
2902
 
#endif
 
2835
 
 
2836
 
2903
2837
    if (new_sock == INVALID_SOCKET)
2904
2838
    {
2905
2839
      if ((error_count++ & 255) == 0)           // This can happen often
3642
3576
   "The argument will be treated as a decimal value with microsecond precission.",
3643
3577
   (char**) &long_query_time, (char**) &long_query_time, 0, GET_DOUBLE,
3644
3578
   REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0},
3645
 
  {"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES,
3646
 
   "If set to 1 table names are stored in lowercase on disk and table names will be case-insensitive.  Should be set to 2 if you are using a case insensitive file system",
3647
 
   (char**) &lower_case_table_names,
3648
 
   (char**) &lower_case_table_names, 0, GET_UINT, OPT_ARG,
3649
 
#ifdef FN_NO_CASE_SENCE
3650
 
    1
3651
 
#else
3652
 
    0
3653
 
#endif
3654
 
   , 0, 2, 0, 1, 0},
3655
3579
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
3656
3580
   "Max packetlength to send/receive from to server.",
3657
3581
   (char**) &global_system_variables.max_allowed_packet,
4250
4174
  opt_log= opt_slow_log= 0;
4251
4175
  log_output_options= find_bit_type(log_output_str, &log_output_typelib);
4252
4176
  opt_bin_log= 0;
4253
 
  opt_disable_networking= opt_skip_show_db=0;
 
4177
  opt_skip_show_db=0;
4254
4178
  opt_logname= opt_binlog_index_name= opt_slow_logname= 0;
4255
4179
  opt_tc_log_file= (char *)"tc.log";      // no hostname in tc_log file name !
4256
4180
  opt_secure_auth= 0;
4257
4181
  opt_secure_file_priv= 0;
4258
 
  opt_bootstrap= opt_myisam_log= 0;
 
4182
  opt_myisam_log= 0;
4259
4183
  segfaulted= kill_in_progress= 0;
4260
4184
  cleanup_done= 0;
4261
4185
  defaults_argc= 0;
4276
4200
  mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
4277
4201
  errmesg= 0;
4278
4202
  opt_mysql_tmpdir= my_bind_addr_str= NullS;
4279
 
  bzero((uchar*) &mysql_tmpdir_list, sizeof(mysql_tmpdir_list));
4280
 
  bzero((char *) &global_status_var, sizeof(global_status_var));
 
4203
  memset((uchar*) &mysql_tmpdir_list, 0, sizeof(mysql_tmpdir_list));
 
4204
  memset((char *) &global_status_var, 0, sizeof(global_status_var));
4281
4205
  key_map_full.set_all();
4282
4206
 
4283
4207
  /* Character sets */
4295
4219
  slave_exec_mode_options= (uint)
4296
4220
    find_bit_type_or_exit(slave_exec_mode_str, &slave_exec_mode_typelib, NULL);
4297
4221
  opt_specialflag= SPECIAL_ENGLISH;
4298
 
  ip_sock= INVALID_SOCKET;
4299
4222
  mysql_home_ptr= mysql_home;
4300
4223
  pidfile_name_ptr= pidfile_name;
4301
4224
  log_error_file_ptr= log_error_file;
4453
4376
    opt_error_log= 1;
4454
4377
    break;
4455
4378
  case (int)OPT_REPLICATE_IGNORE_DB:
4456
 
  {
4457
 
    rpl_filter->add_ignore_db(argument);
4458
 
    break;
4459
 
  }
 
4379
    {
 
4380
      rpl_filter->add_ignore_db(argument);
 
4381
      break;
 
4382
    }
4460
4383
  case (int)OPT_REPLICATE_DO_DB:
4461
 
  {
4462
 
    rpl_filter->add_do_db(argument);
4463
 
    break;
4464
 
  }
 
4384
    {
 
4385
      rpl_filter->add_do_db(argument);
 
4386
      break;
 
4387
    }
4465
4388
  case (int)OPT_REPLICATE_REWRITE_DB:
4466
 
  {
4467
 
    char* key = argument,*p, *val;
4468
 
 
4469
 
    if (!(p= strstr(argument, "->")))
4470
 
    {
4471
 
      fprintf(stderr,
4472
 
              "Bad syntax in replicate-rewrite-db - missing '->'!\n");
4473
 
      exit(1);
4474
 
    }
4475
 
    val= p--;
4476
 
    while (my_isspace(mysqld_charset, *p) && p > argument)
4477
 
      *p-- = 0;
4478
 
    if (p == argument)
4479
 
    {
4480
 
      fprintf(stderr,
4481
 
              "Bad syntax in replicate-rewrite-db - empty FROM db!\n");
4482
 
      exit(1);
4483
 
    }
4484
 
    *val= 0;
4485
 
    val+= 2;
4486
 
    while (*val && my_isspace(mysqld_charset, *val))
4487
 
      *val++;
4488
 
    if (!*val)
4489
 
    {
4490
 
      fprintf(stderr,
4491
 
              "Bad syntax in replicate-rewrite-db - empty TO db!\n");
4492
 
      exit(1);
4493
 
    }
4494
 
 
4495
 
    rpl_filter->add_db_rewrite(key, val);
4496
 
    break;
4497
 
  }
 
4389
    {
 
4390
      char* key = argument,*p, *val;
 
4391
 
 
4392
      if (!(p= strstr(argument, "->")))
 
4393
      {
 
4394
        fprintf(stderr,
 
4395
                "Bad syntax in replicate-rewrite-db - missing '->'!\n");
 
4396
        exit(1);
 
4397
      }
 
4398
      val= p--;
 
4399
      while (my_isspace(mysqld_charset, *p) && p > argument)
 
4400
        *p-- = 0;
 
4401
      if (p == argument)
 
4402
      {
 
4403
        fprintf(stderr,
 
4404
                "Bad syntax in replicate-rewrite-db - empty FROM db!\n");
 
4405
        exit(1);
 
4406
      }
 
4407
      *val= 0;
 
4408
      val+= 2;
 
4409
      while (*val && my_isspace(mysqld_charset, *val))
 
4410
        *val++;
 
4411
      if (!*val)
 
4412
      {
 
4413
        fprintf(stderr,
 
4414
                "Bad syntax in replicate-rewrite-db - empty TO db!\n");
 
4415
        exit(1);
 
4416
      }
 
4417
 
 
4418
      rpl_filter->add_db_rewrite(key, val);
 
4419
      break;
 
4420
    }
4498
4421
 
4499
4422
  case (int)OPT_BINLOG_IGNORE_DB:
4500
 
  {
4501
 
    binlog_filter->add_ignore_db(argument);
4502
 
    break;
4503
 
  }
 
4423
    {
 
4424
      binlog_filter->add_ignore_db(argument);
 
4425
      break;
 
4426
    }
4504
4427
  case OPT_BINLOG_FORMAT:
4505
 
  {
4506
 
    int id;
4507
 
    id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
4508
 
    global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
4509
 
    break;
4510
 
  }
 
4428
    {
 
4429
      int id;
 
4430
      id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
 
4431
      global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
 
4432
      break;
 
4433
    }
4511
4434
  case (int)OPT_BINLOG_DO_DB:
4512
 
  {
4513
 
    binlog_filter->add_do_db(argument);
4514
 
    break;
4515
 
  }
 
4435
    {
 
4436
      binlog_filter->add_do_db(argument);
 
4437
      break;
 
4438
    }
4516
4439
  case (int)OPT_REPLICATE_DO_TABLE:
4517
 
  {
4518
 
    if (rpl_filter->add_do_table(argument))
4519
4440
    {
4520
 
      fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4521
 
      exit(1);
 
4441
      if (rpl_filter->add_do_table(argument))
 
4442
      {
 
4443
        fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
 
4444
        exit(1);
 
4445
      }
 
4446
      break;
4522
4447
    }
4523
 
    break;
4524
 
  }
4525
4448
  case (int)OPT_REPLICATE_WILD_DO_TABLE:
4526
 
  {
4527
 
    if (rpl_filter->add_wild_do_table(argument))
4528
4449
    {
4529
 
      fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
4530
 
      exit(1);
 
4450
      if (rpl_filter->add_wild_do_table(argument))
 
4451
      {
 
4452
        fprintf(stderr, "Could not add do table rule '%s'!\n", argument);
 
4453
        exit(1);
 
4454
      }
 
4455
      break;
4531
4456
    }
4532
 
    break;
4533
 
  }
4534
4457
  case (int)OPT_REPLICATE_WILD_IGNORE_TABLE:
4535
 
  {
4536
 
    if (rpl_filter->add_wild_ignore_table(argument))
4537
4458
    {
4538
 
      fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4539
 
      exit(1);
 
4459
      if (rpl_filter->add_wild_ignore_table(argument))
 
4460
      {
 
4461
        fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
 
4462
        exit(1);
 
4463
      }
 
4464
      break;
4540
4465
    }
4541
 
    break;
4542
 
  }
4543
4466
  case (int)OPT_REPLICATE_IGNORE_TABLE:
4544
 
  {
4545
 
    if (rpl_filter->add_ignore_table(argument))
4546
4467
    {
4547
 
      fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
4548
 
      exit(1);
 
4468
      if (rpl_filter->add_ignore_table(argument))
 
4469
      {
 
4470
        fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument);
 
4471
        exit(1);
 
4472
      }
 
4473
      break;
4549
4474
    }
4550
 
    break;
4551
 
  }
4552
4475
  case (int) OPT_SLOW_QUERY_LOG:
4553
4476
    opt_slow_log= 1;
4554
4477
    break;
4555
4478
#ifdef WITH_CSV_STORAGE_ENGINE
4556
4479
  case  OPT_LOG_OUTPUT:
4557
 
  {
4558
 
    if (!argument || !argument[0])
4559
4480
    {
4560
 
      log_output_options= LOG_FILE;
4561
 
      log_output_str= log_output_typelib.type_names[1];
 
4481
      if (!argument || !argument[0])
 
4482
      {
 
4483
        log_output_options= LOG_FILE;
 
4484
        log_output_str= log_output_typelib.type_names[1];
 
4485
      }
 
4486
      else
 
4487
      {
 
4488
        log_output_str= argument;
 
4489
        log_output_options=
 
4490
          find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
 
4491
      }
 
4492
      break;
4562
4493
    }
4563
 
    else
4564
 
    {
4565
 
      log_output_str= argument;
4566
 
      log_output_options=
4567
 
        find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
4568
 
  }
4569
 
    break;
4570
 
  }
4571
4494
#endif
4572
4495
  case (int) OPT_SKIP_NEW:
4573
4496
    opt_specialflag|= SPECIAL_NO_NEW_FUNC;
4603
4526
    {
4604
4527
      struct addrinfo *res_lst, hints;    
4605
4528
 
4606
 
      bzero(&hints, sizeof(struct addrinfo));
 
4529
      memset(&hints, 0, sizeof(struct addrinfo));
4607
4530
      hints.ai_socktype= SOCK_STREAM;
4608
4531
      hints.ai_protocol= IPPROTO_TCP;
4609
4532
 
4632
4555
    thr_upgraded_concurrent_insert_lock= TL_WRITE_LOW_PRIORITY;
4633
4556
    global_system_variables.low_priority_updates=1;
4634
4557
    break;
4635
 
  case OPT_BOOTSTRAP:
4636
 
    opt_noacl=opt_bootstrap=1;
4637
 
    break;
4638
4558
  case OPT_SERVER_ID:
4639
4559
    server_id_supplied = 1;
4640
4560
    break;
4659
4579
    charsets_dir = mysql_charsets_dir;
4660
4580
    break;
4661
4581
  case OPT_TX_ISOLATION:
4662
 
  {
4663
 
    int type;
4664
 
    type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
4665
 
    global_system_variables.tx_isolation= (type-1);
4666
 
    break;
4667
 
  }
 
4582
    {
 
4583
      int type;
 
4584
      type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
 
4585
      global_system_variables.tx_isolation= (type-1);
 
4586
      break;
 
4587
    }
4668
4588
  case OPT_MYISAM_RECOVER:
4669
 
  {
4670
 
    if (!argument)
4671
 
    {
4672
 
      myisam_recover_options=    HA_RECOVER_DEFAULT;
4673
 
      myisam_recover_options_str= myisam_recover_typelib.type_names[0];
4674
 
    }
4675
 
    else if (!argument[0])
4676
 
    {
4677
 
      myisam_recover_options= HA_RECOVER_NONE;
4678
 
      myisam_recover_options_str= "OFF";
4679
 
    }
4680
 
    else
4681
 
    {
4682
 
      myisam_recover_options_str=argument;
4683
 
      myisam_recover_options=
4684
 
        find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
4685
 
    }
4686
 
    ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
4687
 
    break;
4688
 
  }
 
4589
    {
 
4590
      if (!argument)
 
4591
      {
 
4592
        myisam_recover_options=    HA_RECOVER_DEFAULT;
 
4593
        myisam_recover_options_str= myisam_recover_typelib.type_names[0];
 
4594
      }
 
4595
      else if (!argument[0])
 
4596
      {
 
4597
        myisam_recover_options= HA_RECOVER_NONE;
 
4598
        myisam_recover_options_str= "OFF";
 
4599
      }
 
4600
      else
 
4601
      {
 
4602
        myisam_recover_options_str=argument;
 
4603
        myisam_recover_options=
 
4604
          find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
 
4605
      }
 
4606
      ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
 
4607
      break;
 
4608
    }
4689
4609
  case OPT_TC_HEURISTIC_RECOVER:
4690
4610
    tc_heuristic_recover= find_type_or_exit(argument,
4691
4611
                                            &tc_heuristic_recover_typelib,
4692
4612
                                            opt->name);
4693
4613
    break;
4694
4614
  case OPT_MYISAM_STATS_METHOD:
4695
 
  {
4696
 
    ulong method_conv;
4697
 
    int method;
 
4615
    {
 
4616
      ulong method_conv;
 
4617
      int method;
4698
4618
 
4699
 
    myisam_stats_method_str= argument;
4700
 
    method= find_type_or_exit(argument, &myisam_stats_method_typelib,
4701
 
                              opt->name);
4702
 
    switch (method-1) {
4703
 
    case 2:
4704
 
      method_conv= MI_STATS_METHOD_IGNORE_NULLS;
4705
 
      break;
4706
 
    case 1:
4707
 
      method_conv= MI_STATS_METHOD_NULLS_EQUAL;
4708
 
      break;
4709
 
    case 0:
4710
 
    default:
4711
 
      method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
 
4619
      myisam_stats_method_str= argument;
 
4620
      method= find_type_or_exit(argument, &myisam_stats_method_typelib,
 
4621
                                opt->name);
 
4622
      switch (method-1) {
 
4623
      case 2:
 
4624
        method_conv= MI_STATS_METHOD_IGNORE_NULLS;
 
4625
        break;
 
4626
      case 1:
 
4627
        method_conv= MI_STATS_METHOD_NULLS_EQUAL;
 
4628
        break;
 
4629
      case 0:
 
4630
      default:
 
4631
        method_conv= MI_STATS_METHOD_NULLS_NOT_EQUAL;
 
4632
        break;
 
4633
      }
 
4634
      global_system_variables.myisam_stats_method= method_conv;
4712
4635
      break;
4713
4636
    }
4714
 
    global_system_variables.myisam_stats_method= method_conv;
4715
 
    break;
4716
 
  }
4717
 
  case OPT_LOWER_CASE_TABLE_NAMES:
4718
 
    lower_case_table_names= argument ? atoi(argument) : 1;
4719
 
    lower_case_table_names_used= 1;
4720
 
    break;
4721
4637
  }
4722
4638
  return 0;
4723
4639
}
4765
4681
  va_start(args, format);
4766
4682
 
4767
4683
  /* Don't print warnings for --loose options during bootstrap */
4768
 
  if (level == ERROR_LEVEL || !opt_bootstrap ||
4769
 
      global_system_variables.log_warnings)
 
4684
  if (level == ERROR_LEVEL || global_system_variables.log_warnings)
4770
4685
  {
4771
4686
    vprint_msg_to_log(level, format, args);
4772
4687
  }
5056
4971
 
5057
4972
 
5058
4973
/**
5059
 
  Check if file system used for databases is case insensitive.
5060
 
 
5061
 
  @param dir_name                       Directory to test
5062
 
 
5063
 
  @retval
5064
 
    -1  Don't know (Test failed)
5065
 
  @retval
5066
 
    0   File system is case sensitive
5067
 
  @retval
5068
 
    1   File system is case insensitive
5069
 
*/
5070
 
 
5071
 
static int test_if_case_insensitive(const char *dir_name)
5072
 
{
5073
 
  int result= 0;
5074
 
  File file;
5075
 
  char buff[FN_REFLEN], buff2[FN_REFLEN];
5076
 
  struct stat stat_info;
5077
 
 
5078
 
  fn_format(buff, glob_hostname, dir_name, ".lower-test",
5079
 
            MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
5080
 
  fn_format(buff2, glob_hostname, dir_name, ".LOWER-TEST",
5081
 
            MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR);
5082
 
  (void) my_delete(buff2, MYF(0));
5083
 
  if ((file= my_create(buff, 0666, O_RDWR, MYF(0))) < 0)
5084
 
  {
5085
 
    sql_print_warning("Can't create test file %s", buff);
5086
 
    return(-1);
5087
 
  }
5088
 
  my_close(file, MYF(0));
5089
 
  if (!stat(buff2, &stat_info))
5090
 
    result= 1;                                  // Can access file
5091
 
  (void) my_delete(buff, MYF(MY_WME));
5092
 
  return(result);
5093
 
}
5094
 
 
5095
 
 
5096
 
/**
5097
4974
  Create file to store pid number.
5098
4975
*/
5099
4976
static void create_pid_file()
5125
5002
  add_to_status(&global_status_var, &thd->status_var);
5126
5003
 
5127
5004
  /* Reset thread's status variables */
5128
 
  bzero((uchar*) &thd->status_var, sizeof(thd->status_var));
 
5005
  memset((uchar*) &thd->status_var, 0, sizeof(thd->status_var));
5129
5006
 
5130
5007
  /* Reset some global variables */
5131
5008
  reset_status_vars();