diff options
| author | Mark Stapp <mstapp@nvidia.com> | 2021-10-21 13:21:35 +0000 |
|---|---|---|
| committer | Donald Sharp <sharpd@nvidia.com> | 2023-03-28 10:10:33 -0400 |
| commit | 449f66552fd85277f9fa8724ae9c26e652ded7e0 (patch) | |
| tree | eca735a443ae71060682a2142834de548578410f /vtysh/vtysh_main.c | |
| parent | 916af6559c73f8a2d91c8b73f265954a33473f1e (diff) | |
vtysh: use daemon type and handle multi-instance types
To handle multi-instance daemons (ospf, e.g.), each forked
vtysh handles all of the instances of a daemon type.
Signed-off-by: Mark Stapp <mstapp@nvidia.com>
Diffstat (limited to 'vtysh/vtysh_main.c')
| -rw-r--r-- | vtysh/vtysh_main.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index f34bb9a456..053d663245 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -345,6 +345,8 @@ int main(int argc, char **argv, char **env) char pathspace[MAXPATHLEN] = ""; const char *histfile = NULL; const char *histfile_env = getenv("VTYSH_HISTFILE"); + char my_client[64]; + int my_client_type; /* SUID: drop down to calling user & go back up when needed */ elevuid = geteuid(); @@ -739,6 +741,7 @@ int main(int argc, char **argv, char **env) /* Store name of client this fork will handle */ strlcpy(my_client, vtysh_client[i].name, sizeof(my_client)); + my_client_type = vtysh_client[i].flag; fork_pid = fork(); /* If child, break */ @@ -761,15 +764,21 @@ int main(int argc, char **argv, char **env) */ for (unsigned int i = 0; i < array_size(vtysh_client); i++) { - if (strcmp(my_client, vtysh_client[i].name)) { + if (my_client_type != vtysh_client[i].flag) { + struct vtysh_client *cl; + /* * If this is a client we aren't * responsible for, disconnect */ - if (vtysh_client[i].fd >= 0) - close(vtysh_client[i].fd); - vtysh_client[i].fd = -1; - } else if (vtysh_client[i].fd == -1) { + for (cl = &vtysh_client[i]; cl; + cl = cl->next) { + if (cl->fd >= 0) + close(cl->fd); + cl->fd = -1; + } + } else if (vtysh_client[i].fd == -1 && + vtysh_client[i].next == NULL) { /* * If this is the client we are * responsible for, but we aren't |
