diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-07-11 17:06:46 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-07-11 17:06:46 +0000 |
commit | ec80cb701de542d205210980ce5034823899c844 (patch) | |
tree | 48c0b1030f8a4c3c6e7f4e34cf71c459720ef494 /usr.bin/tmux | |
parent | 3edc0bd2decfd31c18264264b5e36e79bbaf4617 (diff) |
Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.
New clients should be compatible with old tmux servers but vice versa may print
an error.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-if-shell.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-run-shell.c | 7 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 22 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 7 |
5 files changed, 39 insertions, 20 deletions
diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c index ecb6a12657d..02ab6bedc5c 100644 --- a/usr.bin/tmux/cmd-if-shell.c +++ b/usr.bin/tmux/cmd-if-shell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-if-shell.c,v 1.7 2009/11/13 19:53:29 nicm Exp $ */ +/* $OpenBSD: cmd-if-shell.c,v 1.8 2010/07/11 17:06:45 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -104,10 +104,13 @@ cmd_if_shell_free(void *data) { struct cmd_if_shell_data *cdata = data; struct cmd_ctx *ctx = &cdata->ctx; + struct msg_exit_data exitdata; if (ctx->cmdclient != NULL) { ctx->cmdclient->references--; - server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); + exitdata.retcode = ctx->cmdclient->retcode; + server_write_client( + ctx->cmdclient, MSG_EXIT, &exitdata, sizeof exitdata); } if (ctx->curclient != NULL) ctx->curclient->references--; diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c index 310f3d1c7d1..1cc80c8f111 100644 --- a/usr.bin/tmux/cmd-run-shell.c +++ b/usr.bin/tmux/cmd-run-shell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-run-shell.c,v 1.7 2010/05/25 20:05:25 nicm Exp $ */ +/* $OpenBSD: cmd-run-shell.c,v 1.8 2010/07/11 17:06:45 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -131,10 +131,13 @@ cmd_run_shell_free(void *data) { struct cmd_run_shell_data *cdata = data; struct cmd_ctx *ctx = &cdata->ctx; + struct msg_exit_data exitdata; if (ctx->cmdclient != NULL) { ctx->cmdclient->references--; - server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); + exitdata.retcode = ctx->cmdclient->retcode; + server_write_client( + ctx->cmdclient, MSG_EXIT, &exitdata, sizeof exitdata); } if (ctx->curclient != NULL) ctx->curclient->references--; diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index d1abbf5dad8..63180f82aa1 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.33 2010/06/28 22:10:42 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.34 2010/07/11 17:06:45 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -664,6 +664,8 @@ server_client_msg_error(struct cmd_ctx *ctx, const char *fmt, ...) fputc('\n', ctx->cmdclient->stderr_file); fflush(ctx->cmdclient->stderr_file); + + ctx->cmdclient->retcode = 1; } /* Callback to send print message to client. */ @@ -701,10 +703,11 @@ server_client_msg_info(struct cmd_ctx *ctx, const char *fmt, ...) void server_client_msg_command(struct client *c, struct msg_command_data *data) { - struct cmd_ctx ctx; - struct cmd_list *cmdlist = NULL; - int argc; - char **argv, *cause; + struct cmd_ctx ctx; + struct cmd_list *cmdlist = NULL; + struct msg_exit_data exitdata; + int argc; + char **argv, *cause; ctx.error = server_client_msg_error; ctx.print = server_client_msg_print; @@ -735,15 +738,18 @@ server_client_msg_command(struct client *c, struct msg_command_data *data) } cmd_free_argv(argc, argv); - if (cmd_list_exec(cmdlist, &ctx) != 1) - server_write_client(c, MSG_EXIT, NULL, 0); + if (cmd_list_exec(cmdlist, &ctx) != 1) { + exitdata.retcode = c->retcode; + server_write_client(c, MSG_EXIT, &exitdata, sizeof exitdata); + } cmd_list_free(cmdlist); return; error: if (cmdlist != NULL) cmd_list_free(cmdlist); - server_write_client(c, MSG_EXIT, NULL, 0); + exitdata.retcode = c->retcode; + server_write_client(c, MSG_EXIT, &exitdata, sizeof exitdata); } /* Handle identify message. */ diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 9f80e5a0b7d..644412deaf9 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.83 2010/06/28 22:10:42 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.84 2010/07/11 17:06:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -61,7 +61,6 @@ char *makesockpath(const char *); __dead void shell_exec(const char *, const char *); struct imsgbuf *main_ibuf; -int main_exitval; void main_signal(int, short, unused void *); void main_callback(int, short, void *); @@ -548,7 +547,6 @@ main(int argc, char **argv) events |= EV_WRITE; event_once(main_ibuf->fd, events, main_callback, shellcmd, NULL); - main_exitval = 0; event_dispatch(); clear_signals(); @@ -597,6 +595,7 @@ main_dispatch(const char *shellcmd) struct imsg imsg; ssize_t n, datalen; struct msg_shell_data shelldata; + struct msg_exit_data exitdata; if ((n = imsg_read(main_ibuf)) == -1 || n == 0) fatalx("imsg_read failed"); @@ -611,10 +610,13 @@ main_dispatch(const char *shellcmd) switch (imsg.hdr.type) { case MSG_EXIT: case MSG_SHUTDOWN: - if (datalen != 0) - fatalx("bad MSG_EXIT size"); - - exit(main_exitval); + if (datalen != sizeof exitdata) { + if (datalen != 0) + fatalx("bad MSG_EXIT size"); + exit(0); + } + memcpy(&exitdata, imsg.data, sizeof exitdata); + exit(exitdata.retcode); case MSG_READY: if (datalen != 0) fatalx("bad MSG_READY size"); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 09397cd8e58..66b952c263d 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.233 2010/06/29 05:24:49 tedu Exp $ */ +/* $OpenBSD: tmux.h,v 1.234 2010/07/11 17:06:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -413,6 +413,10 @@ struct msg_shell_data { char shell[MAXPATHLEN]; }; +struct msg_exit_data { + int retcode; +}; + /* Mode key commands. */ enum mode_key_cmd { MODEKEY_NONE, @@ -1081,6 +1085,7 @@ struct message_entry { struct client { struct imsgbuf ibuf; struct event event; + int retcode; struct timeval creation_time; struct timeval activity_time; |