]> git.meshlink.io Git - catta/blobdiff - avahi-dnsconfd/main.c
* strip glib from avahi-core
[catta] / avahi-dnsconfd / main.c
index db807dabdd0790cc7c5b37ba39fc41774aa2a700..a76aa71e018e37692f7be0d80adf49d90bf1b71b 100644 (file)
@@ -39,8 +39,7 @@
 
 #include <glib.h>
 
-#include <avahi-common/util.h>
-#include <avahi-core/llist.h>
+#include <avahi-common/llist.h>
 
 #include <libdaemon/dfork.h>
 #include <libdaemon/dsignal.h>
@@ -116,6 +115,20 @@ static DNSServerInfo* new_server_info(gint interface, guchar protocol, const gch
     return i;
 }
 
+static int set_cloexec(int fd) {
+    int n;
+
+    assert(fd >= 0);
+    
+    if ((n = fcntl(fd, F_GETFD)) < 0)
+        return -1;
+
+    if (n & FD_CLOEXEC)
+        return 0;
+
+    return fcntl(fd, F_SETFD, n|FD_CLOEXEC);
+}
+
 static int open_socket(void) {
     int fd = -1;
     struct sockaddr_un sa;
@@ -125,7 +138,7 @@ static int open_socket(void) {
         goto fail;
     }
 
-    if (avahi_set_cloexec(fd) < 0) {
+    if (set_cloexec(fd) < 0) {
         daemon_log(LOG_ERR, "fcntl(): %s", strerror(errno));
         goto fail;
     }
@@ -224,11 +237,12 @@ finish:
 
 static void run_script(gboolean new, gint interface, guchar protocol, const gchar *address) {
     gchar *p;
-    g_assert(interface > 0);
     gint ret;
     gchar ia[16], pa[16];
     gchar name[IFNAMSIZ+1];
 
+    g_assert(interface > 0);
+
     if (!getifname(interface, name, sizeof(name))) 
         return;
     
@@ -411,7 +425,9 @@ static int run_daemon(void) {
 
     if (daemonize)
         daemon_retval_send(0);
-    
+
+    ret = 0;
+
     while (!quit) {
         fd_set rfds, wfds;
 
@@ -498,8 +514,6 @@ static int run_daemon(void) {
             }
         }
     }
-
-    ret = 0;
     
 finish:
 
@@ -510,6 +524,9 @@ finish:
     
     daemon_signal_done();
 
+    if (ret != 0 && daemonize)
+        daemon_retval_send(1);
+    
     return ret;
 }