/*
    Monitor status of quagga daemons and restart if necessary.

    Copyright (C) 2004  Andrew J. Schorr

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <zebra.h>
#include <thread.h>
#include <log.h>
#include <network.h>
#include <sigevent.h>
#include <lib/version.h>
#include <getopt.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <memory.h>

#ifndef MIN
#define MIN(X,Y) (((X) <= (Y)) ? (X) : (Y))
#endif

/* Macros to help randomize timers. */
#define JITTER(X) ((random() % ((X)+1))-((X)/2))
#define FUZZY(X) ((X)+JITTER((X)/20))

#define DEFAULT_PERIOD		5
#define DEFAULT_TIMEOUT		10
#define DEFAULT_RESTART_TIMEOUT	20
#define DEFAULT_LOGLEVEL	LOG_INFO
#define DEFAULT_MIN_RESTART	60
#define DEFAULT_MAX_RESTART	600
#ifdef PATH_WATCHQUAGGA_PID
#define DEFAULT_PIDFILE		PATH_WATCHQUAGGA_PID
#else
#define DEFAULT_PIDFILE		STATEDIR "/watchquagga.pid"
#endif
#ifdef DAEMON_VTY_DIR
#define VTYDIR			DAEMON_VTY_DIR
#else
#define VTYDIR			STATEDIR
#endif

#define PING_TOKEN	"PING"

/* Needs to be global, referenced somewhere inside libzebra. */
struct thread_master *master;

typedef enum
{
  MODE_MONITOR = 0,
  MODE_GLOBAL_RESTART,
  MODE_SEPARATE_RESTART,
  MODE_PHASED_ZEBRA_RESTART,
  MODE_PHASED_ALL_RESTART
} watch_mode_t;

static const char *mode_str[] =
{
  "monitor",
  "global restart",
  "individual daemon restart",
  "phased zebra restart",
  "phased global restart for any failure",
};

typedef enum
{
  PHASE_NONE = 0,
  PHASE_STOPS_PENDING,
  PHASE_WAITING_DOWN,
  PHASE_ZEBRA_RESTART_PENDING,
  PHASE_WAITING_ZEBRA_UP
} restart_phase_t;

static const char *phase_str[] =
{
  "None",
  "Stop jobs running",
  "Waiting for other daemons to come down",
  "Zebra restart job running",
  "Waiting for zebra to come up",
  "Start jobs running",
};

#define PHASE_TIMEOUT (3*gs.restart_timeout)

struct restart_info
{
  const char *name;
  const char *what;
  pid_t pid;
  struct timeval time;
  long interval;
  struct thread *t_kill;
  int kills;
};

static struct global_state
{
  watch_mode_t mode;
  restart_phase_t phase;
  struct thread *t_phase_hanging;
  const char *vtydir;
  long period;
  long timeout;
  long restart_timeout;
  long min_restart_interval;
  long max_restart_interval;
  int do_ping;
  struct daemon *daemons;
  const char *restart_command;
  const char *start_command;
  const char *stop_command;
  struct restart_info restart;
  int unresponsive_restart;
  int loglevel;
  struct daemon *special;	/* points to zebra when doing phased restart */
  int numdaemons;
  int numpids;
  int numdown;		/* # of daemons that are not UP or UNRESPONSIVE */
} gs = {
  .mode = MODE_MONITOR,
  .phase = PHASE_NONE,
  .vtydir = VTYDIR,
  .period = 1000*DEFAULT_PERIOD,
  .timeout = DEFAULT_TIMEOUT,
  .restart_timeout = DEFAULT_RESTART_TIMEOUT,
  .loglevel = DEFAULT_LOGLEVEL,
  .min_restart_interval = DEFAULT_MIN_RESTART,
  .max_restart_interval = DEFAULT_MAX_RESTART,
  .do_ping = 1,
};

typedef enum
{
  DAEMON_INIT,
  DAEMON_DOWN,
  DAEMON_CONNECTING,
  DAEMON_UP,
  DAEMON_UNRESPONSIVE
} daemon_state_t;

#define IS_UP(DMN) \
  (((DMN)->state == DAEMON_UP) || ((DMN)->state == DAEMON_UNRESPONSIVE))

static const char *state_str[] =
{
  "Init",
  "Down",
  "Connecting",
  "Up",
  "Unresponsive",
};

struct daemon {
  const char *name;
  daemon_state_t state;
  int fd;
  struct timeval echo_sent;
  u_int connect_tries;
  struct thread *t_wakeup;
  struct thread *t_read;
  struct thread *t_write;
  struct daemon *next;
  struct restart_info restart;
};

static const struct option longopts[] = 
{
  { "daemon", no_argument, NULL, 'd'},
  { "statedir", required_argument, NULL, 'S'},
  { "no-echo", no_argument, NULL, 'e'},
  { "loglevel", required_argument, NULL, 'l'},
  { "interval", required_argument, NULL, 'i'},
  { "timeout", required_argument, NULL, 't'},
  { "restart-timeout", required_argument, NULL, 'T'},
  { "restart", required_argument, NULL, 'r'},
  { "start-command", required_argument, NULL, 's'},
  { "kill-command", required_argument, NULL, 'k'},
  { "restart-all", required_argument, NULL, 'R'},
  { "all-restart", no_argument, NULL, 'a'},
  { "always-all-restart", no_argument, NULL, 'A'},
  { "unresponsive-restart", no_argument, NULL, 'z'},
  { "min-restart-interval", required_argument, NULL, 'm'},
  { "max-restart-interval", required_argument, NULL, 'M'},
  { "pid-file", required_argument, NULL, 'p'},
  { "blank-string", required_argument, NULL, 'b'},
  { "help", no_argument, NULL, 'h'},
  { "version", no_argument, NULL, 'v'},
  { NULL, 0, NULL, 0 }
};

static int try_connect(struct daemon *dmn);
static int wakeup_send_echo(struct thread *t_wakeup);
static void try_restart(struct daemon *dmn);
static void phase_check(void);

static int
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\
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\
It then repeatedly sends echo commands over that socket to determine whether\n\
the daemon is responsive.  If the daemon crashes, we will receive an EOF\n\
on the socket connection and know immediately that the daemon is down.\n\n\
The daemons to be monitored should be listed on the command line.\n\n\
This program can run in one of 5 modes:\n\n\
0. Mode: %s.\n\
  Just monitor and report on status changes.  Example:\n\
    %s -d zebra ospfd bgpd\n\n\
1. Mode: %s.\n\
  Whenever any daemon hangs or crashes, use the given command to restart\n\
  them all.  Example:\n\
    %s -dz \\\n\
      -R '/sbin/service zebra restart; /sbin/service ospfd restart' \\\n\
      zebra ospfd\n\n\
2. Mode: %s.\n\
  When any single daemon hangs or crashes, restart only the daemon that's\n\
  in trouble using the supplied restart command.  Example:\n\
    %s -dz -r '/sbin/service %%s restart' zebra ospfd bgpd\n\n\
3. Mode: %s.\n\
  The same as the previous mode, except that there is special treatment when\n\
  the zebra daemon is in trouble.  In that case, a phased restart approach\n\
  is used: 1. stop all other daemons; 2. restart zebra; 3. start the other\n\
  daemons.  Example:\n\
    %s -adz -r '/sbin/service %%s restart' \\\n\
      -s '/sbin/service %%s start' \\\n\
      -k '/sbin/service %%s stop' zebra ospfd bgpd\n\n\
4. Mode: %s.\n\
  This is the same as the previous mode, except that the phased restart\n\
  procedure is used whenever any of the daemons hangs or crashes.  Example:\n\
    %s -Adz -r '/sbin/service %%s restart' \\\n\
      -s '/sbin/service %%s start' \\\n\
      -k '/sbin/service %%s stop' zebra ospfd bgpd\n\n\
As of this writing, it is believed that mode 2 [%s]\n\
is not safe, and mode 3 [%s] may not be safe with some of the\n\
routing daemons.\n\n\
In order to avoid attempting to restart the daemons in a fast loop,\n\
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\
-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\
-e, --no-echo	Do not ping the daemons to test responsiveness (this\n\
		option is necessary if the daemons do not support the\n\
		echo command)\n\
-l, --loglevel	Set the logging level (default is %d).\n\
		The value should range from %d (LOG_EMERG) to %d (LOG_DEBUG),\n\
		but it can be set higher than %d if extra-verbose debugging\n\
		messages are desired.\n\
-m, --min-restart-interval\n\
		Set the minimum seconds to wait between invocations of daemon\n\
		restart commands (default is %d).\n\
-M, --max-restart-interval\n\
		Set the maximum seconds to wait between invocations of daemon\n\
		restart commands (default is %d).\n\
-i, --interval	Set the status polling interval in seconds (default is %d)\n\
-t, --timeout	Set the unresponsiveness timeout in seconds (default is %d)\n\
-T, --restart-timeout\n\
		Set the restart (kill) timeout in seconds (default is %d).\n\
		If any background jobs are still running after this much\n\
		time has elapsed, they will be killed.\n\
-r, --restart	Supply a Bourne shell command to use to restart a single\n\
		daemon.  The command string should include '%%s' where the\n\
		name of the daemon should be substituted.\n\
		Note that -r and -R are incompatible.\n\
-s, --start-command\n\
		Supply a Bourne shell to command to use to start a single\n\
		daemon.  The command string should include '%%s' where the\n\
		name of the daemon should be substituted.\n\
-k, --kill-command\n\
		Supply a Bourne shell to command to use to stop a single\n\
		daemon.  The command string should include '%%s' where the\n\
		name of the daemon should be substituted.\n\
-R, --restart-all\n\
		When one or more daemons is down, try to restart everything\n\
		using the Bourne shell command supplied as the argument.\n\
		Note that -r and -R are incompatible.\n\
-z, --unresponsive-restart\n\
		When a daemon is unresponsive, treat it as being down for\n\
		restart purposes.\n\
-a, --all-restart\n\
		When zebra hangs or crashes, restart all daemons using\n\
		this phased approach: 1. stop all other daemons; 2. restart\n\
		zebra; 3. start other daemons.  Requires -r, -s, and -k.\n\
-A, --always-all-restart\n\
		When any daemon (not just zebra) hangs or crashes, use the\n\
		same phased restart mechanism described above for -a.\n\
		Requires -r, -s, and -k.\n\
-p, --pid-file	Set process identifier file name\n\
		(default is %s).\n\
-b, --blank-string\n\
		When the supplied argument string is found in any of the\n\
		various shell command arguments (-r, -s, -k, or -R), replace\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);

  return status;
}

static pid_t
run_background(const char *shell_cmd)
{
  pid_t child;

  switch (child = fork())
    {
    case -1:
      zlog_err("fork failed, cannot run command [%s]: %s",
	       shell_cmd,safe_strerror(errno));
      return -1;
    case 0:
      /* Child process. */
      /* Use separate process group so child processes can be killed easily. */
      if (setpgid(0,0) < 0)
        zlog_warn("warning: setpgid(0,0) failed: %s",safe_strerror(errno));
      {
        const char *argv[4] = { "sh", "-c", shell_cmd, NULL};
	execv("/bin/sh",(char *const *)argv);
	zlog_err("execv(/bin/sh -c '%s') failed: %s",
		 shell_cmd,safe_strerror(errno));
	_exit(127);
      }
    default:
      /* Parent process: we will reap the child later. */
      zlog_err("Forked background command [pid %d]: %s",(int)child,shell_cmd);
      return child;
    }
}

static struct timeval *
time_elapsed(struct timeval *result, const struct timeval *start_time)
{
  gettimeofday(result,NULL);
  result->tv_sec -= start_time->tv_sec;
  result->tv_usec -= start_time->tv_usec;
  while (result->tv_usec < 0)
    {
      result->tv_usec += 1000000L;
      result->tv_sec--;
    }
  return result;
}

static int
restart_kill(struct thread *t_kill)
{
  struct restart_info *restart = THREAD_ARG(t_kill);
  struct timeval delay;

  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, (long)delay.tv_sec,
	    (restart->kills ? SIGKILL : SIGTERM));
  kill(-restart->pid,(restart->kills ? SIGKILL : SIGTERM));
  restart->kills++;
  restart->t_kill = thread_add_timer(master,restart_kill,restart,
				     gs.restart_timeout);
  return 0;
}

static struct restart_info *
find_child(pid_t child)
{
  if (gs.mode == MODE_GLOBAL_RESTART)
    {
      if (gs.restart.pid == child)
        return &gs.restart;
    }
  else
    {
      struct daemon *dmn;
      for (dmn = gs.daemons; dmn; dmn = dmn->next)
        {
	  if (dmn->restart.pid == child)
	    return &dmn->restart;
        }
    }
  return NULL;
}

static void
sigchild(void)
{
  pid_t child;
  int status;
  const char *name;
  const char *what;
  struct restart_info *restart;

  switch (child = waitpid(-1,&status,WNOHANG)) 
    {
    case -1:
      zlog_err("waitpid failed: %s",safe_strerror(errno));
      return;
    case 0:
      zlog_warn("SIGCHLD received, but waitpid did not reap a child");
      return;
    }

  if ((restart = find_child(child)) != NULL)
    {
      name = restart->name;
      what = restart->what;
      restart->pid = 0;
      gs.numpids--;
      thread_cancel(restart->t_kill);
      restart->t_kill = NULL;
      /* Update restart time to reflect the time the command completed. */
      gettimeofday(&restart->time,NULL);
    }
  else
    {
      zlog_err("waitpid returned status for an unknown child process %d",
	       (int)child);
      name = "(unknown)";
      what = "background";
    }
  if (WIFSTOPPED(status))
      zlog_warn("warning: %s %s process %d is stopped",
		what,name,(int)child);
  else if (WIFSIGNALED(status))
    zlog_warn("%s %s process %d terminated due to signal %d",
	      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,(int)child,WEXITSTATUS(status));
      else
	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,(int)child,status);
  phase_check();
}

static int
run_job(struct restart_info *restart, const char *cmdtype, const char *command,
	int force, int update_interval)
{
  struct timeval delay;

  if (gs.loglevel > LOG_DEBUG+1)
    zlog_debug("attempting to %s %s",cmdtype,restart->name);

  if (restart->pid)
    {
      if (gs.loglevel > LOG_DEBUG+1)
        zlog_debug("cannot %s %s, previous pid %d still running",
		   cmdtype,restart->name,(int)restart->pid);
      return -1;
    }

  /* 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: "
		   "elapsed time %ld < retry interval %ld",
		   cmdtype,restart->name,(long)delay.tv_sec,restart->interval);
      return -1;
    }

  gettimeofday(&restart->time,NULL);
  restart->kills = 0;
  {
    char cmd[strlen(command)+strlen(restart->name)+1];
    snprintf(cmd,sizeof(cmd),command,restart->name);
    if ((restart->pid = run_background(cmd)) > 0)
      {
	restart->t_kill = thread_add_timer(master,restart_kill,restart,
					   gs.restart_timeout);
	restart->what = cmdtype;
	gs.numpids++;
      }
    else
      restart->pid = 0;
  }

  /* Calculate the new restart interval. */
  if (update_interval)
    {
      if (delay.tv_sec > 2*gs.max_restart_interval)
	restart->interval = gs.min_restart_interval;
      else if ((restart->interval *= 2) > gs.max_restart_interval)
	restart->interval = gs.max_restart_interval;
      if (gs.loglevel > LOG_DEBUG+1)
	zlog_debug("restart %s interval is now %ld",
		   restart->name,restart->interval);
    }
  return restart->pid;
}

#define SET_READ_HANDLER(DMN) \
  (DMN)->t_read = thread_add_read(master,handle_read,(DMN),(DMN)->fd)

#define SET_WAKEUP_DOWN(DMN)	\
  (DMN)->t_wakeup = thread_add_timer_msec(master,wakeup_down,(DMN),	\
    					  FUZZY(gs.period))

#define SET_WAKEUP_UNRESPONSIVE(DMN)	\
  (DMN)->t_wakeup = thread_add_timer_msec(master,wakeup_unresponsive,(DMN), \
    					  FUZZY(gs.period))

#define SET_WAKEUP_ECHO(DMN) \
  (DMN)->t_wakeup = thread_add_timer_msec(master,wakeup_send_echo,(DMN), \
					  FUZZY(gs.period))

static int
wakeup_down(struct thread *t_wakeup)
{
  struct daemon *dmn = THREAD_ARG(t_wakeup);

  dmn->t_wakeup = NULL;
  if (try_connect(dmn) < 0)
    SET_WAKEUP_DOWN(dmn);
  if ((dmn->connect_tries > 1) && (dmn->state != DAEMON_UP))
    try_restart(dmn);
  return 0;
}

static int
wakeup_init(struct thread *t_wakeup)
{
  struct daemon *dmn = THREAD_ARG(t_wakeup);

  dmn->t_wakeup = NULL;
  if (try_connect(dmn) < 0)
    {
      SET_WAKEUP_DOWN(dmn);
      zlog_err("%s state -> down : initial connection attempt failed",
	       dmn->name);
      dmn->state = DAEMON_DOWN;
    }
  return 0;
}

static void
daemon_down(struct daemon *dmn, const char *why)
{
  if (IS_UP(dmn) || (dmn->state == DAEMON_INIT))
    zlog_err("%s state -> down : %s",dmn->name,why);
  else if (gs.loglevel > LOG_DEBUG)
    zlog_debug("%s still down : %s",dmn->name,why);
  if (IS_UP(dmn))
    gs.numdown++;
  dmn->state = DAEMON_DOWN;
  if (dmn->fd >= 0)
    {
      close(dmn->fd);
      dmn->fd = -1;
    }
  THREAD_OFF(dmn->t_read);
  THREAD_OFF(dmn->t_write);
  THREAD_OFF(dmn->t_wakeup);
  if (try_connect(dmn) < 0)
    SET_WAKEUP_DOWN(dmn);
  phase_check();
}

static int
handle_read(struct thread *t_read)
{
  struct daemon *dmn = THREAD_ARG(t_read);
  static const char resp[sizeof(PING_TOKEN)+4] = PING_TOKEN "\n";
  char buf[sizeof(resp)+100];
  ssize_t rc;
  struct timeval delay;

  dmn->t_read = NULL;
  if ((rc = read(dmn->fd,buf,sizeof(buf))) < 0)
    {
      char why[100];

      if (ERRNO_IO_RETRY(errno))
	{
	  /* Pretend it never happened. */
	  SET_READ_HANDLER(dmn);
	  return 0;
	}
      snprintf(why,sizeof(why),"unexpected read error: %s",
	       safe_strerror(errno));
      daemon_down(dmn,why);
      return 0;
    }
  if (rc == 0)
    {
      daemon_down(dmn,"read returned EOF");
      return 0;
    }
  if (!dmn->echo_sent.tv_sec)
    {
      char why[sizeof(buf)+100];
      snprintf(why,sizeof(why),"unexpected read returns %d bytes: %.*s",
	       (int)rc,(int)rc,buf);
      daemon_down(dmn,why);
      return 0;
    }

  /* We are expecting an echo response: is there any chance that the
     response would not be returned entirely in the first read?  That
     seems inconceivable... */
  if ((rc != sizeof(resp)) || memcmp(buf,resp,sizeof(resp)))
    {
      char why[100+sizeof(buf)];
      snprintf(why,sizeof(why),"read returned bad echo response of %d bytes "
			       "(expecting %u): %.*s",
	       (int)rc,(u_int)sizeof(resp),(int)rc,buf);
      daemon_down(dmn,why);
      return 0;
    }

  time_elapsed(&delay,&dmn->echo_sent);
  dmn->echo_sent.tv_sec = 0;
  if (dmn->state == DAEMON_UNRESPONSIVE)
    {
      if (delay.tv_sec < gs.timeout)
	{
	  dmn->state = DAEMON_UP;
	  zlog_warn("%s state -> up : echo response received after %ld.%06ld "
		    "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,
		  (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, (long)delay.tv_sec, (long)delay.tv_usec);

  SET_READ_HANDLER(dmn);
  if (dmn->t_wakeup)
    thread_cancel(dmn->t_wakeup);
  SET_WAKEUP_ECHO(dmn);

  return 0;
}

static void
daemon_up(struct daemon *dmn, const char *why)
{
  dmn->state = DAEMON_UP;
  gs.numdown--;
  dmn->connect_tries = 0;
  zlog_notice("%s state -> up : %s",dmn->name,why);
  if (gs.do_ping)
    SET_WAKEUP_ECHO(dmn);
  phase_check();
}

static int
check_connect(struct thread *t_write)
{
  struct daemon *dmn = THREAD_ARG(t_write);
  int sockerr;
  socklen_t reslen = sizeof(sockerr);

  dmn->t_write = NULL;
  if (getsockopt(dmn->fd,SOL_SOCKET,SO_ERROR,(char *)&sockerr,&reslen) < 0)
    {
      zlog_warn("%s: check_connect: getsockopt failed: %s",
	        dmn->name,safe_strerror(errno));
      daemon_down(dmn,"getsockopt failed checking connection success");
      return 0;
    }
  if ((reslen == sizeof(sockerr)) && sockerr)
    {
      char why[100];
      snprintf(why,sizeof(why),
	       "getsockopt reports that connection attempt failed: %s",
	       safe_strerror(sockerr));
      daemon_down(dmn,why);
      return 0;
    }

  daemon_up(dmn,"delayed connect succeeded");
  return 0;
}

static int
wakeup_connect_hanging(struct thread *t_wakeup)
{
  struct daemon *dmn = THREAD_ARG(t_wakeup);
  char why[100];

  dmn->t_wakeup = NULL;
  snprintf(why,sizeof(why),"connection attempt timed out after %ld seconds",
	   gs.timeout);
  daemon_down(dmn,why);
  return 0;
}

/* Making connection to protocol daemon. */
static int
try_connect(struct daemon *dmn)
{
  int sock;
  struct sockaddr_un addr;
  socklen_t len;

  if (gs.loglevel > LOG_DEBUG+1)
    zlog_debug("%s: attempting to connect",dmn->name);
  dmn->connect_tries++;

  memset (&addr, 0, sizeof (struct sockaddr_un));
  addr.sun_family = AF_UNIX;
  snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s.vty",
	   gs.vtydir,dmn->name);
#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_STRUCT_SOCKADDR_UN_SUN_LEN */

  /* Quick check to see if we might succeed before we go to the trouble
     of creating a socket. */
  if (access(addr.sun_path, W_OK) < 0)
    {
      if (errno != ENOENT)
        zlog_err("%s: access to socket %s denied: %s",
		dmn->name,addr.sun_path,safe_strerror(errno));
      return -1;
    }

  if ((sock = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
    {
      zlog_err("%s(%s): cannot make socket: %s",
	       __func__,addr.sun_path, safe_strerror(errno));
      return -1;
    }

  if (set_nonblocking(sock) < 0)
    {
      zlog_err("%s(%s): set_nonblocking(%d) failed",
	       __func__, addr.sun_path, sock);
      close(sock);
      return -1;
    }

  if (connect (sock, (struct sockaddr *) &addr, len) < 0)
    {
      if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK))
	{
	  if (gs.loglevel > LOG_DEBUG)
	    zlog_debug("%s(%s): connect failed: %s",
		       __func__,addr.sun_path, safe_strerror(errno));
	  close (sock);
	  return -1;
	}
      if (gs.loglevel > LOG_DEBUG)
	zlog_debug("%s: connection in progress",dmn->name);
      dmn->state = DAEMON_CONNECTING;
      dmn->fd = sock;
      dmn->t_write = thread_add_write(master,check_connect,dmn,dmn->fd);
      dmn->t_wakeup = thread_add_timer(master,wakeup_connect_hanging,dmn,
				       gs.timeout);
      SET_READ_HANDLER(dmn);
      return 0;
    }

  dmn->fd = sock;
  SET_READ_HANDLER(dmn);
  daemon_up(dmn,"connect succeeded");
  return 1;
}

static int
phase_hanging(struct thread *t_hanging)
{
  gs.t_phase_hanging = NULL;
  zlog_err("Phase [%s] hanging for %ld seconds, aborting phased restart",
           phase_str[gs.phase],PHASE_TIMEOUT);
  gs.phase = PHASE_NONE;
  return 0;
}

static void
set_phase(restart_phase_t new_phase)
{
  gs.phase = new_phase;
  if (gs.t_phase_hanging)
    thread_cancel(gs.t_phase_hanging);
  gs.t_phase_hanging = thread_add_timer(master,phase_hanging,NULL,
  					PHASE_TIMEOUT);
}

static void
phase_check(void)
{
  switch (gs.phase)
    {
    case PHASE_NONE:
      break;
    case PHASE_STOPS_PENDING:
      if (gs.numpids)
	break;
      zlog_info("Phased restart: all routing daemon stop jobs have completed.");
      set_phase(PHASE_WAITING_DOWN);
      /*FALLTHRU*/
    case PHASE_WAITING_DOWN:
      if (gs.numdown+IS_UP(gs.special) < gs.numdaemons)
        break;
      zlog_info("Phased restart: all routing daemons now down.");
      run_job(&gs.special->restart,"restart",gs.restart_command,1,1);
      set_phase(PHASE_ZEBRA_RESTART_PENDING);
      /*FALLTHRU*/
    case PHASE_ZEBRA_RESTART_PENDING:
      if (gs.special->restart.pid)
	break;
      zlog_info("Phased restart: %s restart job completed.",gs.special->name);
      set_phase(PHASE_WAITING_ZEBRA_UP);
      /*FALLTHRU*/
    case PHASE_WAITING_ZEBRA_UP:
      if (!IS_UP(gs.special))
        break;
      zlog_info("Phased restart: %s is now up.",gs.special->name);
      {
        struct daemon *dmn;
	for (dmn = gs.daemons; dmn; dmn = dmn->next)
	  {
	    if (dmn != gs.special)
	      run_job(&dmn->restart,"start",gs.start_command,1,0);
	  }
      }
      gs.phase = PHASE_NONE;
      THREAD_OFF(gs.t_phase_hanging);
      zlog_notice("Phased global restart has completed.");
      break;
    }
}

static void
try_restart(struct daemon *dmn)
{
  switch (gs.mode)
  {
  case MODE_MONITOR:
    return;
  case MODE_GLOBAL_RESTART:
    run_job(&gs.restart,"restart",gs.restart_command,0,1);
    break;
  case MODE_SEPARATE_RESTART:
    run_job(&dmn->restart,"restart",gs.restart_command,0,1);
    break;
  case MODE_PHASED_ZEBRA_RESTART:
    if (dmn != gs.special)
      {
        if ((gs.special->state == DAEMON_UP) && (gs.phase == PHASE_NONE))
	  run_job(&dmn->restart,"restart",gs.restart_command,0,1);
	else
	  zlog_debug("%s: postponing restart attempt because master %s daemon "
		     "not up [%s], or phased restart in progress",
		     dmn->name,gs.special->name,state_str[gs.special->state]);
	break;
      }
    /*FALLTHRU*/
  case MODE_PHASED_ALL_RESTART:
    if ((gs.phase != PHASE_NONE) || gs.numpids)
      {
	if (gs.loglevel > LOG_DEBUG+1)
	  zlog_debug("postponing phased global restart: restart already in "
		     "progress [%s], or outstanding child processes [%d]",
		     phase_str[gs.phase],gs.numpids);
        break;
      }
    /* Is it too soon for a restart? */
    {
      struct timeval delay;
      if (time_elapsed(&delay,&gs.special->restart.time)->tv_sec <
      	  gs.special->restart.interval)
	{
	  if (gs.loglevel > LOG_DEBUG+1)
	    zlog_debug("postponing phased global restart: "
		       "elapsed time %ld < retry interval %ld",
		       (long)delay.tv_sec,gs.special->restart.interval);
	  break;
	}
    }
    zlog_info("Phased restart: stopping all routing daemons.");
    /* First step: stop all other daemons. */
    for (dmn = gs.daemons; dmn; dmn = dmn->next)
      {
        if (dmn != gs.special)
	  run_job(&dmn->restart,"stop",gs.stop_command,1,1);
      }
    set_phase(PHASE_STOPS_PENDING);
    break;
  default:
    zlog_err("error: unknown restart mode %d",gs.mode);
    break;
  }
}

static int
wakeup_unresponsive(struct thread *t_wakeup)
{
  struct daemon *dmn = THREAD_ARG(t_wakeup);

  dmn->t_wakeup = NULL;
  if (dmn->state != DAEMON_UNRESPONSIVE)
    zlog_err("%s: no longer unresponsive (now %s), "
	     "wakeup should have been cancelled!",
	     dmn->name,state_str[dmn->state]);
  else
    {
      SET_WAKEUP_UNRESPONSIVE(dmn);
      try_restart(dmn);
    }
  return 0;
}

static int
wakeup_no_answer(struct thread *t_wakeup)
{
  struct daemon *dmn = THREAD_ARG(t_wakeup);

  dmn->t_wakeup = NULL;
  dmn->state = DAEMON_UNRESPONSIVE;
  zlog_err("%s state -> unresponsive : no response yet to ping "
	   "sent %ld seconds ago",dmn->name,gs.timeout);
  if (gs.unresponsive_restart)
    {
      SET_WAKEUP_UNRESPONSIVE(dmn);
      try_restart(dmn);
    }
  return 0;
}

static int
wakeup_send_echo(struct thread *t_wakeup)
{
  static const char echocmd[] = "echo " PING_TOKEN;
  ssize_t rc;
  struct daemon *dmn = THREAD_ARG(t_wakeup);

  dmn->t_wakeup = NULL;
  if (((rc = write(dmn->fd,echocmd,sizeof(echocmd))) < 0) ||
      ((size_t)rc != sizeof(echocmd)))
    {
      char why[100+sizeof(echocmd)];
      snprintf(why,sizeof(why),"write '%s' returned %d instead of %u",
               echocmd,(int)rc,(u_int)sizeof(echocmd));
      daemon_down(dmn,why);
    }
  else
    {
      gettimeofday(&dmn->echo_sent,NULL);
      dmn->t_wakeup = thread_add_timer(master,wakeup_no_answer,dmn,gs.timeout);
    }
  return 0;
}

static void
sigint(void)
{
  zlog_notice("Terminating on signal");
  exit(0);
}

static int
valid_command(const char *cmd)
{
  char *p;

  return ((p = strchr(cmd,'%')) != NULL) && (*(p+1) == 's') && !strchr(p+1,'%');
}

/* This is an ugly hack to circumvent problems with passing command-line
   arguments that contain spaces.  The fix is to use a configuration file. */
static char *
translate_blanks(const char *cmd, const char *blankstr)
{
  char *res;
  char *p;
  size_t bslen = strlen(blankstr);

  if (!(res = strdup(cmd)))
    {
      perror("strdup");
      exit(1);
    }
  while ((p = strstr(res,blankstr)) != NULL)
    {
      *p = ' ';
      if (bslen != 1)
	 memmove(p+1,p+bslen,strlen(p+bslen)+1);
    }
  return res;
}

int
main(int argc, char **argv)
{
  const char *progname;
  int opt;
  int daemon_mode = 0;
  const char *pidfile = DEFAULT_PIDFILE;
  const char *special = "zebra";
  const char *blankstr = NULL;
  static struct quagga_signal_t my_signals[] =
  {
    {
      .signal = SIGINT,
      .handler = sigint,
    },
    {
      .signal = SIGTERM,
      .handler = sigint,
    },
    {
      .signal = SIGCHLD,
      .handler = sigchild,
    },
  };

  if ((progname = strrchr (argv[0], '/')) != NULL)
    progname++;
  else
    progname = argv[0];

  gs.restart.name = "all";
  while ((opt = getopt_long(argc, argv, "aAb:dek:l:m:M:i:p:r:R:S:s:t:T:zvh",
			    longopts, 0)) != EOF)
    {
      switch (opt)
        {
	case 0:
	  break;
        case 'a':
	  if ((gs.mode != MODE_MONITOR) && (gs.mode != MODE_SEPARATE_RESTART))
	    {
	      fputs("Ambiguous operating mode selected.\n",stderr);
	      return usage(progname,1);
	    }
	  gs.mode = MODE_PHASED_ZEBRA_RESTART;
	  break;
        case 'A':
	  if ((gs.mode != MODE_MONITOR) && (gs.mode != MODE_SEPARATE_RESTART))
	    {
	      fputs("Ambiguous operating mode selected.\n",stderr);
	      return usage(progname,1);
	    }
	  gs.mode = MODE_PHASED_ALL_RESTART;
	  break;
	case 'b':
	  blankstr = optarg;
	  break;
        case 'd':
	  daemon_mode = 1;
	  break;
        case 'e':
	  gs.do_ping = 0;
	  break;
        case 'k':
	  if (!valid_command(optarg))
	  {
	    fprintf(stderr,"Invalid kill command, must contain '%%s': %s\n",
		    optarg);
	    return usage(progname,1);
	  }
	  gs.stop_command = optarg;
	  break;
	case 'l':
	  {
	    char garbage[3];
	    if ((sscanf(optarg,"%d%1s",&gs.loglevel,garbage) != 1) ||
	        (gs.loglevel < LOG_EMERG))
	      {
	        fprintf(stderr,"Invalid loglevel argument: %s\n",optarg);
		return usage(progname,1);
	      }
	  }
	  break;
	case 'm':
	  {
	    char garbage[3];
	    if ((sscanf(optarg,"%ld%1s",
	    		&gs.min_restart_interval,garbage) != 1) ||
	        (gs.min_restart_interval < 0))
	      {
	        fprintf(stderr,"Invalid min_restart_interval argument: %s\n",
		        optarg);
		return usage(progname,1);
	      }
	  }
	  break;
	case 'M':
	  {
	    char garbage[3];
	    if ((sscanf(optarg,"%ld%1s",
	    		&gs.max_restart_interval,garbage) != 1) ||
	        (gs.max_restart_interval < 0))
	      {
	        fprintf(stderr,"Invalid max_restart_interval argument: %s\n",
		        optarg);
		return usage(progname,1);
	      }
	  }
	  break;
	case 'i':
	  {
	    char garbage[3];
	    int period;
	    if ((sscanf(optarg,"%d%1s",&period,garbage) != 1) ||
	        (gs.period < 1))
	      {
	        fprintf(stderr,"Invalid interval argument: %s\n",optarg);
		return usage(progname,1);
	      }
	    gs.period = 1000*period;
	  }
	  break;
        case 'p':
	  pidfile = optarg;
	  break;
        case 'r':
	  if ((gs.mode == MODE_GLOBAL_RESTART) ||
	      (gs.mode == MODE_SEPARATE_RESTART))
	    {
	      fputs("Ambiguous operating mode selected.\n",stderr);
	      return usage(progname,1);
	    }
	  if (!valid_command(optarg))
	  {
	    fprintf(stderr,
		    "Invalid restart command, must contain '%%s': %s\n",
		    optarg);
	    return usage(progname,1);
	  }
	  gs.restart_command = optarg;
	  if (gs.mode == MODE_MONITOR)
	    gs.mode = MODE_SEPARATE_RESTART;
	  break;
        case 'R':
	  if (gs.mode != MODE_MONITOR)
	    {
	      fputs("Ambiguous operating mode selected.\n",stderr);
	      return usage(progname,1);
	    }
	  if (strchr(optarg,'%'))
	    {
	      fprintf(stderr,
		      "Invalid restart-all arg, must not contain '%%s': %s\n",
		      optarg);
	      return usage(progname,1);
	    }
	  gs.restart_command = optarg;
	  gs.mode = MODE_GLOBAL_RESTART;
	  break;
        case 's':
	  if (!valid_command(optarg))
	  {
	    fprintf(stderr,"Invalid start command, must contain '%%s': %s\n",
		    optarg);
	    return usage(progname,1);
	  }
	  gs.start_command = optarg;
	  break;
	case 'S':
	  gs.vtydir = optarg;
	  break;
	case 't':
	  {
	    char garbage[3];
	    if ((sscanf(optarg,"%ld%1s",&gs.timeout,garbage) != 1) ||
	        (gs.timeout < 1))
	      {
	        fprintf(stderr,"Invalid timeout argument: %s\n",optarg);
		return usage(progname,1);
	      }
	  }
	  break;
	case 'T':
	  {
	    char garbage[3];
	    if ((sscanf(optarg,"%ld%1s",&gs.restart_timeout,garbage) != 1) ||
	        (gs.restart_timeout < 1))
	      {
	        fprintf(stderr,"Invalid restart timeout argument: %s\n",optarg);
		return usage(progname,1);
	      }
	  }
	  break;
        case 'z':
	  gs.unresponsive_restart = 1;
	  break;
	case 'v':
	  printf ("%s version %s\n", progname, QUAGGA_VERSION);
	  puts("Copyright 2004 Andrew J. Schorr");
	  return 0;
        case 'h':
	  return usage(progname,0);
        default:
	  fputs("Invalid option.\n",stderr);
	  return usage(progname,1);
        }
    }
  
  if (gs.unresponsive_restart && (gs.mode == MODE_MONITOR))
    {
      fputs("Option -z requires a -r or -R restart option.\n",stderr);
      return usage(progname,1);
    }
  switch (gs.mode)
    {
    case MODE_MONITOR:
      if (gs.restart_command || gs.start_command || gs.stop_command)
        {
	  fprintf(stderr,"No kill/(re)start commands needed for %s mode.\n",
		  mode_str[gs.mode]);
	  return usage(progname,1);
	}
      break;
    case MODE_GLOBAL_RESTART:
    case MODE_SEPARATE_RESTART:
      if (!gs.restart_command || gs.start_command || gs.stop_command)
        {
	  fprintf(stderr,"No start/kill commands needed in [%s] mode.\n",
		  mode_str[gs.mode]);
	  return usage(progname,1);
	}
      break;
    case MODE_PHASED_ZEBRA_RESTART:
    case MODE_PHASED_ALL_RESTART:
      if (!gs.restart_command || !gs.start_command || !gs.stop_command)
        {
	  fprintf(stderr,
	  	  "Need start, kill, and restart commands in [%s] mode.\n",
		  mode_str[gs.mode]);
	  return usage(progname,1);
	}
      break;
    }

  if (blankstr)
    {
      if (gs.restart_command)
        gs.restart_command = translate_blanks(gs.restart_command,blankstr);
      if (gs.start_command)
        gs.start_command = translate_blanks(gs.start_command,blankstr);
      if (gs.stop_command)
        gs.stop_command = translate_blanks(gs.stop_command,blankstr);
    }
      
  gs.restart.interval = gs.min_restart_interval;
  master = thread_master_create();
  signal_init (master, array_size(my_signals), my_signals);
  srandom(time(NULL));

  {
    int i;
    struct daemon *tail = NULL;

    for (i = optind; i < argc; i++)
      {
	struct daemon *dmn;

	if (!(dmn = (struct daemon *)calloc(1,sizeof(*dmn))))
	  {
	    fprintf(stderr,"calloc(1,%u) failed: %s\n",
		    (u_int)sizeof(*dmn), safe_strerror(errno));
	    return 1;
	  }
	dmn->name = dmn->restart.name = argv[i];
	dmn->state = DAEMON_INIT;
	gs.numdaemons++;
	gs.numdown++;
	dmn->fd = -1;
	dmn->t_wakeup = thread_add_timer_msec(master,wakeup_init,dmn,
					      100+(random() % 900));
	dmn->restart.interval = gs.min_restart_interval;
	if (tail)
	  tail->next = dmn;
	else
	  gs.daemons = dmn;
	tail = dmn;

	if (((gs.mode == MODE_PHASED_ZEBRA_RESTART) ||
	     (gs.mode == MODE_PHASED_ALL_RESTART)) &&
	    !strcmp(dmn->name,special))
	  gs.special = dmn;
      }
  }
  if (!gs.daemons)
    {
      fputs("Must specify one or more daemons to monitor.\n",stderr);
      return usage(progname,1);
    }
  if (((gs.mode == MODE_PHASED_ZEBRA_RESTART) ||
      (gs.mode == MODE_PHASED_ALL_RESTART)) && !gs.special)
    {
      fprintf(stderr,"In mode [%s], but cannot find master daemon %s\n",
	      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,
			  LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
  zlog_set_level(NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
  if (daemon_mode)
    {
      zlog_set_level(NULL, ZLOG_DEST_SYSLOG, MIN(gs.loglevel,LOG_DEBUG));
      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));

  /* Make sure we're not already running. */
  pid_output (pidfile);

  /* Announce which daemons are being monitored. */
  {
    struct daemon *dmn;
    size_t len = 0;

    for (dmn = gs.daemons; dmn; dmn = dmn->next)
      len += strlen(dmn->name)+1;

    {
      char buf[len+1];
      char *p = buf;

      for (dmn = gs.daemons; dmn; dmn = dmn->next)
	{
	  if (p != buf)
	    *p++ = ' ';
	  strcpy(p,dmn->name);
	  p += strlen(p);
	}
      zlog_notice("%s %s watching [%s], mode [%s]",
      		  progname, QUAGGA_VERSION, buf, mode_str[gs.mode]);
    }
  }

  {
    struct thread thread;

    while (thread_fetch (master, &thread))
      thread_call (&thread);
  }

  /* Not reached. */
  return 0;
}
