Browse Source

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.
Stephen Hemminger 10 years ago
parent
commit
065de90380
9 changed files with 45 additions and 17 deletions
  1. 5 2
      isisd/isis_main.c
  2. 5 2
      ospf6d/ospf6_main.c
  3. 5 2
      ospfd/ospf_main.c
  4. 5 2
      ripd/rip_main.c
  5. 5 2
      ripngd/ripng_main.c
  6. 5 2
      tests/main.c
  7. 5 1
      watchquagga/watchquagga.c
  8. 5 2
      zebra/main.c
  9. 5 2
      zebra/test_main.c

+ 5 - 2
isisd/isis_main.c

@@ -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);

+ 5 - 2
ospf6d/ospf6_main.c

@@ -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);

+ 5 - 2
ospfd/ospf_main.c

@@ -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);

+ 5 - 2
ripd/rip_main.c

@@ -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);

+ 5 - 2
ripngd/ripng_main.c

@@ -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);

+ 5 - 2
tests/main.c

@@ -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");

+ 5 - 1
watchquagga/watchquagga.c

@@ -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));

+ 5 - 2
zebra/main.c

@@ -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);

+ 5 - 2
zebra/test_main.c

@@ -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 ();