]> arthur.barton.de Git - netatalk.git/commitdiff
afpd crashed when it failed to register with Avahi because eg user service registrati...
authorFrank Lahm <franklahm@googlemail.com>
Thu, 18 Aug 2011 09:04:56 +0000 (11:04 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 18 Aug 2011 09:04:56 +0000 (11:04 +0200)
NEWS
etc/afpd/afp_avahi.c
etc/afpd/afp_avahi.h
etc/afpd/afp_zeroconf.c

diff --git a/NEWS b/NEWS
index 87e89b39aaedb113324bad14e684b25581a37c10..0109f7ee640bdc6a53fabfa2ee90563ca568130a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,8 @@ Changes in 2.2.1
 * FIX: afpd: return correct user/group type when mapping UUIDs to names
 * FIX: afpd: for directories add DARWIN_ACE_DELETE ACE if DARWIN_ACE_ADD_SUBDIRECTORY
        is set
+* FIX: afpd: afpd crashed when it failed to register with Avahi because eg user
+       service registration is disabled in the Avahi config
 * FIX: cnid_dbd: increase BerkeleyDB locks and lockobjs
 * FIX: cnid_dbd: implement -d option, deletes CNID db
 * FIX: suse: initscript return better status
index b564c4734b9a6398e353e650414eb9b8e158dc5d..df685e4a0b2df3bb8246a80ddcde156591708306 100644 (file)
@@ -176,8 +176,8 @@ static void register_stuff(void) {
     return;
 
 fail:
-    avahi_client_free (ctx->client);
-    avahi_threaded_poll_quit(ctx->threaded_poll);
+    time(NULL);
+//    avahi_threaded_poll_quit(ctx->threaded_poll);
 }
 
 /* Called when publishing of service data completes */
@@ -198,14 +198,12 @@ static void publish_reply(AvahiEntryGroup *g,
         /* With multiple names there's no way to know which one collided */
         LOG(log_error, logtype_afpd, "publish_reply: AVAHI_ENTRY_GROUP_COLLISION",
             avahi_strerror(avahi_client_errno(ctx->client)));
-        avahi_client_free(avahi_entry_group_get_client(g));
         avahi_threaded_poll_quit(ctx->threaded_poll);
         break;
                
     case AVAHI_ENTRY_GROUP_FAILURE:
         LOG(log_error, logtype_afpd, "Failed to register service: %s",
             avahi_strerror(avahi_client_errno(ctx->client)));
-        avahi_client_free(avahi_entry_group_get_client(g));
         avahi_threaded_poll_quit(ctx->threaded_poll);
         break;
 
@@ -253,14 +251,12 @@ static void client_callback(AvahiClient *client,
                 LOG(log_error, logtype_afpd, "Failed to contact server: %s",
                     avahi_strerror(error));
 
-                avahi_client_free (ctx->client);
                 avahi_threaded_poll_quit(ctx->threaded_poll);
             }
 
         } else {
             LOG(log_error, logtype_afpd, "Client failure: %s",
                 avahi_strerror(avahi_client_errno(client)));
-            avahi_client_free (ctx->client);
             avahi_threaded_poll_quit(ctx->threaded_poll);
         }
         break;
@@ -281,7 +277,7 @@ static void client_callback(AvahiClient *client,
  * Tries to setup the Zeroconf thread and any
  * neccessary config setting.
  */
-void av_zeroconf_setup(const AFPConfig *configs) {
+void av_zeroconf_register(const AFPConfig *configs) {
     int error;
 
     /* initialize the struct that holds our config settings. */
@@ -310,20 +306,6 @@ void av_zeroconf_setup(const AFPConfig *configs) {
         goto fail;
     }
 
-    return;
-
-fail:
-    if (ctx)
-        av_zeroconf_unregister();
-
-    return;
-}
-
-/*
- * This function finally runs the loop impl.
- */
-int av_zeroconf_run(void) {
-    /* Finally, start the event loop thread */
     if (avahi_threaded_poll_start(ctx->threaded_poll) < 0) {
         LOG(log_error, logtype_afpd, "Failed to create thread: %s",
             avahi_strerror(avahi_client_errno(ctx->client)));
@@ -333,26 +315,12 @@ int av_zeroconf_run(void) {
     }
 
     ctx->thread_running = 1;
-    return 0;
+    return;
 
 fail:
-    if (ctx)
-        av_zeroconf_unregister();
-
-    return -1;
-}
+    av_zeroconf_unregister();
 
-/*
- * Tries to shutdown this loop impl.
- * Call this function from outside this thread.
- */
-void av_zeroconf_shutdown() {
-    /* Call this when the app shuts down */
-    avahi_threaded_poll_stop(ctx->threaded_poll);
-    avahi_client_free(ctx->client);
-    avahi_threaded_poll_free(ctx->threaded_poll);
-    free(ctx);
-    ctx = NULL;
+    return;
 }
 
 /*
@@ -360,27 +328,21 @@ void av_zeroconf_shutdown() {
  * Call this function from inside this thread.
  */
 int av_zeroconf_unregister() {
-    if (ctx->thread_running) {
-        /* First, block the event loop */
-        avahi_threaded_poll_lock(ctx->threaded_poll);
-
-        /* Than, do your stuff */
-        avahi_threaded_poll_quit(ctx->threaded_poll);
+    LOG(log_error, logtype_afpd, "av_zeroconf_unregister");
 
-        /* Finally, unblock the event loop */
-        avahi_threaded_poll_unlock(ctx->threaded_poll);
-        ctx->thread_running = 0;
+    if (ctx) {
+        LOG(log_error, logtype_afpd, "av_zeroconf_unregister: avahi_threaded_poll_stop");
+        if (ctx->threaded_poll)
+            avahi_threaded_poll_stop(ctx->threaded_poll);
+        LOG(log_error, logtype_afpd, "av_zeroconf_unregister: avahi_client_free");
+        if (ctx->client)
+            avahi_client_free(ctx->client);
+        LOG(log_error, logtype_afpd, "av_zeroconf_unregister: avahi_threaded_poll_free");
+        if (ctx->threaded_poll)
+            avahi_threaded_poll_free(ctx->threaded_poll);
+        free(ctx);
+        ctx = NULL;
     }
-
-    if (ctx->client)
-        avahi_client_free(ctx->client);
-
-    if (ctx->threaded_poll)
-        avahi_threaded_poll_free(ctx->threaded_poll);
-
-    free(ctx);
-    ctx = NULL;
-
     return 0;
 }
 
index c0216fef4723f7d0b722c2a1d7b89bc7634105fb..e516408c6a79e17cc27ad95e7230e3e70e1830bd 100644 (file)
@@ -41,9 +41,7 @@ struct context {
 };
 
 /* prototype definitions */
-void av_zeroconf_setup(const AFPConfig *configs);
-int av_zeroconf_run(void);
+void av_zeroconf_register(const AFPConfig *configs);
 int av_zeroconf_unregister(void);
-void av_zeroconf_shutdown(void);
 
 #endif   /* AFPD_AVAHI_H */
index 84f187126340dd1664274106f08dc4765c167688..d6fa657728b568ee1fe5b9a547ab02fc3b10990b 100644 (file)
@@ -27,8 +27,7 @@ void zeroconf_register(const AFPConfig *configs)
 #if defined (HAVE_AVAHI)
   LOG(log_debug, logtype_afpd, "Attempting to register with mDNS using Avahi");
 
-       av_zeroconf_setup(configs);
-  av_zeroconf_run();
+       av_zeroconf_register(configs);
 #endif
 }
 
@@ -36,6 +35,6 @@ void zeroconf_deregister(void)
 {
 #if defined (HAVE_AVAHI)
   LOG(log_debug, logtype_afpd, "Attempting to de-register mDNS using Avahi");
-       av_zeroconf_shutdown();
+       av_zeroconf_unregister();
 #endif
 }