]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_dsi.c
change SIGHUP and SIGUSR1, SIGHUP reload config files, Volumes file are reloaded...
[netatalk.git] / etc / afpd / afp_dsi.c
index f881de659cc44a898ace619254f3be8d7b3b5549..1c1bc89bca80df4f2f3eb33aa7c13d9f9002ae69 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $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.
@@ -71,7 +71,10 @@ static __inline__ void afp_dsi_close(AFPObj *obj)
     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);
@@ -87,6 +90,9 @@ static void afp_dsi_die(int sig)
     }
 }
 
+/* ---------------------------------
+ * SIGUSR1 down in five mn.
+*/
 static void afp_dsi_timedown()
 {
     struct sigaction   sv;
@@ -102,11 +108,11 @@ static void afp_dsi_timedown()
     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 );
@@ -117,8 +123,30 @@ static void afp_dsi_timedown()
         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)
 {
@@ -127,12 +155,18 @@ 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);
@@ -140,8 +174,8 @@ static void alarm_handler()
 }
 
 
-/*
- *  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)
@@ -155,8 +189,9 @@ 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;
@@ -171,22 +206,26 @@ void afp_over_dsi(AFPObj *obj)
     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) );
@@ -205,10 +244,12 @@ void afp_over_dsi(AFPObj *obj)
     }
 #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) );
@@ -229,15 +270,20 @@ void afp_over_dsi(AFPObj *obj)
     /* 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);