Commit 14d60276 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(server_init): Use sigaction instead of signal if available.

(go_daemon): Likewise.
(main): Likewise.
(sighandler_hup): Don't reinstall the signal if sigaction is available.
(sighandler_usr1): Likewise.
(sighandler_usr2): Likewise.
parent 3aff202e
/*
* $Id: ramkomd.c,v 0.60 1996/07/29 13:17:10 ceder Exp $
* $Id: ramkomd.c,v 0.61 1996/07/30 14:32:56 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -22,6 +22,13 @@
*
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* The next comment block is a historic comment, written in Swedish
* using ISO 646 since nobody in Lysator knew about ISO 8859-1 by
* then. It translates, rougly, to "This is the main program of the
* server. It will hopefully be bigger than it is at the moment.
* Created by Willfr 31-mar-1990."
*/
/*
* Detta {r serverns huvudprogram. Det kommer f|rhoppningsvis bli st|rre
* {n det {r just nu...
......@@ -31,7 +38,7 @@
* It has grown! /ceder
*/
static char *rcsid = "$Id: ramkomd.c,v 0.60 1996/07/29 13:17:10 ceder Exp $";
static char *rcsid = "$Id: ramkomd.c,v 0.61 1996/07/30 14:32:56 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -114,7 +121,10 @@ server_init (char * client_port, char * mux_port)
{
IscConfig config;
IscAddress *isc_adr = NULL;
#ifdef HAVE_STRUCT_SIGACTION
struct sigaction act;
#endif
/*
** Setup some parameters here
*/
......@@ -165,7 +175,14 @@ server_init (char * client_port, char * mux_port)
* socket and the client has died. The server will anyhow handle
* this situation correct.
*/
#ifdef HAVE_STRUCT_SIGACTION
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = SIG_IGN;
sigaction(SIGHUP, &act, NULL);
#else
signal(SIGPIPE, SIG_IGN);
#endif
}
static void
......@@ -181,7 +198,9 @@ init_data_base(const char *dir_base)
static void
sighandler_hup (int sig)
{
#ifndef HAVE_STRUCT_SIGACTION
signal(SIGHUP, sighandler_hup);
#endif
log ("Signal HUP received. Shutting down server.\n");
go_and_die = TRUE;
}
......@@ -198,7 +217,9 @@ sighandler_quit (int sig)
static void
sighandler_usr1 (int sig)
{
#ifndef HAVE_STRUCT_SIGACTION
signal(SIGUSR1, sighandler_usr1);
#endif
do_sync_db = TRUE;
}
......@@ -207,7 +228,9 @@ sighandler_usr2 (int sig)
{
int child;
#ifndef HAVE_STRUCT_SIGACTION
signal(SIGUSR2, sighandler_usr2);
#endif
log ("Signal USR2 received - will dump core now. (Check that child dies.)\n");
if ((child = fork()) == 0)
......@@ -243,7 +266,10 @@ go_daemon()
{
pid_t child;
int fd;
#ifdef HAVE_STRUCT_SIGACTION
struct sigaction act;
#endif
if (buglevel != 0)
{
return;
......@@ -254,14 +280,33 @@ go_daemon()
/* We were not invoked from /etc/inittab, so
disassociate from controlling terminal. */
#ifdef SIGTTOU
#ifdef HAVE_STRUCT_SIGACTION
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = SIG_IGN;
# ifdef SIGTTOU
sigaction(SIGTTOU, &act, NULL);
# endif
# ifdef SIGTTIN
sigaction(SIGTTIN, &act, NULL);
# endif
# ifdef SIGTSTP
sigaction(SIGTSTP, &act, NULL);
# endif
#else /* !HAVE_STRUCT_SIGACTION */
# ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
# endif
# ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
# endif
# ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
# endif
#endif
child = fork();
......@@ -375,6 +420,9 @@ main (int argc,
int i;
char *default_config_file;
char *config_file;
#ifdef HAVE_STRUCT_SIGACTION
struct sigaction act;
#endif
log("*** Version %s (process %lu) started.\n",
kom_version_info.server_version, (unsigned long)getpid());
......@@ -413,11 +461,28 @@ main (int argc,
if (i < argc)
restart_kom("usage: %s [-d ...] [config-file]\n", argv[0]);
#ifdef HAVE_STRUCT_SIGACTION
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
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);
#else
signal(SIGHUP, sighandler_hup);
signal(SIGQUIT, sighandler_quit);
signal(SIGUSR1, sighandler_usr1);
signal(SIGUSR2, sighandler_usr2);
#endif
initialize(config_file); /* Read config, listen, and start db */
chdir(param.core_dir);
sfree(default_config_file);
......
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