620
Force server down. Kill all connections and threads and exit.
622
@param sig_ptr Signal number that caused kill_server to be called.
625
A signal number of 0 mean that the function was not called
626
from a signal handler and there is thus no signal to block
627
or stop, we just want to kill the server.
630
static void *kill_server(void *sig_ptr)
631
#define RETURN_FROM_KILL_SERVER return(0)
633
int sig=(int) (long) sig_ptr; // This is passed a int
634
// if there is a signal during the kill in progress, ignore the other
635
if (kill_in_progress) // Safety
636
RETURN_FROM_KILL_SERVER;
637
kill_in_progress=true;
638
abort_loop=1; // This should be set
639
if (sig != 0) // 0 is not a valid signal number
640
my_sigset(sig, SIG_IGN); /* purify inspected */
641
if (sig == DRIZZLE_KILL_SIGNAL || sig == 0)
642
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_NORMAL_SHUTDOWN)),my_progname);
644
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_GOT_SIGNAL)),my_progname,sig); /* purecov: inspected */
647
if (sig != DRIZZLE_KILL_SIGNAL &&
649
unireg_abort(1); /* purecov: inspected */
653
/* purecov: begin deadcode */
659
RETURN_FROM_KILL_SERVER;
663
613
extern "C" void print_signal_warning(int sig)
665
615
if (global_system_variables.log_warnings)
1398
static void start_signal_handler(void)
1401
pthread_attr_t thr_attr;
1403
(void) pthread_attr_init(&thr_attr);
1404
pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
1405
(void) pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
1407
struct sched_param tmp_sched_param;
1409
memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
1410
tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
1411
(void)pthread_attr_setschedparam(&thr_attr, &tmp_sched_param);
1413
#if defined(__ia64__) || defined(__ia64)
1415
Peculiar things with ia64 platforms - it seems we only have half the
1416
stack size in reality, so we have to double it here
1418
pthread_attr_setstacksize(&thr_attr,my_thread_stack_size*2);
1420
pthread_attr_setstacksize(&thr_attr,my_thread_stack_size);
1423
(void) pthread_mutex_lock(&LOCK_thread_count);
1424
if ((error=pthread_create(&signal_thread,&thr_attr,signal_hand,0)))
1426
errmsg_printf(ERRMSG_LVL_ERROR, _("Can't create interrupt-thread (error %d, errno: %d)"),
1430
(void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
1431
pthread_mutex_unlock(&LOCK_thread_count);
1433
(void) pthread_attr_destroy(&thr_attr);
1438
/** This threads handles all signals and alarms. */
1440
pthread_handler_t signal_hand(void *)
1444
my_thread_init(); // Init new thread
1445
signal_thread_in_use= 1;
1447
if (thd_lib_detected != THD_LIB_LT && (test_flags & TEST_SIGINT))
1449
(void) sigemptyset(&set); // Setup up SIGINT for debug
1450
(void) sigaddset(&set,SIGINT); // For debugging
1451
(void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
1453
(void) sigemptyset(&set); // Setup up SIGINT for debug
1454
#ifndef IGNORE_SIGHUP_SIGQUIT
1455
(void) sigaddset(&set,SIGQUIT);
1456
(void) sigaddset(&set,SIGHUP);
1458
(void) sigaddset(&set,SIGTERM);
1459
(void) sigaddset(&set,SIGTSTP);
1461
/* Save pid to this process (or thread on Linux) */
1464
#ifdef HAVE_STACK_TRACE_ON_SEGV
1467
sprintf(pstack_file_name,"drizzled-%lu-%%d-%%d.backtrace", (uint32_t)getpid());
1468
pstack_install_segv_action(pstack_file_name);
1470
#endif /* HAVE_STACK_TRACE_ON_SEGV */
1473
signal to start_signal_handler that we are ready
1474
This works by waiting for start_signal_handler to free mutex,
1475
after which we signal it that we are ready.
1476
At this pointer there is no other threads running, so there
1477
should not be any other pthread_cond_signal() calls.
1479
We call lock/unlock to out wait any thread/session which is
1480
dieing. Since only comes from this code, this should be safe.
1481
(Asked MontyW over the phone about this.) -Brian
1484
if (pthread_mutex_lock(&LOCK_thread_count) == 0)
1485
(void) pthread_mutex_unlock(&LOCK_thread_count);
1486
(void) pthread_cond_broadcast(&COND_thread_count);
1488
(void) pthread_sigmask(SIG_BLOCK,&set,NULL);
1491
int error; // Used when debugging
1492
if (shutdown_in_progress && !abort_loop)
1498
while ((error= sigwait(&set,&sig)) == EINTR) ;
1502
signal_thread_in_use= 0;
1509
/* switch to the old log message processing */
1512
abort_loop=1; // mark abort for threads
1513
kill_server((void*) sig); // MIT THREAD has a alarm thread
1520
reload_cache((Session*) 0,
1521
(REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST |
1523
(TableList*) 0, ¬_used); // Flush logs
1527
break; /* purecov: tested */
1532
1326
static void check_data_home(const char *)
3751
3524
} /* find_bit_type */
3755
Create file to store pid number.
3757
static void create_pid_file()
3760
if ((file = my_create(pidfile_name,0664,
3761
O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0)
3763
char buff[21], *end;
3764
end= int10_to_str((long) getpid(), buff, 10);
3766
if (!my_write(file, (unsigned char*) buff, (uint32_t) (end-buff), MYF(MY_WME | MY_NABP)))
3768
(void) my_close(file, MYF(0));
3771
(void) my_close(file, MYF(0));
3773
sql_perror("Can't start server: can't create PID file");
3777
3527
bool safe_read_error_impl(NET *net)