/*
- * $Id: afp_dsi.c,v 1.24 2002-08-30 19:32:40 didg Exp $
+ * $Id: afp_dsi.c,v 1.27.2.1 2003-05-26 11:17:25 didg Exp $
*
* Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
* Copyright (c) 1990,1993 Regents of The University of Michigan.
dsi_close(dsi);
}
-/* a little bit of code duplication. */
+/* -------------------------------
+ * SIGTERM
+ * a little bit of code duplication.
+ */
static void afp_dsi_die(int sig)
{
dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN);
}
}
+/* ---------------------------------
+ * SIGUSR1 down in five mn.
+*/
static void afp_dsi_timedown()
{
struct sigaction sv;
it.it_interval.tv_usec = 0;
it.it_value.tv_sec = 300;
it.it_value.tv_usec = 0;
+
if ( setitimer( ITIMER_REAL, &it, 0 ) < 0 ) {
LOG(log_error, logtype_afpd, "afp_timedown: setitimer: %s", strerror(errno) );
afp_dsi_die(1);
}
-
memset(&sv, 0, sizeof(sv));
sv.sa_handler = afp_dsi_die;
sigemptyset( &sv.sa_mask );
LOG(log_error, logtype_afpd, "afp_timedown: sigaction: %s", strerror(errno) );
afp_dsi_die(1);
}
+
+ /* ignore myself */
+ sv.sa_handler = SIG_IGN;
+ sigemptyset( &sv.sa_mask );
+ sv.sa_flags = SA_RESTART;
+ if ( sigaction( SIGUSR1, &sv, 0 ) < 0 ) {
+ LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGHUP: %s", strerror(errno) );
+ afp_dsi_die(1);
+ }
+
}
+/* ---------------------------------
+ * SIGHUP reload configuration file
+ * FIXME here or we wait ?
+*/
+volatile reload_request = 0;
+
+static void afp_dsi_reload()
+{
+ reload_request = 1;
+}
+
+/* ---------------------- */
#ifdef SERVERTEXT
static void afp_dsi_getmesg (int sig)
{
}
#endif /* SERVERTEXT */
+/* ---------------------- */
static void alarm_handler()
{
+int err;
/* if we're in the midst of processing something,
don't die. */
if ((child.flags & CHILD_RUNNING) || (child.tickle++ < child.obj->options.timeout)) {
- dsi_tickle(child.obj->handle);
+ if (!(err = pollvoltime(child.obj)))
+ err = dsi_tickle(child.obj->handle);
+ if (err <= 0)
+ afp_dsi_die(1);
+
} else { /* didn't receive a tickle. close connection */
LOG(log_error, logtype_afpd, "afp_alarm: child timed out");
afp_dsi_die(1);
}
-/*
- * Signal handler for SIGUSR1 - set the debug flag and
+/* ---------------------------------
+ * old signal handler for SIGUSR1 - set the debug flag and
* redirect stdout to <tmpdir>/afpd-debug-<pid>.
*/
void afp_set_debug (int sig)
return;
}
-
-/* afp over dsi. this never returns. */
+/* -------------------------------------------
+ afp over dsi. this never returns.
+*/
void afp_over_dsi(AFPObj *obj)
{
DSI *dsi = (DSI *) obj->handle;
child.obj = obj;
child.tickle = child.flags = 0;
- /* install SIGTERM and SIGHUP */
memset(&action, 0, sizeof(action));
- action.sa_handler = afp_dsi_timedown;
+
+ /* install SIGHUP */
+ action.sa_handler = afp_dsi_reload;
sigemptyset( &action.sa_mask );
sigaddset(&action.sa_mask, SIGALRM);
sigaddset(&action.sa_mask, SIGTERM);
+ sigaddset(&action.sa_mask, SIGUSR1);
action.sa_flags = SA_RESTART;
if ( sigaction( SIGHUP, &action, 0 ) < 0 ) {
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
afp_dsi_die(1);
}
+ /* install SIGTERM */
action.sa_handler = afp_dsi_die;
sigemptyset( &action.sa_mask );
sigaddset(&action.sa_mask, SIGALRM);
sigaddset(&action.sa_mask, SIGHUP);
+ sigaddset(&action.sa_mask, SIGUSR1);
action.sa_flags = SA_RESTART;
if ( sigaction( SIGTERM, &action, 0 ) < 0 ) {
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
}
#endif /* SERVERTEXT */
- /* SIGUSR1 - set "debug" flag on this process. */
- action.sa_handler = afp_set_debug;
+ /* SIGUSR1 - set down in 5 minutes */
+ action.sa_handler = afp_dsi_timedown;
sigemptyset( &action.sa_mask );
- sigaddset(&action.sa_mask, SIGUSR1);
+ sigaddset(&action.sa_mask, SIGALRM);
+ sigaddset(&action.sa_mask, SIGHUP);
+ sigaddset(&action.sa_mask, SIGTERM);
action.sa_flags = SA_RESTART;
if ( sigaction( SIGUSR1, &action, 0) < 0 ) {
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
/* get stuck here until the end */
while ((cmd = dsi_receive(dsi))) {
child.tickle = 0;
+ dsi_sleep(dsi, 0); /* wake up */
+ if (reload_request) {
+ reload_request = 0;
+ load_volumes(child.obj);
+ }
if (cmd == DSIFUNC_TICKLE) {
/* so we don't get killed on the client side. */
if (child.flags & CHILD_DIE)
dsi_tickle(dsi);
continue;
- } else if (!(child.flags & CHILD_DIE)) /* reset tickle timer */
+ } else if (!(child.flags & CHILD_DIE)) { /* reset tickle timer */
setitimer(ITIMER_REAL, &dsi->timer, NULL);
-
+ }
switch(cmd) {
case DSIFUNC_CLOSE:
afp_dsi_close(obj);