/*
- * $Id: afp_dsi.c,v 1.20 2002-03-24 01:23:40 sibaz 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.
#include "auth.h"
#include "fork.h"
+#ifdef FORCE_UIDGID
+#warning UIDGID
+#include "uid.h"
+#endif /* FORCE_UIDGID */
+
extern struct oforks *writtenfork;
#define CHILD_DIE (1 << 0)
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);
}
}
-/* afp over dsi. this never returns. */
+
+/* ---------------------------------
+ * old signal handler for SIGUSR1 - set the debug flag and
+ * redirect stdout to <tmpdir>/afpd-debug-<pid>.
+ */
+void afp_set_debug (int sig)
+{
+ char fname[MAXPATHLEN];
+
+ snprintf(fname, MAXPATHLEN-1, "%safpd-debug-%d", P_tmpdir, getpid());
+ freopen(fname, "w", stdout);
+ child.obj->options.flags |= OPTION_DEBUG;
+
+ return;
+}
+
+/* -------------------------------------------
+ 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 down in 5 minutes */
+ action.sa_handler = afp_dsi_timedown;
+ sigemptyset( &action.sa_mask );
+ 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) );
+ afp_dsi_die(1);
+ }
+
/* tickle handler */
action.sa_handler = alarm_handler;
sigemptyset(&action.sa_mask);
/* 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);
if (afp_switch[function]) {
dsi->datalen = DSI_DATASIZ;
child.flags |= CHILD_RUNNING;
+
err = (*afp_switch[function])(obj,
dsi->commands, dsi->cmdlen,
dsi->data, &dsi->datalen);
+#ifdef FORCE_UIDGID
+ /* bring everything back to old euid, egid */
+ if (obj->force_uid)
+ restore_uidgid ( &obj->uidgid );
+#endif /* FORCE_UIDGID */
child.flags &= ~CHILD_RUNNING;
} else {
LOG(log_error, logtype_afpd, "bad function %X", function);
err = (*afp_switch[function])(obj, dsi->commands, dsi->cmdlen,
dsi->data, &dsi->datalen);
child.flags &= ~CHILD_RUNNING;
+#ifdef FORCE_UIDGID
+ /* bring everything back to old euid, egid */
+ if (obj->force_uid)
+ restore_uidgid ( &obj->uidgid );
+#endif /* FORCE_UIDGID */
} else {
LOG(log_error, logtype_afpd, "(write) bad function %x", function);
dsi->datalen = 0;