Commits

Bryan O'Sullivan committed 51bc5b8

More changes from Steve Grubb

Comments (0)

Files changed (2)

     }
 
     if (!foreground) {
-        if (daemon(0, 0) == -1) {
-            do_log(LOG_ERR, "daemon: %m");
-            exit(1);
-        }
         use_syslog = 1;
         openlog("netplugd", LOG_PID, LOG_DAEMON);
 
         exit(1);
     }
 
+    if (!foreground && daemon(0, 0) == -1) {
+        do_log(LOG_ERR, "daemon: %m");
+        exit(1);
+    }
+
     struct pollfd fds[] = {
         { fd, POLLIN, 0 },
         { child_handler_pipe[0], POLLIN, 0 },
             if (l < 0 || len > status) {
                 if (msg.msg_flags & MSG_TRUNC) {
                     do_log(LOG_ERR, "Truncated message");
-                    exit(1);
+                    return 1;
                 }
                 do_log(LOG_ERR, "Malformed netlink message");
-                exit(1);
+                return 1;
             }
 
             if (callback) {
         }
         if (status) {
             do_log(LOG_ERR, "!!!Remnant of size %d", status);
-            exit(1);
+            return 1;
         }
     outer:
         /* do nothing */;
 	switch (receive(fd, &msg, &status)) {
 	case bail:
 	case done:
-	    return;
+	    exit(1);
 	case user:
 	case skip:
 	    continue;
 
                 if ((err = callback(hdr, arg)) == -1) {
                     do_log(LOG_ERR, "Callback failed");
-                    return;
+                    exit(1);
                 }
             }
 
         }
         if (msg.msg_flags & MSG_TRUNC) {
             do_log(LOG_ERR, "Message truncated");
-            continue;
+            exit(1);
         }
         if (status) {
             do_log(LOG_ERR, "Dangling remnant of size %d!", status);