From: David Lamparter Date: Fri, 30 Nov 2018 16:56:04 +0000 (+0100) Subject: watchfrr: immediately try connecting after start X-Git-Tag: frr-7.1-dev~111^2~4 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=75f8b0e41b500b02675222515f3173c4effebdfe;p=matthieu%2Ffrr.git watchfrr: immediately try connecting after start When we make a call to (re)start some daemon(s), we can immediately try connecting to its VTY socket after the script completes. If the daemon started correctly, this will always succeed since the start script only returns after daemon startup is complete. Among other things, this reduces the delay to "startup complete" notification at initial watchfrr start. Signed-off-by: David Lamparter --- diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index 95fa6c4aec..35a633b158 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -179,6 +179,7 @@ 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 void restart_done(struct daemon *dmn); static const char *progname; static void printhelp(FILE *target) @@ -335,6 +336,7 @@ static void sigchild(void) const char *name; const char *what; struct restart_info *restart; + struct daemon *dmn; switch (child = waitpid(-1, &status, WNOHANG)) { case -1: @@ -380,9 +382,18 @@ static void sigchild(void) zlog_warn( "%s %s process %d exited with non-zero status %d", what, name, (int)child, WEXITSTATUS(status)); - else + else { zlog_debug("%s %s process %d exited normally", what, name, (int)child); + + if (restart && restart != &gs.restart) { + dmn = container_of(restart, struct daemon, + restart); + restart_done(dmn); + } else if (restart) + for (dmn = gs.daemons; dmn; dmn = dmn->next) + restart_done(dmn); + } } else flog_err_sys( EC_LIB_SYSTEM_CALL, @@ -505,6 +516,18 @@ static int wakeup_init(struct thread *t_wakeup) return 0; } +static void restart_done(struct daemon *dmn) +{ + if (dmn->state != DAEMON_DOWN) { + zlog_warn("wtf?"); + return; + } + if (dmn->t_wakeup) + THREAD_OFF(dmn->t_wakeup); + if (try_connect(dmn) < 0) + SET_WAKEUP_DOWN(dmn); +} + static void daemon_down(struct daemon *dmn, const char *why) { if (IS_UP(dmn) || (dmn->state == DAEMON_INIT))