]> git.puffer.fish Git - matthieu/frr.git/commitdiff
mgmtd: fix possible race btw read config and backend connection
authorChristian Hopps <chopps@labn.net>
Tue, 30 May 2023 15:52:19 +0000 (11:52 -0400)
committerChristian Hopps <chopps@labn.net>
Tue, 30 May 2023 15:52:19 +0000 (11:52 -0400)
Signed-off-by: Christian Hopps <chopps@labn.net>
mgmtd/mgmt.c
mgmtd/mgmt_vty.c

index 29d35fe02f5fcbdb48af0256cbfe2ba0c7a51f56..77c4473e49f10cb849101f490dffbf6179c6f64c 100644 (file)
@@ -49,20 +49,22 @@ void mgmt_init(void)
        /* Initialize MGMTD Transaction module */
        mgmt_txn_init(mm, mm->master);
 
-       /* Initialize the MGMTD Backend Adapter Module */
-       mgmt_be_adapter_init(mm->master);
-
        /* Initialize the MGMTD Frontend Adapter Module */
        mgmt_fe_adapter_init(mm->master);
 
-       /*
-        * Allocates some vital data structures used by peer commands in
-        * vty_init
-        */
+       /* Initialize the CLI frontend client */
        vty_init_mgmt_fe();
 
        /* MGMTD VTY commands installation. */
        mgmt_vty_init();
+
+       /*
+        * Initialize the MGMTD Backend Adapter Module
+        *
+        * We do this after the FE stuff so that we always read our config file
+        * prior to any BE connection.
+        */
+       mgmt_be_adapter_init(mm->master);
 }
 
 void mgmt_terminate(void)
index 5cb172f3c93adebaf9f66d6ef45e5a109e69f72f..93c5145d712e20726e21db6c018f5affadbb6b68 100644 (file)
@@ -454,44 +454,11 @@ DEFPY(debug_mgmt, debug_mgmt_cmd,
        return CMD_SUCCESS;
 }
 
-/*
- * We need an event driven file reader for reading in config files.
- */
-
 static void mgmt_config_read_in(struct event *event)
 {
        mgmt_vty_read_configs();
 }
 
-#if 0
-/*
- * Analog of `frr_config_read_in()`, instead of our config file though we loop
- * over all daemons that have transitioned to mgmtd, loading their configs
- */
-static int mgmt_config_pre_hook(struct event_loop *loop)
-{
-       FILE *confp;
-       char *p;
-
-       for (uint i = 0; i < mgmt_daemons_count; i++) {
-               p = asprintfrr(MTYPE_TMP, "%s/%s.conf", frr_sysconfdir,
-                              mgmt_daemons[i]);
-               confp = fopen(p, "r");
-               if (confp == NULL) {
-                       if (errno != ENOENT)
-                               zlog_err("%s: couldn't read config file %s: %s",
-                                        __func__, p, safe_strerror(errno));
-               } else {
-                       zlog_info("mgmtd: reading daemon config from %s", p);
-                       vty_read_file(vty_shared_candidate_config, confp);
-                       fclose(confp);
-               }
-               XFREE(MTYPE_TMP, p);
-       }
-       return 0;
-}
-#endif
-
 void mgmt_vty_init(void)
 {
        /*
@@ -505,8 +472,6 @@ void mgmt_vty_init(void)
        static_vty_init();
 #endif
 
-       // hook_register(frr_config_pre, mgmt_config_pre_hook);
-
        event_add_event(mm->master, mgmt_config_read_in, NULL, 0,
                        &mgmt_daemon_info->read_in);