Merge pull request #16451 from LabNConsulting/chopps/fix-early-mgmtd-detach

lib: mgmtd: fix too early daemon detach of mgmtd
This commit is contained in:
Donald Sharp 2024-07-24 10:22:53 -04:00 committed by GitHub
commit 5bb0b01e34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 15 deletions

View File

@ -1051,7 +1051,17 @@ void frr_config_fork(void)
zlog_tls_buffer_init(); 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 /* allow explicit override of vty_path in the future
* (not currently set anywhere) */ * (not currently set anywhere) */
@ -1074,6 +1084,9 @@ void frr_vty_serv_start(void)
} }
vty_serv_start(di->vty_addr, di->vty_port, di->vty_path); vty_serv_start(di->vty_addr, di->vty_port, di->vty_path);
if (check_detach)
frr_check_detach();
} }
void frr_vty_serv_stop(void) void frr_vty_serv_stop(void)
@ -1084,16 +1097,6 @@ void frr_vty_serv_stop(void)
unlink(di->vty_path); 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) static void frr_terminal_close(int isexit)
{ {
int nullfd; int nullfd;
@ -1179,7 +1182,7 @@ void frr_run(struct event_loop *master)
char instanceinfo[64] = ""; char instanceinfo[64] = "";
if (!(di->flags & FRR_MANUAL_VTY_START)) if (!(di->flags & FRR_MANUAL_VTY_START))
frr_vty_serv_start(); frr_vty_serv_start(false);
if (di->instance) if (di->instance)
snprintf(instanceinfo, sizeof(instanceinfo), "instance %u ", snprintf(instanceinfo, sizeof(instanceinfo), "instance %u ",
@ -1217,7 +1220,8 @@ void frr_run(struct event_loop *master)
close(nullfd); close(nullfd);
} }
frr_check_detach(); if (!(di->flags & FRR_MANUAL_VTY_START))
frr_check_detach();
} }
/* end fixed stderr startup logging */ /* end fixed stderr startup logging */

View File

@ -202,7 +202,7 @@ extern void frr_config_fork(void);
extern void frr_run(struct event_loop *master); extern void frr_run(struct event_loop *master);
extern void frr_detach(void); 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 void frr_vty_serv_stop(void);
extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len, extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,

View File

@ -3502,7 +3502,7 @@ static void vty_mgmt_server_connected(struct mgmt_fe_client *client,
/* Start or stop listening for vty connections */ /* Start or stop listening for vty connections */
if (connected) if (connected)
frr_vty_serv_start(); frr_vty_serv_start(true);
else else
frr_vty_serv_stop(); frr_vty_serv_stop();
} }