]> arthur.barton.de Git - netatalk.git/commitdiff
Use pthread_sigmask instead of sigprocmask. correctly restart zeroconf with SIGHUP...
authorFrank Lahm <franklahm@googlemail.com>
Sun, 27 Jun 2010 09:56:47 +0000 (11:56 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Sun, 27 Jun 2010 09:56:47 +0000 (11:56 +0200)
etc/afpd/afp_avahi.c
etc/afpd/main.c
libatalk/cnid/cnid.c
libatalk/compat/pselect.c
libatalk/util/server_child.c

index 1ceb7458540829ce8a16e814bf7f51e165bee7c1..fb7616d2b744f26032351b58eb2ca1afd68b8d19 100644 (file)
@@ -247,11 +247,14 @@ void av_zeroconf_setup(const AFPConfig *configs) {
   int error, ret;
 
   /* initialize the struct that holds our config settings. */
-  if (!ctx) {
+  if (ctx) {
+               LOG(log_debug, logtype_afpd, "Resetting zeroconf records");
+               avahi_entry_group_reset(ctx->group);
+       } else {
                ctx = calloc(1, sizeof(struct context));
                ctx->configs = configs;
+               assert(ctx);
        }
-  assert(ctx);
 
 /* first of all we need to initialize our threading env */
   if (!(ctx->threaded_poll = avahi_threaded_poll_new())) {
@@ -312,6 +315,8 @@ void av_zeroconf_shutdown() {
   avahi_threaded_poll_stop(ctx->threaded_poll);
   avahi_client_free(ctx->client);
   avahi_threaded_poll_free(ctx->threaded_poll);
+  free(ctx);
+       ctx = NULL;
 }
 
 /*
@@ -338,8 +343,10 @@ int av_zeroconf_unregister() {
     avahi_threaded_poll_free(ctx->threaded_poll);
 
   free(ctx);
+       ctx = NULL;
 
   return 0;
 }
 
 #endif /* USE_AVAHI */
+
index 12c7295ce350994e313853a4690bbcd3a77c539e..0bd0a4eeec8acf7ed615902524e7f10983677e2d 100644 (file)
@@ -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,50 +102,30 @@ 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;
 }
 
@@ -272,12 +254,12 @@ int main(int ac, 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();
@@ -296,9 +278,34 @@ int main(int ac, 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;
index 9231cf5508f72648af2dd114da9143879cb0b978..263f24145063bac89aa7b0593a2a6d095f1de0cb 100644 (file)
@@ -166,7 +166,7 @@ struct _cnid_db *cnid_open(const char *volpath, mode_t mask, char *type, int fla
 static void block_signal( u_int32_t flags)
 {
     if ((flags & CNID_FLAG_BLOCK)) {
-        sigprocmask(SIG_BLOCK, &sigblockset, NULL);
+        pthread_sigmask(SIG_BLOCK, &sigblockset, NULL);
     }
 }
 
@@ -174,7 +174,7 @@ static void block_signal( u_int32_t flags)
 static void unblock_signal(u_int32_t flags)
 {
     if ((flags & CNID_FLAG_BLOCK)) {
-        sigprocmask(SIG_UNBLOCK, &sigblockset, NULL);
+        pthread_sigmask(SIG_UNBLOCK, &sigblockset, NULL);
     }
 }
 
index 608996b28aa3565a94952f2dc5bba680bf0a29d6..0f887e45ec40b5d3d513f249a02002e219b68a43 100644 (file)
@@ -63,7 +63,7 @@ pselect(int count, fd_set * restrict rfds, fd_set * restrict wfds,
         tvp = 0;
 
     if (mask != 0) {
-        rv = sigprocmask(SIG_SETMASK, mask, &omask);
+        rv = pthread_sigmask(SIG_SETMASK, mask, &omask);
         if (rv != 0)
             return rv;
     }
@@ -71,7 +71,7 @@ pselect(int count, fd_set * restrict rfds, fd_set * restrict wfds,
     rv = select(count, rfds, wfds, efds, tvp);
     if (mask != 0) {
         sverrno = errno;
-        sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
+        pthread_sigmask(SIG_SETMASK, &omask, (sigset_t *)0);
         errno = sverrno;
     }
 
index 85c150c4c37cd9290f0aae8a53a99ab606d8660f..b21bae35f08fe427b4f1f8eed027f0420cb2dd57 100644 (file)
@@ -141,12 +141,12 @@ int server_child_add(server_child *children, const int forkid,
    * chance to add the child in. */
   sigemptyset(&sig);
   sigaddset(&sig, SIGCHLD);
-  sigprocmask(SIG_BLOCK, &sig, &oldsig);
+  pthread_sigmask(SIG_BLOCK, &sig, &oldsig);
 
   /* it's possible that the child could have already died before the
-   * sigprocmask. we need to check for this. */
+   * pthread_sigmask. we need to check for this. */
   if (kill(pid, 0) < 0) {
-    sigprocmask(SIG_SETMASK, &oldsig, NULL);
+    pthread_sigmask(SIG_SETMASK, &oldsig, NULL);
     return 1;
   }
 
@@ -154,13 +154,13 @@ int server_child_add(server_child *children, const int forkid,
 
   /* if we already have an entry. just return. */
   if (resolve_child(fork->table, pid)) {
-    sigprocmask(SIG_SETMASK, &oldsig, NULL);
+    pthread_sigmask(SIG_SETMASK, &oldsig, NULL);
     return 0;
   }
 
   if ((child = (struct server_child_data *) 
        calloc(1, sizeof(struct server_child_data))) == NULL) {
-    sigprocmask(SIG_SETMASK, &oldsig, NULL);
+    pthread_sigmask(SIG_SETMASK, &oldsig, NULL);
     return -1;
   }
 
@@ -169,7 +169,7 @@ int server_child_add(server_child *children, const int forkid,
   child->killed = 0;
   hash_child(fork->table, child);
   children->count++;
-  sigprocmask(SIG_SETMASK, &oldsig, NULL);
+  pthread_sigmask(SIG_SETMASK, &oldsig, NULL);
 
   return 0;
 }
@@ -427,6 +427,6 @@ void server_reset_signal(void)
     sigaddset(&sigs, SIGHUP);
     sigaddset(&sigs, SIGUSR1);
     sigaddset(&sigs, SIGCHLD);
-    sigprocmask(SIG_UNBLOCK, &sigs, NULL);
+    pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
         
 }