Commits

Bryan O'Sullivan committed c7aa506

Log assert failures properly.

Comments (0)

Files changed (3)

     return WIFEXITED(status) ? WEXITSTATUS(status) : -WTERMSIG(status);
 }
 
+
 /*
    Synchronously kill a script
 
     sigprocmask(SIG_SETMASK, &origmask, NULL);
 }
 
+
 void *
 xmalloc(size_t n)
 {
 }
 
 
+void
+__assert_fail(const char *assertion, const char *file,
+              unsigned int line, const char *function)
+{
+    do_log(LOG_CRIT, "%s:%u: %s%sAssertion `%s' failed",
+           file, line,
+           function ? function : "",
+           function ? ": " : "",
+           assertion);
+
+    abort();
+}
+
+
 /*
  * Local variables:
  * c-file-style: "stroustrup"
 static void
 usage(char *progname, int exitcode)
 {
-    fprintf(stderr, "Usage: %s [-DFP] [-c config-file] [-i interface] [-p pid-file]\n", 
-	    progname);
+    fprintf(stderr, "Usage: %s [-FPcip]\n", progname);
 
-    fprintf(stderr, "\t-D\t\t"
-            "print extra debugging messages\n");
     fprintf(stderr, "\t-F\t\t"
             "run in foreground (don't become a daemon)\n");
     fprintf(stderr, "\t-P\t\t"
 
         /* Make sure we don't miss anything interesting */
         poll_interfaces();
+
+        ret = poll(fds, sizeof(fds)/sizeof(fds[0]), -1);
+
+        if (ret == -1) {
+            if (errno == EINTR)
+                continue;
+            do_log(LOG_ERR, "poll failed: %m");
+            exit(1);
+        }
+        if (ret == 0)
+            continue;           /* XXX??? */
+
+        if (fds[0].revents & POLLIN) {
+            /* interface flag state change */
+            if (netlink_listen(fd, handle_interface, NULL) == 0)
+                break;          /* done */
+        }
+
+        if (fds[1].revents & POLLIN) {
+            /* netplug script finished */
+            int ret;
+            struct child_exit ce;
+
+            do {
+                ret = read(child_handler_pipe[0], &ce, sizeof(ce));
+
+                assert(ret == 0 || ret == -1 || ret == sizeof(ce));
+
+                if (ret == sizeof(ce))
+                    ifsm_scriptdone(ce.pid, ce.status);
+                else if (ret == -1 && errno != EAGAIN) {
+                    do_log(LOG_ERR, "pipe read failed: %m");
+                    exit(1);
+                }
+            } while(ret == sizeof(ce));
+        }
     }
 
     return 0;

man/man8/netplugd.8

 .It Fl i Ar interface_pattern
 Specify a pattern that will be used to match interface names that
 .Nm
-should manage.  You can provide this option multiple times to specify
+should manage.  You can probide this option multiple times to specify
 multiple patterns.
 .\"
 .It Fl p Ar pid_file
 .Bl -tag -width Ds
 .It in
 A cable was plugged in, or carrier came up.  The command should bring
-the interface up.  The command is run asynchronously, and it should
-exit with status 0 on success.
+the interface up.  The command is run asynchronously, and its exit
+status is ignored.
 .It out
 A cable was plugged out, or carrier went down.  The command should
-bring the interface down.  The command is run asynchronously, and it should
-exit with status 0 on success.
+bring the interface down.  The command is run asynchronously, and its exit
+status is ignored.
 .It probe
 The command should load and initialise the driver for this interface,
 if possible, and bring the interface into the "up" state, so that it