Allow the caller to fetch the parameter generation seed and counter.
[u/mdw/catacomb] / pixie.c
diff --git a/pixie.c b/pixie.c
index d4aefdf..5482798 100644 (file)
--- a/pixie.c
+++ b/pixie.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: pixie.c,v 1.7 2000/12/06 20:33:27 mdw Exp $
+ * $Id: pixie.c,v 1.9 2001/02/03 16:06:44 mdw Exp $
  *
  * Passphrase pixie for Catacomb
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: pixie.c,v $
+ * 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.
+ *
  * Revision 1.7  2000/12/06 20:33:27  mdw
  * Make flags be macros rather than enumerations, to ensure that they're
  * unsigned.
@@ -603,7 +610,7 @@ typedef struct pixserv {
   unsigned f;
 } pixserv;
 
-enum { px_stdin = 1 };
+#define px_stdin 1u
 
 #define PIXSERV_TIMEOUT 30
 
@@ -1068,7 +1075,9 @@ static void pix_setup(struct sockaddr_un *sun, size_t sz)
 
 static selbuf c_server, c_client;
 static unsigned c_flags = 0;
-enum { cf_uclose = 1, cf_sclose = 2 };
+
+#define cf_uclose 1u
+#define cf_sclose 2u
 
 /* --- Line handler functions --- */
 
@@ -1384,8 +1393,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);
@@ -1426,14 +1438,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);
 }