+ while (waitpid(-1, NULL, WNOHANG) > 0);
+}
+
+/* Handle other signals in event loop by writing signal number to pipe */
+int eventpipe[2];
+static void handle_signal(int signalnum) {
+ write(eventpipe[1], &signalnum, sizeof signalnum);
+}
+
+/* Callbacks for polling the event pipe in the GLib event loop */
+static GPollFD fdevents_pfd;
+/* Called before entering the poll() */
+static gboolean fdevents_prepare(GSource *source, gint *timeout) {
+ /* No timeout for poll() */
+ *timeout = -1;
+ return FALSE;
+}
+/* Check to see whether a handled event has happened */
+static gboolean fdevents_check(GSource *source) {
+ return !!(fdevents_pfd.revents & G_IO_IN);
+}
+/* Read the event from the pipe and handle it */
+static gboolean fdevents_dispatch(GSource *source,
+ GSourceFunc callback, gpointer user_data) {
+ int eventnum;
+
+ if (read(eventpipe[0], &eventnum, sizeof eventnum) == (sizeof eventnum)) {
+ /* Handle the event passed to us */
+ switch (eventnum) {
+ /* SIGHUP received -- reread config file */
+ case SIGHUP:
+ read_config();
+ break;
+ default:
+ return FALSE;
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }