Commit 7ec920b0 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(setup_sighandlers): New function. Use SA_RESTART if the

	"restartable" argument is true and SA_RESTART is defined.
(restart_syscalls_on_intr): New function.
(intr_syscalls_on_intr): New function.
(main): Move signal handler setup to setup_sighandlers().
parent db1c22bc
/*
* $Id: ramkomd.c,v 0.105 2002/10/26 08:22:20 ceder Exp $
* $Id: ramkomd.c,v 0.106 2002/10/26 11:59:03 ceder Exp $
* Copyright (C) 1991-1999, 2001-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -463,6 +463,69 @@ initialize(const char *config_file)
init_data_base();
}
static void
setup_sighandlers(int restartable)
{
#ifdef HAVE_STRUCT_SIGACTION
struct sigaction act;
sigemptyset(&act.sa_mask);
#ifdef SA_RESTART
act.sa_flags = restartable ? SA_RESTART : 0;
#else
/* SunOS 4.1.1 doesn't have SA_RESTART, but it always uses
restartable syscalls, and select() returns with EINTR, so
we get what we want there. */
act.sa_flags = 0
#endif
act.sa_handler = sighandler_hup;
sigaction(SIGHUP, &act, NULL);
act.sa_handler = sighandler_quit;
sigaction(SIGQUIT, &act, NULL);
act.sa_handler = sighandler_usr1;
sigaction(SIGUSR1, &act, NULL);
act.sa_handler = sighandler_usr2;
sigaction(SIGUSR2, &act, NULL);
act.sa_handler = sighandler_winch;
sigaction(SIGWINCH, &act, NULL);
#else
signal(SIGHUP, sighandler_hup);
signal(SIGQUIT, sighandler_quit);
signal(SIGUSR1, sighandler_usr1);
signal(SIGUSR2, sighandler_usr2);
signal(SIGWINCH, sighandler_winch);
#endif
}
void
restart_syscalls_on_intr(void)
{
/* FIXME (bug 845): This should be a noop, except on HP-UX and
other systems where select() don't return immediately when
interrupted by a signal. To always reinstall the signal
handlers decreases performance for no good reason on systems
such as Solaris and Linux where select always returns with
EINTR, even if SA_RESTART has been specified for the signals.
We should test this at configure-time. testsuite/test-select.c
is a suitable test program. */
setup_sighandlers(1);
}
void
intr_syscalls_on_intr(void)
{
/* FIXME (bug 845): see restart_syscalls_on_intr(). */
setup_sighandlers(0);
}
/* Stop complaint from gcc 2.0 about "no previous prototype for `main'". */
int main(int argc, char **argv);
......@@ -474,9 +537,6 @@ main (int argc,
int i;
char *default_config_file;
char *config_file;
#ifdef HAVE_STRUCT_SIGACTION
struct sigaction act;
#endif
link_ansi();
......@@ -543,46 +603,7 @@ main (int argc,
if (i < argc)
restart_kom("usage: %s [-d ...] [config-file]\n", argv[0]);
#ifdef HAVE_STRUCT_SIGACTION
sigemptyset(&act.sa_mask);
/* We would like to set se_flags to SA_RESTART here, but that
could interact badly with select. select(3C) on Solaris 8
says:
If SA_RESTART has been set for the interrupting sig-
nal, it is implementation-dependent whether select()
restarts or returns with EINTR.
However, all platforms I've come across interrupts select. The
testsuite/test-select.c program checks if this is true on your
platform. Until we find a counter-example, we will continue to
use SA_RESTART. */
act.sa_flags = SA_RESTART;
act.sa_handler = sighandler_hup;
sigaction(SIGHUP, &act, NULL);
act.sa_handler = sighandler_quit;
sigaction(SIGQUIT, &act, NULL);
act.sa_handler = sighandler_usr1;
sigaction(SIGUSR1, &act, NULL);
act.sa_handler = sighandler_usr2;
sigaction(SIGUSR2, &act, NULL);
act.sa_handler = sighandler_winch;
sigaction(SIGWINCH, &act, NULL);
#else
signal(SIGHUP, sighandler_hup);
signal(SIGQUIT, sighandler_quit);
signal(SIGUSR1, sighandler_usr1);
signal(SIGUSR2, sighandler_usr2);
signal(SIGWINCH, sighandler_winch);
#endif
setup_sighandlers(1);
initialize(config_file); /* Read config, listen, and start db */
chdir(param.core_dir);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment