]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/main.c
merge from branch 2-1
[netatalk.git] / etc / afpd / main.c
index 5a944033e6b878aae3cc6d81c0d4e3a64144fe7f..85b5147fceaea4e52f35930130ca21d605179335 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.23 2006-08-01 09:01:32 didg Exp $
+ * $Id: main.c,v 1.26 2009-10-14 02:24:05 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -40,6 +40,7 @@
 #include "status.h"
 #include "fork.h"
 #include "uam_auth.h"
+#include "afp_zeroconf.h"
 
 #ifdef TRU64
 #include <sys/security.h>
@@ -57,6 +58,7 @@ static AFPConfig *configs;
 static server_child *server_children;
 static fd_set save_rfds;
 static int    Ipc_fd = -1;
+static sig_atomic_t reloadconfig = 0;
 
 #ifdef TRU64
 void afp_get_cmdline( int *ac, char ***av)
@@ -100,61 +102,39 @@ static void afp_goaway(int sig)
 
     dsi_kill(sig);
     switch( sig ) {
+
     case SIGTERM :
         LOG(log_info, logtype_afpd, "shutting down on signal %d", sig );
+        AFPConfig *config;
+        for (config = configs; config; config = config->next)
+            if (config->server_cleanup)
+                config->server_cleanup(config);
+        afp_exit(0);
         break;
+
     case SIGUSR1 :
-    case SIGHUP :
-        /* w/ a configuration file, we can force a re-read if we want */
         nologin++;
         auth_unload();
-        if (sig == SIGHUP || ((nologin + 1) & 1)) {
-            AFPConfig *config;
-
-            LOG(log_info, logtype_afpd, "re-reading configuration file");
-            for (config = configs; config; config = config->next)
-                if (config->server_cleanup)
-                    config->server_cleanup(config);
+        LOG(log_info, logtype_afpd, "disallowing logins");        
+        break;
 
-            /* configfree close atp socket used for DDP tickle, there's an issue
-             * with atp tid.
-            */
-            configfree(configs, NULL);
-            if (!(configs = configinit(&default_options))) {
-                LOG(log_error, logtype_afpd, "config re-read: no servers configured");
-                afp_exit(EXITERR_CONF);
-            }
-            set_fd(Ipc_fd);
-        } else {
-            LOG(log_info, logtype_afpd, "disallowing logins");
-        }
-        if (sig == SIGHUP) {
-            nologin = 0;
-        }
+    case SIGHUP :
+        /* w/ a configuration file, we can force a re-read if we want */
+        reloadconfig = 1;
         break;
+
     default :
         LOG(log_error, logtype_afpd, "afp_goaway: bad signal" );
     }
-    if ( sig == SIGTERM ) {
-        AFPConfig *config;
-
-        for (config = configs; config; config = config->next)
-            if (config->server_cleanup)
-                config->server_cleanup(config);
-
-        afp_exit(0);
-    }
     return;
 }
 
-static void child_handler()
+static void child_handler(int sig _U_)
 {
     server_child_handler(server_children);
 }
 
-int main( ac, av )
-int            ac;
-char   **av;
+int main(int ac, char **av)
 {
     AFPConfig           *config;
     fd_set              rfds;
@@ -190,9 +170,6 @@ char        **av;
         exit(0);
     }
 
-    /* Register CNID  */
-    cnid_init();
-
     /* install child handler for asp and dsi. we do this before afp_goaway
      * as afp_goaway references stuff from here. 
      * XXX: this should really be setup after the initial connections. */
@@ -201,16 +178,21 @@ char      **av;
         LOG(log_error, logtype_afpd, "main: server_child alloc: %s", strerror(errno) );
         afp_exit(EXITERR_SYS);
     }
-    
+
+    memset(&sv, 0, sizeof(sv));    
 #ifdef AFP3x
     /* linux at least up to 2.4.22 send a SIGXFZ for vfat fs,
        even if the file is open with O_LARGEFILE ! */
 #ifdef SIGXFSZ
-    signal(SIGXFSZ , SIG_IGN); 
+    sv.sa_handler = SIG_IGN;
+    sigemptyset( &sv.sa_mask );
+    if (sigaction(SIGXFSZ, &sv, NULL ) < 0 ) {
+        LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
+        afp_exit(EXITERR_SYS);
+    }
+#endif
 #endif
-#endif    
     
-    memset(&sv, 0, sizeof(sv));
     sv.sa_handler = child_handler;
     sigemptyset( &sv.sa_mask );
     sigaddset(&sv.sa_mask, SIGALRM);
@@ -219,7 +201,7 @@ char        **av;
     sigaddset(&sv.sa_mask, SIGUSR1);
     
     sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGCHLD, &sv, 0 ) < 0 ) {
+    if ( sigaction( SIGCHLD, &sv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
         afp_exit(EXITERR_SYS);
     }
@@ -231,7 +213,7 @@ char        **av;
     sigaddset(&sv.sa_mask, SIGHUP);
     sigaddset(&sv.sa_mask, SIGCHLD);
     sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR1, &sv, 0 ) < 0 ) {
+    if ( sigaction( SIGUSR1, &sv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
         afp_exit(EXITERR_SYS);
     }
@@ -242,7 +224,7 @@ char        **av;
     sigaddset(&sv.sa_mask, SIGUSR1);
     sigaddset(&sv.sa_mask, SIGCHLD);
     sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGHUP, &sv, 0 ) < 0 ) {
+    if ( sigaction( SIGHUP, &sv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
         afp_exit(EXITERR_SYS);
     }
@@ -254,7 +236,7 @@ char        **av;
     sigaddset(&sv.sa_mask, SIGUSR1);
     sigaddset(&sv.sa_mask, SIGCHLD);
     sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGTERM, &sv, 0 ) < 0 ) {
+    if ( sigaction( SIGTERM, &sv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
         afp_exit(EXITERR_SYS);
     }
@@ -277,12 +259,15 @@ char      **av;
 #endif
     sigaddset(&sigs, SIGCHLD);
 
-    sigprocmask(SIG_BLOCK, &sigs, NULL);
+    pthread_sigmask(SIG_BLOCK, &sigs, NULL);
     if (!(configs = configinit(&default_options))) {
         LOG(log_error, logtype_afpd, "main: no servers configured");
         afp_exit(EXITERR_CONF);
     }
-    sigprocmask(SIG_UNBLOCK, &sigs, NULL);
+    pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
+
+    /* Register CNID  */
+    cnid_init();
 
     /* watch atp, dsi sockets and ipc parent/child file descriptor. */
     if ((ipc = server_ipc_create())) {
@@ -298,9 +283,34 @@ char       **av;
      * solution. */
     while (1) {
         rfds = save_rfds;
-        sigprocmask(SIG_UNBLOCK, &sigs, NULL);
+        pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
         ret = select(FD_SETSIZE, &rfds, NULL, NULL, NULL);
-        sigprocmask(SIG_BLOCK, &sigs, NULL);
+        pthread_sigmask(SIG_BLOCK, &sigs, NULL);
+        int saveerrno = errno;
+
+        if (reloadconfig) {
+            nologin++;
+            auth_unload();
+            AFPConfig *config;
+
+            LOG(log_info, logtype_afpd, "re-reading configuration file");
+            for (config = configs; config; config = config->next)
+                if (config->server_cleanup)
+                    config->server_cleanup(config);
+
+            /* configfree close atp socket used for DDP tickle, there's an issue
+             * with atp tid. */
+            configfree(configs, NULL);
+            if (!(configs = configinit(&default_options))) {
+                LOG(log_error, logtype_afpd, "config re-read: no servers configured");
+                afp_exit(EXITERR_CONF);
+            }
+            set_fd(Ipc_fd);
+            nologin = 0;
+            reloadconfig = 0;
+            errno = saveerrno;
+        }
+        
         if (ret < 0) {
             if (errno == EINTR)
                 continue;