From: mdw Date: Sat, 20 Jan 2001 11:55:17 +0000 (+0000) Subject: Handle select errors more robustly. X-Git-Tag: 1.2.5~5 X-Git-Url: https://git.distorted.org.uk/~mdw/fwd/commitdiff_plain/f9d40245f5a776b34e0f0dcc2aad164e3b3d02af Handle select errors more robustly. --- diff --git a/fw.c b/fw.c index 8665b43..6b8f16d 100644 --- a/fw.c +++ b/fw.c @@ -1,6 +1,6 @@ /* -*-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 * @@ -29,6 +29,9 @@ /*----- 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. * @@ -532,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 --- */ @@ -568,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); }