Add an internal-representation no-op function.
[u/mdw/catacomb] / pixie.c
diff --git a/pixie.c b/pixie.c
index ecbab8f..363f833 100644 (file)
--- a/pixie.c
+++ b/pixie.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: pixie.c,v 1.8 2001/01/25 22:19:31 mdw Exp $
+ * $Id: pixie.c,v 1.10 2001/02/21 20:03:54 mdw Exp $
  *
  * Passphrase pixie for Catacomb
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: pixie.c,v $
+ * Revision 1.10  2001/02/21 20:03:54  mdw
+ * Handle select errors (by bombing out).  Cosmetic tweak.
+ *
+ * Revision 1.9  2001/02/03 16:06:44  mdw
+ * Don't set a handler for @SIGINT@ if it's ignored at startup.  Add some
+ * error handling for the @select@ loop.
+ *
  * Revision 1.8  2001/01/25 22:19:31  mdw
  * Make flags be unsigned.
  *
@@ -1100,8 +1107,8 @@ static void c_sline(char *s, void *p)
       selbuf_destroy(&c_client);
     }
     exit(0);
-  } else 
-    puts(s);
+  }
+  puts(s);
 }
 
 /* --- @pix_client@ --- *
@@ -1151,8 +1158,10 @@ static void pix_client(struct sockaddr_un *sun, size_t sz, char *argv[])
 
   /* --- And repeat --- */
 
-  for (;;)
-    sel_select(&sel);
+  for (;;) {
+    if (sel_select(&sel))
+      die(EXIT_FAILURE, "select error: %s", strerror(errno));
+  }
 }
 
 /*----- Main code ---------------------------------------------------------*/
@@ -1389,8 +1398,11 @@ int main(int argc, char *argv[])
 
   {
     static sig sigint, sigterm, sigquit, sighup;
+    struct sigaction sa;
     sig_init(&sel);
-    sig_add(&sigint, SIGINT, pix_sigdie, 0);
+    sigaction(SIGINT, 0, &sa);
+    if (sa.sa_handler != SIG_IGN)
+      sig_add(&sigint, SIGINT, pix_sigdie, 0);
     sig_add(&sigterm, SIGTERM, pix_sigdie, 0);
     sig_add(&sigquit, SIGQUIT, pix_sigflush, 0);
     sig_add(&sighup, SIGHUP, pix_sigflush, 0);
@@ -1431,14 +1443,28 @@ int main(int argc, char *argv[])
     chdir("/");
     setsid();
 
-    if (fork() > 0)
+    if (fork() >= 0)
       _exit(0);
   }
 
   if (verbose)
     log("initialized ok");
-  for (;;)
-    sel_select(&sel);
+
+  {
+    int selerr = 0;
+    for (;;) {
+      if (!sel_select(&sel))
+       selerr = 0;
+      else if (errno != EINTR && errno != EAGAIN) {
+       log("error from select: %s", strerror(errno));
+       selerr++;
+       if (selerr > 8) {
+         log("too many consecutive select errors: bailing out");
+         exit(EXIT_FAILURE);
+       }
+      }
+    }
+  }
   return (0);
 }