Commit c4d7d239 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(listen_client): Static variable removed.

(server_init): Initialize liboop.  Adjusted to the new isc API:s.
(sighandler_hup): Now an liboop signal callback, not a real signal
	handler.
(sighandler_quit): Ditto.
(sighandler_usr2): Ditto.
(sighandler_usr1): Ditto.  Do the real work here.
(sighandler_winch): Ditto.  Do the real work here.
(setup_sighandlers): Removed.
(restart_syscalls_on_intr): Removed.
(intr_syscalls_on_intr): Removed.
(main): Clean up liboop structures on shutdown.
parent b097a2ff
/*
* $Id: ramkomd.c,v 0.111 2002/11/04 10:03:28 ceder Exp $
* $Id: ramkomd.c,v 0.112 2003/07/12 00:18:46 ceder Exp $
* Copyright (C) 1991-1999, 2001-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -80,6 +80,8 @@
#include <sys/socket.h>
#include <fcntl.h>
#include "oop.h"
#include "exp.h"
#include "s-string.h"
#include "misc-types.h"
......@@ -89,6 +91,7 @@
#include "connections.h"
#include "internal-connections.h"
#include "kom-errno.h"
#include "oop-malloc.h"
#include "isc-malloc.h"
#include "isc-interface.h"
#include "kom-config.h"
......@@ -136,10 +139,14 @@ int buglevel = 0;
intended for debugging and the test suite. */
static int foreground = 0;
static IscSession *listen_client = NULL; /* ISC listen identifier */
static void dump_exit_statistics(void);
static void free_kom_info(void);
static oop_call_signal sighandler_hup;
static oop_call_signal sighandler_quit;
static oop_call_signal sighandler_usr1;
static oop_call_signal sighandler_usr2;
static oop_call_signal sighandler_winch;
#ifdef HAVE_STRUCT_SIGACTION
......@@ -161,34 +168,42 @@ set_handler_sig_ign(struct sigaction *ptr)
static void
server_init(const char *host, const char * client_port)
{
IscConfig config;
IscAddress *isc_adr = NULL;
struct isc_scb *listen_client;
union isc_address *isc_adr = NULL;
oop_source *src;
#ifdef HAVE_STRUCT_SIGACTION
struct sigaction act;
#endif
oop_malloc = &oop_malloc_wrapper;
oop_realloc = &oop_realloc_wrapper;
oop_free = &oop_free_wrapper;
kom_server_oop_src = oop_sys_new();
if (kom_server_oop_src == NULL)
restart_kom("server_init: can't get system event source\n");
src = oop_sys_source(kom_server_oop_src);
oop_sys_use_sa_restart();
src->on_signal(src, SIGHUP, sighandler_hup, NULL);
src->on_signal(src, SIGQUIT, sighandler_quit, NULL);
src->on_signal(src, SIGUSR1, sighandler_usr1, NULL);
src->on_signal(src, SIGUSR2, sighandler_usr2, NULL);
src->on_signal(src, SIGWINCH, sighandler_winch, NULL);
/*
** Setup some parameters here
*/
config.version = 1006;
config.master.version = 1001;
config.master.memfn.alloc = &isc_malloc_wrapper;
config.master.memfn.realloc = &isc_realloc_wrapper;
config.master.memfn.free = &isc_free_wrapper;
config.master.abortfn = NULL; /* Use default abort function. */
config.session.version = 1002;
config.session.max.msgsize = -1; /* Use default sizes. */
config.session.max.queuedsize = -1;
config.session.max.dequeuelen = -1;
config.session.max.openretries = -1;
config.session.max.backlog = -1;
config.session.fd_relocate = PROTECTED_FDS;
kom_server_mcb = isc_initialize(&config);
isc_setallocfn(&isc_malloc_wrapper,
&isc_realloc_wrapper,
&isc_free_wrapper);
kom_server_mcb = isc_initialize(oop_sys_source(kom_server_oop_src));
if ( kom_server_mcb == NULL )
restart_kom("server_init: can't isc_initialize()\n");
isc_cfg_fd_relocate(kom_server_mcb, PROTECTED_FDS);
listen_client = isc_listentcp(kom_server_mcb, host, client_port);
listen_client = isc_listentcp(kom_server_mcb, host, client_port,
handle_accept_event);
if (listen_client == NULL)
restart_kom("server_init: can't isc_listentcp(CLIENT)\n");
......@@ -227,18 +242,20 @@ init_data_base(void)
restart_kom ("Cannot find database.\n");
}
static void
sighandler_hup (int UNUSED(sig))
static void *
sighandler_hup(oop_source *UNUSED(source),
int UNUSED(sig),
void *UNUSED(user))
{
#ifndef HAVE_STRUCT_SIGACTION
signal(SIGHUP, sighandler_hup);
#endif
kom_log ("Signal HUP received. Shutting down server.\n");
go_and_die = 1;
return OOP_HALT;
}
static void
sighandler_quit (int UNUSED(sig))
static void *
sighandler_quit(oop_source *UNUSED(source),
int UNUSED(sig),
void *UNUSED(user))
{
kom_log ("Signal QUIT received - syncing...\n");
cache_sync_all();
......@@ -246,24 +263,22 @@ sighandler_quit (int UNUSED(sig))
abort();
}
static void
sighandler_usr1 (int UNUSED(sig))
static void *
sighandler_usr1(oop_source *UNUSED(source),
int UNUSED(sig),
void *UNUSED(user))
{
#ifndef HAVE_STRUCT_SIGACTION
signal(SIGUSR1, sighandler_usr1);
#endif
do_statistics = 1;
dump_statistics();
return OOP_CONTINUE;
}
static void
sighandler_usr2 (int UNUSED(sig))
static void *
sighandler_usr2(oop_source *UNUSED(source),
int UNUSED(sig),
void *UNUSED(user))
{
int child;
#ifndef HAVE_STRUCT_SIGACTION
signal(SIGUSR2, sighandler_usr2);
#endif
kom_log ("Signal USR2 received - will dump core now. (Check that child dies.)\n");
if ((child = fork()) == 0)
{
......@@ -279,15 +294,18 @@ sighandler_usr2 (int UNUSED(sig))
{
wait (NULL);
}
return OOP_CONTINUE;
}
static void
sighandler_winch(int UNUSED(sig))
static void *
sighandler_winch(oop_source *UNUSED(source),
int UNUSED(sig),
void *UNUSED(user))
{
#ifndef HAVE_STRUCT_SIGACTION
signal(SIGWINCH, sighandler_winch);
#endif
reread_param = TRUE;
free_aux_item_definitions();
initialize_aux_items(param.aux_def_file);
kom_log("Signal WINCH received. aux definitions reloaded.\n");
return OOP_CONTINUE;
}
static void
......@@ -493,69 +511,6 @@ 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);
......@@ -567,6 +522,7 @@ main (int argc,
int i;
char *default_config_file;
char *config_file;
oop_source *src;
link_ansi();
......@@ -633,7 +589,6 @@ main (int argc,
if (i < argc)
restart_kom("usage: %s [-d ...] [config-file]\n", argv[0]);
setup_sighandlers(1);
initialize(config_file); /* Read config, listen, and start db */
chdir(param.core_dir);
......@@ -652,6 +607,13 @@ main (int argc,
isc_shutdown(kom_server_mcb);
cache_sync_all();
unlock_db();
src = oop_sys_source(kom_server_oop_src);
src->cancel_signal(src, SIGWINCH, sighandler_winch, NULL);
src->cancel_signal(src, SIGUSR2, sighandler_usr2, NULL);
src->cancel_signal(src, SIGUSR1, sighandler_usr1, NULL);
src->cancel_signal(src, SIGQUIT, sighandler_quit, NULL);
src->cancel_signal(src, SIGHUP, sighandler_hup, NULL);
oop_sys_delete(kom_server_oop_src);
/* Finish */
......@@ -702,6 +664,7 @@ dump_exit_statistics(void)
dump_string_alloc_counts(stat_file);
dump_allocated_connections(stat_file);
dump_isc_alloc_counts(stat_file);
dump_oop_alloc_counts(stat_file);
dump_l2g_stats(stat_file);
i_fclose (stat_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