]> git.proxmox.com Git - mirror_frr.git/blobdiff - watchquagga/watchquagga.c
bgp: missing pieces from listener patch
[mirror_frr.git] / watchquagga / watchquagga.c
index e67c61d5f95de2b608b00d62334631e3627cdcf6..f4c483cf428a9719eadac46b933b698abd4f4b9d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    $Id: watchquagga.c,v 1.7 2004/12/29 17:39:10 ajs Exp $
+    $Id$
 
     Monitor status of quagga daemons and restart if necessary.
 
@@ -23,6 +23,7 @@
 #include <zebra.h>
 #include <thread.h>
 #include <log.h>
+#include <network.h>
 #include <sigevent.h>
 #include <lib/version.h>
 #include <getopt.h>
@@ -353,7 +354,7 @@ run_background(const char *shell_cmd)
       }
     default:
       /* Parent process: we will reap the child later. */
-      zlog_err("Forked background command [pid %d]: %s",child,shell_cmd);
+      zlog_err("Forked background command [pid %d]: %s",(int)child,shell_cmd);
       return child;
     }
 }
@@ -381,7 +382,7 @@ restart_kill(struct thread *t_kill)
   time_elapsed(&delay,&restart->time);
   zlog_warn("Warning: %s %s child process %d still running after "
            "%ld seconds, sending signal %d",
-           restart->what,restart->name,restart->pid,delay.tv_sec,
+           restart->what,restart->name,(int)restart->pid,delay.tv_sec,
            (restart->kills ? SIGKILL : SIGTERM));
   kill(-restart->pid,(restart->kills ? SIGKILL : SIGTERM));
   restart->kills++;
@@ -443,27 +444,27 @@ sigchild(void)
   else
     {
       zlog_err("waitpid returned status for an unknown child process %d",
-              child);
+              (int)child);
       name = "(unknown)";
       what = "background";
     }
   if (WIFSTOPPED(status))
       zlog_warn("warning: %s %s process %d is stopped",
-               what,name,child);
+               what,name,(int)child);
   else if (WIFSIGNALED(status))
     zlog_warn("%s %s process %d terminated due to signal %d",
-             what,name,child,WTERMSIG(status));
+             what,name,(int)child,WTERMSIG(status));
   else if (WIFEXITED(status))
     {
       if (WEXITSTATUS(status) != 0)
        zlog_warn("%s %s process %d exited with non-zero status %d",
-                 what,name,child,WEXITSTATUS(status));
+                 what,name,(int)child,WEXITSTATUS(status));
       else
-       zlog_debug("%s %s process %d exited normally",what,name,child);
+       zlog_debug("%s %s process %d exited normally",what,name,(int)child);
     }
   else
     zlog_err("cannot interpret %s %s process %d wait status 0x%x",
-            what,name,child,status);
+            what,name,(int)child,status);
   phase_check();
 }
 
@@ -480,12 +481,15 @@ run_job(struct restart_info *restart, const char *cmdtype, const char *command,
     {
       if (gs.loglevel > LOG_DEBUG+1)
         zlog_debug("cannot %s %s, previous pid %d still running",
-                  cmdtype,restart->name,restart->pid);
+                  cmdtype,restart->name,(int)restart->pid);
       return -1;
     }
 
-  if (!force &&
-      (time_elapsed(&delay,&restart->time)->tv_sec < restart->interval))
+  /* Note: time_elapsed test must come before the force test, since we need
+     to make sure that delay is initialized for use below in updating the
+     restart interval. */
+  if ((time_elapsed(&delay,&restart->time)->tv_sec < restart->interval) &&
+      !force)
     {
       if (gs.loglevel > LOG_DEBUG+1)
         zlog_debug("postponing %s %s: "
@@ -605,7 +609,7 @@ handle_read(struct thread *t_read)
     {
       char why[100];
 
-      if ((errno == EINTR) || (errno == EAGAIN))
+      if (ERRNO_IO_RETRY(errno))
        {
          /* Pretend it never happened. */
          SET_READ_HANDLER(dmn);
@@ -730,7 +734,6 @@ try_connect(struct daemon *dmn)
   int sock;
   struct sockaddr_un addr;
   socklen_t len;
-  int flags;
 
   if (gs.loglevel > LOG_DEBUG+1)
     zlog_debug("%s: attempting to connect",dmn->name);
@@ -740,11 +743,11 @@ try_connect(struct daemon *dmn)
   addr.sun_family = AF_UNIX;
   snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s.vty",
           gs.vtydir,dmn->name);
-#ifdef HAVE_SUN_LEN
+#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
   len = addr.sun_len = SUN_LEN(&addr);
 #else
   len = sizeof (addr.sun_family) + strlen (addr.sun_path);
-#endif /* HAVE_SUN_LEN */
+#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
 
   /* Quick check to see if we might succeed before we go to the trouble
      of creating a socket. */
@@ -763,18 +766,10 @@ try_connect(struct daemon *dmn)
       return -1;
     }
 
-  /* Set non-blocking. */
-  if ((flags = fcntl(sock, F_GETFL, 0)) < 0)
+  if (set_nonblocking(sock) < 0)
     {
-      zlog_err("%s(%s): fcntl(F_GETFL) failed: %s",
-              __func__,addr.sun_path, safe_strerror(errno));
-      close(sock);
-      return -1;
-    }
-  if (fcntl(sock, F_SETFL, (flags|O_NONBLOCK)) < 0)
-    {
-      zlog_err("%s(%s): fcntl(F_SETFL,O_NONBLOCK) failed: %s",
-              __func__,addr.sun_path, safe_strerror(errno));
+      zlog_err("%s(%s): set_nonblocking(%d) failed",
+              __func__, addr.sun_path, sock);
       close(sock);
       return -1;
     }
@@ -861,7 +856,7 @@ phase_check(void)
        for (dmn = gs.daemons; dmn; dmn = dmn->next)
          {
            if (dmn != gs.special)
-             run_job(&dmn->restart,"start",gs.start_command,1,1);
+             run_job(&dmn->restart,"start",gs.start_command,1,0);
          }
       }
       gs.phase = PHASE_NONE;
@@ -923,7 +918,7 @@ try_restart(struct daemon *dmn)
     for (dmn = gs.daemons; dmn; dmn = dmn->next)
       {
         if (dmn != gs.special)
-         run_job(&dmn->restart,"stop",gs.stop_command,1,0);
+         run_job(&dmn->restart,"stop",gs.stop_command,1,1);
       }
     set_phase(PHASE_STOPS_PENDING);
     break;