]> git.proxmox.com Git - mirror_frr.git/blobdiff - watchquagga/watchquagga.c
watchquagga: add ZLOG_WATCHQUAGGA
[mirror_frr.git] / watchquagga / watchquagga.c
index 1e930f4018daac9b38dd682b74d229af537fc0d7..aa5d1bcd80dc07d2f5f40a9a28d4c5f4f924e929 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/un.h>
 #include <sys/wait.h>
 #include <memory.h>
+#include <systemd.h>
 
 #ifndef MIN
 #define MIN(X,Y) (((X) <= (Y)) ? (X) : (Y))
@@ -215,7 +216,8 @@ usage(const char *progname, int status)
   if (status != 0)
     fprintf(stderr, "Try `%s --help' for more information.\n", progname);
   else
-    printf("Usage : %s [OPTION...] <daemon name> ...\n\n\
+    {
+      printf("Usage : %s [OPTION...] <daemon name> ...\n\n\
 Watchdog program to monitor status of quagga daemons and try to restart\n\
 them if they are down or unresponsive.  It determines whether a daemon is\n\
 up based on whether it can connect to the daemon's vty unix stream socket.\n\
@@ -259,8 +261,12 @@ the -m and -M options allow you to control the minimum delay between\n\
 restart commands.  The minimum restart delay is recalculated each time\n\
 a restart is attempted: if the time since the last restart attempt exceeds\n\
 twice the -M value, then the restart delay is set to the -m value.\n\
-Otherwise, the interval is doubled (but capped at the -M value).\n\n\
-Options:\n\
+Otherwise, the interval is doubled (but capped at the -M value).\n\n",
+        progname,mode_str[0],progname,mode_str[1],progname,mode_str[2],
+        progname,mode_str[3],progname,mode_str[4],progname,mode_str[2],
+        mode_str[3]);
+
+      printf("Options:\n\
 -d, --daemon   Run in daemon mode.  In this mode, error messages are sent\n\
                to syslog instead of stdout.\n\
 -S, --statedir Set the vty socket directory (default is %s)\n\
@@ -318,12 +324,12 @@ Options:\n\
                it with a space.  This is an ugly hack to circumvent problems\n\
                passing command-line arguments with embedded spaces.\n\
 -v, --version  Print program version\n\
--h, --help     Display this help and exit\n\
-", progname,mode_str[0],progname,mode_str[1],progname,mode_str[2],
-progname,mode_str[3],progname,mode_str[4],progname,mode_str[2],mode_str[3],
-VTYDIR,DEFAULT_LOGLEVEL,LOG_EMERG,LOG_DEBUG,LOG_DEBUG,
-DEFAULT_MIN_RESTART,DEFAULT_MAX_RESTART,
-DEFAULT_PERIOD,DEFAULT_TIMEOUT,DEFAULT_RESTART_TIMEOUT,DEFAULT_PIDFILE);
+-h, --help     Display this help and exit\n",
+        VTYDIR,DEFAULT_LOGLEVEL,LOG_EMERG,LOG_DEBUG,LOG_DEBUG,
+        DEFAULT_MIN_RESTART,DEFAULT_MAX_RESTART,
+        DEFAULT_PERIOD,DEFAULT_TIMEOUT,DEFAULT_RESTART_TIMEOUT,
+        DEFAULT_PIDFILE);
+    }
 
   return status;
 }
@@ -383,7 +389,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,(int)restart->pid,delay.tv_sec,
+           restart->what,restart->name,(int)restart->pid, (long)delay.tv_sec,
            (restart->kills ? SIGKILL : SIGTERM));
   kill(-restart->pid,(restart->kills ? SIGKILL : SIGTERM));
   restart->kills++;
@@ -656,15 +662,17 @@ handle_read(struct thread *t_read)
        {
          dmn->state = DAEMON_UP;
          zlog_warn("%s state -> up : echo response received after %ld.%06ld "
-                   "seconds", dmn->name,delay.tv_sec,delay.tv_usec);
+                   "seconds", dmn->name,
+                   (long)delay.tv_sec, (long)delay.tv_usec);
        }
       else
        zlog_warn("%s: slow echo response finally received after %ld.%06ld "
-                 "seconds", dmn->name,delay.tv_sec,delay.tv_usec);
+                 "seconds", dmn->name,
+                 (long)delay.tv_sec, (long)delay.tv_usec);
     }
   else if (gs.loglevel > LOG_DEBUG+1)
     zlog_debug("%s: echo response received after %ld.%06ld seconds",
-              dmn->name,delay.tv_sec,delay.tv_usec);
+              dmn->name, (long)delay.tv_sec, (long)delay.tv_usec);
 
   SET_READ_HANDLER(dmn);
   if (dmn->t_wakeup)
@@ -985,6 +993,7 @@ static void
 sigint(void)
 {
   zlog_notice("Terminating on signal");
+  systemd_send_stopping ();
   exit(0);
 }
 
@@ -1275,6 +1284,7 @@ main(int argc, char **argv)
       
   gs.restart.interval = gs.min_restart_interval;
   master = thread_master_create();
+  systemd_send_started (master, 0);
   signal_init (master, array_size(my_signals), my_signals);
   srandom(time(NULL));
 
@@ -1324,14 +1334,8 @@ main(int argc, char **argv)
              mode_str[gs.mode],special);
       return usage(progname,1);
     }
-  if (gs.special && (gs.numdaemons < 2))
-    {
-      fprintf(stderr,"Mode [%s] does not make sense with only 1 daemon "
-                    "to watch.\n",mode_str[gs.mode]);
-      return usage(progname,1);
-    }
 
-  zlog_default = openzlog(progname, ZLOG_NONE, 0,
+  zlog_default = openzlog(progname, ZLOG_WATCHQUAGGA, 0,
                          LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
   zlog_set_level(NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
   if (daemon_mode)
@@ -1380,6 +1384,7 @@ main(int argc, char **argv)
       thread_call (&thread);
   }
 
+  systemd_send_stopping ();
   /* Not reached. */
   return 0;
 }