diff --git a/ChangeLog b/ChangeLog index 86dac8f79..e8305dbdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-03-02 Julien Blache + * frontend/saned.c: work around backends that can't keep their + dirty fingers off stdin/stdout/stderr when run through inetd, + breaking the network dialog and crashing the remote net backend. + 2009-02-28 Chris Bagwell * m4/byteorder.m4: Delete temporary file in all cases. * backend/Makefile.am, japi/Makefile.am: Use BUILT_SOURCES diff --git a/frontend/saned.c b/frontend/saned.c index 7f17d55eb..ae9302960 100644 --- a/frontend/saned.c +++ b/frontend/saned.c @@ -3112,6 +3112,41 @@ static void run_inetd (int argc, char **argv) { int fd = 1; + int dave_null; + + /* Some backends really can't keep their dirty fingers off + * stdin/stdout/stderr; we work around them here so they don't + * mess up the network dialog and crash the remote net backend. + */ + do + { + fd = dup (fd); + + if (fd == -1) + { + DBG (DBG_ERR, "run_inetd: duplicating fd failed: %s", strerror (errno)); + return; + } + } + while (fd < 3); + + /* Our good'ole friend Dave Null to the rescue */ + dave_null = open ("/dev/null", O_RDWR); + if (dave_null < 0) + { + DBG (DBG_ERR, "run_inetd: could not open /dev/null: %s", strerror (errno)); + return; + } + + close (STDIN_FILENO); + close (STDOUT_FILENO); + close (STDERR_FILENO); + + dup2 (dave_null, STDIN_FILENO); + dup2 (dave_null, STDOUT_FILENO); + dup2 (dave_null, STDERR_FILENO); + + close (dave_null); #ifndef HAVE_OS2_H /* Unused in this function */