]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
kronosnetd: perform clean shutdown on daemon exit
authorFabio M. Di Nitto <fdinitto@redhat.com>
Thu, 8 Nov 2012 11:30:50 +0000 (12:30 +0100)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Thu, 8 Nov 2012 11:30:50 +0000 (12:30 +0100)
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
kronosnetd/vty.c
kronosnetd/vty_cli_cmds.c
kronosnetd/vty_cli_cmds.h

index f9edde910c7fe51f5f3e5537587a08691376ebf2..08ce3402b536578eac6a2a31c0a5654bf1bcc748 100644 (file)
@@ -280,7 +280,8 @@ int knet_vty_main_loop(int debug)
                                        knet_vtys[conn_index].got_epipe = 1;
                                }
                        }
-                       sleep(2);
+                       sleep(2); /* give time to all vty to exit */
+                       knet_close_down();
                        log_info("Have a nice day! Goodbye");
                        goto out;
                }
@@ -412,8 +413,6 @@ out:
        close(logfd[0]);
        close(logfd[1]);
 
-       // reverse running config to close/release resources;
-
        return err;
 }
 
index b6e29adc9e618b224aa26b410acb8b369651f0c8..11cb60b55e9aeb3c55e3f8865c90831f7769251c 100644 (file)
@@ -1268,7 +1268,8 @@ static int knet_cmd_stop(struct knet_vty *vty)
        if (err < 0) {
                knet_vty_write(vty, "Error: Unable to set interface %s down!%s", tap_get_name(knet_iface->cfg_eth.tap), telnet_newline);
        } else {
-               knet_handle_setfwd(knet_iface->cfg_ring.knet_h, 0);
+               if (knet_iface->cfg_ring.knet_h)
+                       knet_handle_setfwd(knet_iface->cfg_ring.knet_h, 0);
                knet_iface->active = 0;
        }
        if (error_down) {
@@ -1456,9 +1457,6 @@ static int knet_cmd_no_interface(struct knet_vty *vty)
                        sleep (1);
                }
 
-               if (head == NULL)
-                       break;
-
                host = head;
 
                while (knet_host_release(knet_iface->cfg_ring.knet_h, &head) != 0) {
@@ -1466,6 +1464,9 @@ static int knet_cmd_no_interface(struct knet_vty *vty)
                        sleep (1);
                }
 
+               if (host == NULL)
+                       break;
+
                for (i = 0; i < KNET_MAX_LINK; i++)
                        knet_link_enable(knet_iface->cfg_ring.knet_h, host->node_id, &host->link[i], 0);
 
@@ -1477,8 +1478,10 @@ static int knet_cmd_no_interface(struct knet_vty *vty)
 
        knet_cmd_stop(vty);
 
-       if (knet_iface->cfg_ring.knet_h)
+       if (knet_iface->cfg_ring.knet_h) {
                knet_handle_free(knet_iface->cfg_ring.knet_h);
+               knet_iface->cfg_ring.knet_h = NULL;
+       }
 
        if (knet_iface->cfg_eth.tap)
                tap_close(knet_iface->cfg_eth.tap);
@@ -1900,6 +1903,30 @@ int knet_vty_execute_cmd(struct knet_vty *vty)
        return match_command(vty, cmds, cmd, cmdlen, cmdoffset, KNET_VTY_MATCH_EXEC);
 }
 
+void knet_close_down(void)
+{
+       struct knet_vty *vty = &knet_vtys[0];
+       int err, loop = 0;
+
+       vty->node = NODE_CONFIG;
+       vty->vty_sock = 1;
+       vty->user_can_enable = 1;
+       vty->filemode = 1;
+       vty->got_epipe = 0;
+
+       while ((knet_cfg_head.knet_cfg) && (loop < 10)) {
+               memset(vty->line, 0, sizeof(vty->line));
+               snprintf(vty->line, sizeof(vty->line) - 1, "no interface %s", tap_get_name(knet_cfg_head.knet_cfg->cfg_eth.tap));
+               vty->line_idx = strlen(vty->line);
+               err = knet_vty_execute_cmd(vty);
+               if (err != 0)  {
+                       log_error("error shutting down: %s", vty->line);
+                       break;
+               }
+               loop++;
+       }
+}
+
 int knet_read_conf(void)
 {
        int err = 0, len = 0, line = 0;
index d40c8d0753e8fa6b0e43090a9aba1d5cb5b213e5..1432161af58761a0e4b7dc6f934f462c55d1413b 100644 (file)
@@ -34,6 +34,7 @@ void knet_vty_help(struct knet_vty *vty);
 void knet_vty_tab_completion(struct knet_vty *vty);
 
 int knet_read_conf(void);
+void knet_close_down(void);
 
 extern vty_nodes_t knet_vty_nodes[];