-const char errlog_rcs[] = "$Id: errlog.c,v 1.97 2009/06/14 15:59:56 fabiankeil Exp $";
+const char errlog_rcs[] = "$Id: errlog.c,v 1.98 2009/07/08 23:18:05 ler762 Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
{
fclose(logfp);
}
+#ifdef unix
+ if (!no_daemon && (logfp == stderr))
+ {
+ if (dup2(1, 2) == -1)
+ {
+ /*
+ * We only use fatal_error() to clear the pid
+ * file and to exit. Given that stderr has just
+ * been closed, the user will not see the error
+ * message.
+ */
+ fatal_error("Failed to reserve fd 2.");
+ }
+ }
+#endif
logfp = fp;
unlock_logfile();
-const char jcc_rcs[] = "$Id: jcc.c,v 1.306 2009/12/22 13:04:10 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.307 2009/12/26 11:32:54 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
if (!no_daemon)
{
+ int fd;
+
pid = fork();
if ( pid < 0 ) /* error */
* stderr (fd 2) will be closed later on,
* when the config file has been parsed.
*/
+ close(0);
+ close(1);
+
+ /*
+ * Reserve fd 0 and 1 to prevent abort() and friends
+ * from sending stuff to the clients or servers.
+ */
+ fd = open("/dev/null", O_RDONLY);
+ if (fd > 0)
+ {
+ if (dup2(fd, 0) == -1)
+ {
+ log_error(LOG_LEVEL_FATAL, "Failed to reserve fd 0: %E");
+ }
+ close(fd);
+ fd = open("/dev/null", O_WRONLY);
+ if ((fd >= 0) && (fd != 1))
+ {
+ if (dup2(fd, 1) == -1)
+ {
+ log_error(LOG_LEVEL_FATAL, "Failed to reserve fd 1: %E");
+ }
+ close(fd);
+ }
+ }
+ if (fd == -1)
+ {
+ log_error(LOG_LEVEL_FATAL, "Failed to open /dev/null: %E");
+ }
- close( 0 );
- close( 1 );
chdir("/");
} /* -END- if (!no_daemon) */