From ed3cfaafb2c04776b6452fa968715a3626d99a4a Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 12 Jul 2017 09:21:25 +0000 Subject: Make shell_command a global like other stuff rather than making it an exception and using callback argument. --- client.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index f94ce996..f00b2874 100644 --- a/client.c +++ b/client.c @@ -64,7 +64,7 @@ static void client_write(int, const char *, size_t); static void client_signal(int); static void client_dispatch(struct imsg *, void *); static void client_dispatch_attached(struct imsg *); -static void client_dispatch_wait(struct imsg *, const char *); +static void client_dispatch_wait(struct imsg *); static const char *client_exit_message(void); /* @@ -215,8 +215,7 @@ client_exit_message(void) /* Client main loop. */ int -client_main(struct event_base *base, int argc, char **argv, int flags, - const char *shellcmd) +client_main(struct event_base *base, int argc, char **argv, int flags) { struct cmd *cmd; struct cmd_list *cmdlist; @@ -237,7 +236,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags, /* Set up the initial command. */ cmdflags = 0; - if (shellcmd != NULL) { + if (shell_command != NULL) { msg = MSG_SHELL; cmdflags = CMD_STARTSERVER; } else if (argc == 0) { @@ -276,8 +275,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags, } return (1); } - client_peer = proc_add_peer(client_proc, fd, client_dispatch, - (void *)shellcmd); + client_peer = proc_add_peer(client_proc, fd, client_dispatch, NULL); /* Save these before pledge(). */ if ((cwd = getcwd(path, sizeof path)) == NULL) { @@ -533,7 +531,7 @@ client_signal(int sig) /* Callback for client read events. */ static void -client_dispatch(struct imsg *imsg, void *arg) +client_dispatch(struct imsg *imsg, __unused void *arg) { if (imsg == NULL) { client_exitreason = CLIENT_EXIT_LOST_SERVER; @@ -545,12 +543,12 @@ client_dispatch(struct imsg *imsg, void *arg) if (client_attached) client_dispatch_attached(imsg); else - client_dispatch_wait(imsg, arg); + client_dispatch_wait(imsg); } /* Dispatch imsgs when in wait state (before MSG_READY). */ static void -client_dispatch_wait(struct imsg *imsg, const char *shellcmd) +client_dispatch_wait(struct imsg *imsg) { char *data; ssize_t datalen; @@ -630,7 +628,7 @@ client_dispatch_wait(struct imsg *imsg, const char *shellcmd) fatalx("bad MSG_SHELL string"); clear_signals(0); - client_exec(data, shellcmd); + client_exec(data, shell_command); /* NOTREACHED */ case MSG_DETACH: case MSG_DETACHKILL: -- cgit v1.2.3 From 0453ad01468460d5fca09457ed7c862685076931 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 12 Jul 2017 09:24:17 +0000 Subject: Move signal code into proc.c. --- client.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index f00b2874..efc82e5f 100644 --- a/client.c +++ b/client.c @@ -157,7 +157,7 @@ retry: close(lockfd); return (-1); } - fd = server_start(base, lockfd, lockfile); + fd = server_start(client_proc, base, lockfd, lockfile); } if (locked && lockfd >= 0) { @@ -261,7 +261,8 @@ client_main(struct event_base *base, int argc, char **argv, int flags) } /* Create client process structure (starts logging). */ - client_proc = proc_start("client", base, 0, client_signal); + client_proc = proc_start("client"); + proc_set_signals(client_proc, client_signal); /* Initialize the client socket and start the server. */ fd = client_connect(base, socket_path, cmdflags & CMD_STARTSERVER); @@ -364,7 +365,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags) if (client_exittype == MSG_EXEC) { if (client_flags & CLIENT_CONTROLCONTROL) tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio); - clear_signals(0); + proc_clear_signals(client_proc); client_exec(client_execshell, client_execcmd); } @@ -627,7 +628,7 @@ client_dispatch_wait(struct imsg *imsg) if (datalen == 0 || data[datalen - 1] != '\0') fatalx("bad MSG_SHELL string"); - clear_signals(0); + proc_clear_signals(client_proc); client_exec(data, shell_command); /* NOTREACHED */ case MSG_DETACH: -- cgit v1.2.3