]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: mgmtd: fix too early daemon detach of mgmtd
authorChristian Hopps <chopps@labn.net>
Tue, 23 Jul 2024 21:42:07 +0000 (17:42 -0400)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Wed, 24 Jul 2024 14:23:34 +0000 (14:23 +0000)
Correct FRR startup counts on a daemon's vty socket to be open when the
parent process exits. The parent process waits for `frr_check_detach()`
to be called by the child before exiting. The problem is when the
`FRR_MANUAL_VTY_START` flag is set the vty socket was not opened but
`frr_check_detach()` was called anyway.

Instead add a bool option for `frr_check_detach()` to be called when the
socket is opened with `frr_vty_serv_start()`, and do so when "manually"
calling said function (i.e., when FRR_MANUAL_VTY_START is set).

The `FRR_MANUAL_VTY_START` flag is only set by mgmtd. The reason we
wait to open the vty socket is so that mgmtd can parse the various
daemon specific config files it has taken over, after the event loop has
started, but before we receive any possible new config from `vtysh`.

fixes #16362

Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit be9a6fc0ea8180a4aaa558c5402ea543427e2e7e)

lib/libfrr.c
lib/libfrr.h
lib/vty.c

index 876efe23a826d5a36879e9a1a3a65b743595ada5..cc60cfb829db51b6a34fd3049e2b3672c6cec0f2 100644 (file)
@@ -1040,7 +1040,17 @@ void frr_config_fork(void)
        zlog_tls_buffer_init();
 }
 
-void frr_vty_serv_start(void)
+static void frr_check_detach(void)
+{
+       if (nodetach_term || nodetach_daemon)
+               return;
+
+       if (daemon_ctl_sock != -1)
+               close(daemon_ctl_sock);
+       daemon_ctl_sock = -1;
+}
+
+void frr_vty_serv_start(bool check_detach)
 {
        /* allow explicit override of vty_path in the future
         * (not currently set anywhere) */
@@ -1063,6 +1073,9 @@ void frr_vty_serv_start(void)
        }
 
        vty_serv_start(di->vty_addr, di->vty_port, di->vty_path);
+
+       if (check_detach)
+               frr_check_detach();
 }
 
 void frr_vty_serv_stop(void)
@@ -1073,16 +1086,6 @@ void frr_vty_serv_stop(void)
                unlink(di->vty_path);
 }
 
-static void frr_check_detach(void)
-{
-       if (nodetach_term || nodetach_daemon)
-               return;
-
-       if (daemon_ctl_sock != -1)
-               close(daemon_ctl_sock);
-       daemon_ctl_sock = -1;
-}
-
 static void frr_terminal_close(int isexit)
 {
        int nullfd;
@@ -1168,7 +1171,7 @@ void frr_run(struct event_loop *master)
        char instanceinfo[64] = "";
 
        if (!(di->flags & FRR_MANUAL_VTY_START))
-               frr_vty_serv_start();
+               frr_vty_serv_start(false);
 
        if (di->instance)
                snprintf(instanceinfo, sizeof(instanceinfo), "instance %u ",
@@ -1206,7 +1209,8 @@ void frr_run(struct event_loop *master)
                        close(nullfd);
                }
 
-               frr_check_detach();
+               if (!(di->flags & FRR_MANUAL_VTY_START))
+                       frr_check_detach();
        }
 
        /* end fixed stderr startup logging */
index 77d70448a9a10c5ed0c8d2c0311c6ab022af1149..d52ee9aefe3b77cbf6ec862864c8f9aef24e5e40 100644 (file)
@@ -200,7 +200,7 @@ extern void frr_config_fork(void);
 
 extern void frr_run(struct event_loop *master);
 extern void frr_detach(void);
-extern void frr_vty_serv_start(void);
+extern void frr_vty_serv_start(bool check_detach);
 extern void frr_vty_serv_stop(void);
 
 extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
index ecb5383a53b2f67471eee6cd61a1b5e818f9a68b..d0bbf0e61a5c43249c3aec78e282fe0aaa0949ec 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -3502,7 +3502,7 @@ static void vty_mgmt_server_connected(struct mgmt_fe_client *client,
 
        /* Start or stop listening for vty connections */
        if (connected)
-               frr_vty_serv_start();
+               frr_vty_serv_start(true);
        else
                frr_vty_serv_stop();
 }