summaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2017-01-13 12:01:12 +0000
committerThomas Adam <thomas@xteddy.org>2017-01-13 12:01:12 +0000
commit2311bbd28a227a8b6e6e52bf30665b37315cad11 (patch)
tree01fc816db0980b40d0b75905a097b20719fd4156 /client.c
parentd4cb178249c6c73c6197e34e871c2b8e803de175 (diff)
parent95950bf668cee5a80cd9bbe28d7134a52a240426 (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'client.c')
-rw-r--r--client.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/client.c b/client.c
index 98d14580..1c6c8bff 100644
--- a/client.c
+++ b/client.c
@@ -50,6 +50,8 @@ static enum {
static int client_exitval;
static enum msgtype client_exittype;
static const char *client_exitsession;
+static const char *client_execshell;
+static const char *client_execcmd;
static int client_attached;
static __dead void client_exec(const char *,const char *);
@@ -361,6 +363,14 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
/* Start main loop. */
proc_loop(client_proc, NULL);
+ /* Run command if user requested exec, instead of exiting. */
+ if (client_exittype == MSG_EXEC) {
+ if (client_flags & CLIENT_CONTROLCONTROL)
+ tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
+ clear_signals(0);
+ client_exec(client_execshell, client_execcmd);
+ }
+
/* Print the exit message, if any, and exit. */
if (client_attached) {
if (client_exitreason != CLIENT_EXIT_NONE)
@@ -660,6 +670,16 @@ client_dispatch_attached(struct imsg *imsg)
client_exitreason = CLIENT_EXIT_DETACHED;
proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
break;
+ case MSG_EXEC:
+ if (datalen == 0 || data[datalen - 1] != '\0' ||
+ strlen(data) + 1 == (size_t)datalen)
+ fatalx("bad MSG_EXEC string");
+ client_execcmd = xstrdup(data);
+ client_execshell = xstrdup(data + strlen(data) + 1);
+
+ client_exittype = imsg->hdr.type;
+ proc_send(client_peer, MSG_EXITING, -1, NULL, 0);
+ break;
case MSG_EXIT:
if (datalen != 0 && datalen != sizeof (int))
fatalx("bad MSG_EXIT size");