all: check return value from daemon() call

* */*main.c: (main) Current versions of Gcc warn if the return value for
  daemon() is not checked.  So add a simple test and exit on failure.
This commit is contained in:
Stephen Hemminger 2009-08-07 11:13:49 -07:00 committed by Paul Jakma
parent 5bd5881838
commit 065de90380
9 changed files with 45 additions and 17 deletions

View File

@ -333,8 +333,11 @@ main (int argc, char **argv, char **envp)
return(0);
/* demonize */
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
zlog_err("ISISd daemon failed: %s", strerror(errno));
exit (1);
}
/* Process ID file creation. */
pid_output (pid_file);

View File

@ -282,8 +282,11 @@ main (int argc, char *argv[], char *envp[])
if (dryrun)
return(0);
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
zlog_err("OSPF6d daemon failed: %s", strerror(errno));
exit (1);
}
/* pid file create */
pid_output (pid_file);

View File

@ -314,8 +314,11 @@ main (int argc, char **argv)
return(0);
/* Change to the daemon program. */
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
zlog_err("OSPFd daemon failed: %s", strerror(errno));
exit (1);
}
/* Process id file create. */
pid_output (pid_file);

View File

@ -292,8 +292,11 @@ main (int argc, char **argv)
return (0);
/* Change to the daemon program. */
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
zlog_err("RIPd daemon failed: %s", strerror(errno));
exit (1);
}
/* Pid file create. */
pid_output (pid_file);

View File

@ -288,8 +288,11 @@ main (int argc, char **argv)
return(0);
/* Change to the daemon program. */
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
zlog_err("RIPNGd daemon failed: %s", strerror(errno));
exit (1);
}
/* Create VTY socket */
vty_serv_sock (vty_addr, vty_port, RIPNG_VTYSH_PATH);

View File

@ -174,8 +174,11 @@ main (int argc, char **argv)
sort_node ();
/* Change to the daemon program. */
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
fprintf(stderr, "daemon failed: %s", strerror(errno));
exit (1);
}
/* Create VTY socket */
vty_serv_sock (vty_addr, vty_port, "/tmp/.heavy.sock");

View File

@ -1343,7 +1343,11 @@ main(int argc, char **argv)
if (daemon_mode)
{
zlog_set_level(NULL, ZLOG_DEST_SYSLOG, MIN(gs.loglevel,LOG_DEBUG));
daemon(0, 0);
if (daemon (0, 0) < 0)
{
fprintf(stderr, "Watchquagga daemon failed: %s", strerror(errno));
exit (1);
}
}
else
zlog_set_level(NULL, ZLOG_DEST_STDOUT, MIN(gs.loglevel,LOG_DEBUG));

View File

@ -362,8 +362,11 @@ main (int argc, char **argv)
exit (0);
/* Daemonize. */
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
zlog_err("Zebra daemon failed: %s", strerror(errno));
exit (1);
}
/* Output pid of zebra. */
pid_output (pid_file);

View File

@ -308,8 +308,11 @@ main (int argc, char **argv)
exit (0);
/* Daemonize. */
if (daemon_mode)
daemon (0, 0);
if (daemon_mode && daemon (0, 0) < 0)
{
perror("daemon start failed");
exit (1);
}
/* Needed for BSD routing socket. */
pid = getpid ();