From 5be3fb86b9225842515f79a611a44d587814bd4c Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Wed, 23 Sep 2009 15:18:56 +0000 Subject: Sync OpenBSD patchset 350: Support -c like sh(1) to execute a command, useful when tmux is a login shell. Suggested by halex@. This includes another protocol version increase (the last for now) so again restart the tmux server before upgrading. --- server-msg.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'server-msg.c') diff --git a/server-msg.c b/server-msg.c index 7cfdc2d9..8a18c4ab 100644 --- a/server-msg.c +++ b/server-msg.c @@ -1,4 +1,4 @@ -/* $Id: server-msg.c,v 1.87 2009-09-23 15:00:08 tcunha Exp $ */ +/* $Id: server-msg.c,v 1.88 2009-09-23 15:18:56 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -29,6 +30,7 @@ void server_msg_command(struct client *, struct msg_command_data *); void server_msg_identify(struct client *, struct msg_identify_data *, int); +void server_msg_shell(struct client *); void printflike2 server_msg_command_error(struct cmd_ctx *, const char *, ...); void printflike2 server_msg_command_print(struct cmd_ctx *, const char *, ...); @@ -113,6 +115,12 @@ server_msg_dispatch(struct client *c) if (strchr(environdata.var, '=') != NULL) environ_put(&c->environ, environdata.var); break; + case MSG_SHELL: + if (datalen != 0) + fatalx("bad MSG_SHELL size"); + + server_msg_shell(c); + break; default: fatalx("unexpected message"); } @@ -248,3 +256,20 @@ server_msg_identify(struct client *c, struct msg_identify_data *data, int fd) c->flags |= CLIENT_TERMINAL; } + +void +server_msg_shell(struct client *c) +{ + struct msg_shell_data data; + const char *shell; + + shell = options_get_string(&global_s_options, "default-shell"); + + if (*shell == '\0' || areshell(shell)) + shell = _PATH_BSHELL; + if (strlcpy(data.shell, shell, sizeof data.shell) >= sizeof data.shell) + strlcpy(data.shell, _PATH_BSHELL, sizeof data.shell); + + server_write_client(c, MSG_SHELL, &data, sizeof data); + c->flags |= CLIENT_BAD; /* it will die after exec */ +} -- cgit