]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/main.c
use libdaemon's new daemon_close_all() function to close all fds when daemonizing...
[catta] / avahi-daemon / main.c
index 0367b98d431857cdba776a303461e3c754ccb73a..884ad2ed3fcfb36b1c55161152a96a6a4df9edf1 100644 (file)
 #include <sys/resource.h>
 #include <sys/socket.h>
 
+#ifdef HAVE_INOTIFY
 #ifdef HAVE_SYS_INOTIFY_H
 #include <sys/inotify.h>
 #else
 #include "inotify-nosys.h"
 #endif
+#endif
 
 #include <libdaemon/dfork.h>
 #include <libdaemon/dsignal.h>
@@ -675,8 +677,16 @@ static void add_inotify_watches(void) {
     c = config.use_chroot;
 #endif
     
-    inotify_add_watch(inotify_fd, c ? "/services" : AVAHI_SERVICE_DIR, IN_CLOSE_WRITE|IN_DELETE|IN_DELETE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_MOVE_SELF|IN_ONLYDIR);
-    inotify_add_watch(inotify_fd, c ? "/" : AVAHI_CONFIG_DIR, IN_CLOSE_WRITE|IN_DELETE|IN_DELETE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_MOVE_SELF|IN_ONLYDIR);
+    inotify_add_watch(inotify_fd, c ? "/services" : AVAHI_SERVICE_DIR, IN_CLOSE_WRITE|IN_DELETE|IN_DELETE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_MOVE_SELF
+#ifdef IN_ONLYDIR
+                      |IN_ONLYDIR
+#endif
+    );
+    inotify_add_watch(inotify_fd, c ? "/" : AVAHI_CONFIG_DIR, IN_CLOSE_WRITE|IN_DELETE|IN_DELETE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_MOVE_SELF
+#ifdef IN_ONLYDIR
+                      |IN_ONLYDIR
+#endif
+    );
 }
 
 #endif
@@ -1239,6 +1249,11 @@ int main(int argc, char *argv[]) {
         if (config.use_syslog || config.daemonize)
             daemon_log_use = DAEMON_LOG_SYSLOG;
 
+        if (daemon_close_all(-1) < 0) {
+            avahi_log_error("Failed to close remaining file descriptors: %s", strerror(errno));
+            goto finish;
+        }
+        
         if (make_runtime_dir() < 0)
             goto finish;