Handle select errors more robustly.
[fwd] / fw.c
diff --git a/fw.c b/fw.c
index 68871a6..6b8f16d 100644 (file)
--- a/fw.c
+++ b/fw.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: fw.c,v 1.7 2000/03/23 00:37:33 mdw Exp $
+ * $Id: fw.c,v 1.9 2001/01/20 11:55:17 mdw Exp $
  *
  * Port forwarding thingy
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: fw.c,v $
+ * Revision 1.9  2001/01/20 11:55:17  mdw
+ * Handle select errors more robustly.
+ *
+ * Revision 1.8  2000/03/23 23:19:19  mdw
+ * Fix changed options in parser table.
+ *
  * Revision 1.7  2000/03/23 00:37:33  mdw
  * Add option to change user and group after initialization.  Naughtily
  * reassign short equivalents of --grammar and --options.
@@ -405,8 +411,8 @@ int main(int argc, char *argv[])
 
       /* --- Other help options --- */
 
-      { "grammar",     0,              0,      'g' },
-      { "options",     0,              0,      'o' },
+      { "grammar",     0,              0,      'G' },
+      { "options",     0,              0,      'O' },
 
       /* --- Other useful arguments --- */
 
@@ -529,11 +535,13 @@ int main(int argc, char *argv[])
 
 #ifdef HAVE_SETGROUPS
   if ((dropg != -1 && (setgid(dropg) || setgroups(1, &dropg))) ||
+      (drop != -1 && setuid(drop)))
+    die(1, "couldn't drop privileges: %s", strerror(errno));
 #else
   if ((dropg != -1 && setgid(dropg)) ||
-#endif
       (drop != -1 && setuid(drop)))
     die(1, "couldn't drop privileges: %s", strerror(errno));
+#endif
 
   /* --- Fork into the background --- */
 
@@ -565,8 +573,23 @@ int main(int argc, char *argv[])
   if (!(flags & FW_SET))
     moan("nothing to do!");
   signal(SIGPIPE, SIG_IGN);
-  while (active)
-    sel_select(sel);
+
+  {
+    int selerr = 0;
+    while (active) {
+      if (!sel_select(sel))
+        selerr = 0;
+      else {
+       fw_log(-1, "error from select: %s", strerror(errno));
+       selerr++;
+       if (selerr > 8) {
+         fw_log(-1, "too many consecutive select errors: bailing out");
+         exit(EXIT_FAILURE);
+       }
+      }
+    }
+  }
+    
   return (0);
 }