Handle select errors more robustly.
authormdw <mdw>
Sat, 20 Jan 2001 11:55:17 +0000 (11:55 +0000)
committermdw <mdw>
Sat, 20 Jan 2001 11:55:17 +0000 (11:55 +0000)
fw.c

diff --git a/fw.c b/fw.c
index 8665b43..6b8f16d 100644 (file)
--- a/fw.c
+++ b/fw.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: fw.c,v 1.8 2000/03/23 23:19:19 mdw Exp $
+ * $Id: fw.c,v 1.9 2001/01/20 11:55:17 mdw Exp $
  *
  * Port forwarding thingy
  *
  *
  * Port forwarding thingy
  *
@@ -29,6 +29,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: fw.c,v $
 /*----- 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.8  2000/03/23 23:19:19  mdw
  * Fix changed options in parser table.
  *
@@ -532,11 +535,13 @@ int main(int argc, char *argv[])
 
 #ifdef HAVE_SETGROUPS
   if ((dropg != -1 && (setgid(dropg) || setgroups(1, &dropg))) ||
 
 #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)) ||
 #else
   if ((dropg != -1 && setgid(dropg)) ||
-#endif
       (drop != -1 && setuid(drop)))
     die(1, "couldn't drop privileges: %s", strerror(errno));
       (drop != -1 && setuid(drop)))
     die(1, "couldn't drop privileges: %s", strerror(errno));
+#endif
 
   /* --- Fork into the background --- */
 
 
   /* --- Fork into the background --- */
 
@@ -568,8 +573,23 @@ int main(int argc, char *argv[])
   if (!(flags & FW_SET))
     moan("nothing to do!");
   signal(SIGPIPE, SIG_IGN);
   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);
 }
 
   return (0);
 }