-const char jcc_rcs[] = "$Id: jcc.c,v 1.307 2009/12/26 11:32:54 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.310 2009/12/29 13:17:37 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
const char jcc_h_rcs[] = JCC_H_VERSION;
const char project_h_rcs[] = PROJECT_H_VERSION;
-int no_daemon = 0;
+int daemon_mode = 1;
struct client_state clients[1];
struct file_list files[1];
else if (strcmp(argv[argc_pos], "--no-daemon" ) == 0)
{
set_debug_level(LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
- no_daemon = 1;
+ daemon_mode = 0;
}
else if (strcmp(argv[argc_pos], "--pidfile" ) == 0)
{
pid_t pid = 0;
- if (!no_daemon)
+ if (daemon_mode)
{
int fd;
* from sending stuff to the clients or servers.
*/
fd = open("/dev/null", O_RDONLY);
- if (fd > 0)
+ if (fd == -1)
+ {
+ log_error(LOG_LEVEL_FATAL, "Failed to open /dev/null: %E");
+ }
+ else 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);
- }
}
+ fd = open("/dev/null", O_WRONLY);
if (fd == -1)
{
log_error(LOG_LEVEL_FATAL, "Failed to open /dev/null: %E");
}
+ else if (fd != 1)
+ {
+ if (dup2(fd, 1) == -1)
+ {
+ log_error(LOG_LEVEL_FATAL, "Failed to reserve fd 1: %E");
+ }
+ close(fd);
+ }
chdir("/");
- } /* -END- if (!no_daemon) */
+ } /* -END- if (daemon_mode) */
/*
* As soon as we have written the PID file, we can switch