-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) */