aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2010-07-17 14:36:41 +0000
committerTiago Cunha <tcunha@gmx.com>2010-07-17 14:36:41 +0000
commitad6a528f611bf793f0c3d4f832f34a1c778068e3 (patch)
tree7cc69a9c6ed4419842ac808a695b568e04b1d918
parent46f27eab22f78ec35a11b6e5b4d61e705c96eca1 (diff)
downloadrtmux-ad6a528f611bf793f0c3d4f832f34a1c778068e3.tar.gz
rtmux-ad6a528f611bf793f0c3d4f832f34a1c778068e3.tar.bz2
rtmux-ad6a528f611bf793f0c3d4f832f34a1c778068e3.zip
Sync OpenBSD patchset 734:
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.
-rw-r--r--cmd-if-shell.c7
-rw-r--r--cmd-run-shell.c7
-rw-r--r--server-client.c22
-rw-r--r--tmux.c16
-rw-r--r--tmux.h7
5 files changed, 39 insertions, 20 deletions
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 0fa5ba38..b64599e9 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-if-shell.c,v 1.8 2009-11-14 17:56:39 tcunha Exp $ */
+/* $Id: cmd-if-shell.c,v 1.9 2010-07-17 14:36:40 tcunha 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/cmd-run-shell.c b/cmd-run-shell.c
index 0a4a4095..5e7701f5 100644
--- a/cmd-run-shell.c
+++ b/cmd-run-shell.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-run-shell.c,v 1.7 2010-06-06 00:04:59 tcunha Exp $ */
+/* $Id: cmd-run-shell.c,v 1.8 2010-07-17 14:36:40 tcunha 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/server-client.c b/server-client.c
index 9af40994..05949edd 100644
--- a/server-client.c
+++ b/server-client.c
@@ -1,4 +1,4 @@
-/* $Id: server-client.c,v 1.34 2010-07-02 02:52:13 tcunha Exp $ */
+/* $Id: server-client.c,v 1.35 2010-07-17 14:36:40 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -663,6 +663,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. */
@@ -700,10 +702,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;
@@ -734,15 +737,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/tmux.c b/tmux.c
index 571ef070..b2a6d1b8 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.213 2010-07-02 02:52:13 tcunha Exp $ */
+/* $Id: tmux.c,v 1.214 2010-07-17 14:36:41 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -60,7 +60,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 *);
@@ -565,7 +564,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();
@@ -614,6 +612,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");
@@ -628,10 +627,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/tmux.h b/tmux.h
index 8e43ae43..bbf6ae1b 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.569 2010-07-02 02:56:07 tcunha Exp $ */
+/* $Id: tmux.h,v 1.570 2010-07-17 14:36:41 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -412,6 +412,10 @@ struct msg_shell_data {
char shell[MAXPATHLEN];
};
+struct msg_exit_data {
+ int retcode;
+};
+
/* Mode key commands. */
enum mode_key_cmd {
MODEKEY_NONE,
@@ -1080,6 +1084,7 @@ struct message_entry {
struct client {
struct imsgbuf ibuf;
struct event event;
+ int retcode;
struct timeval creation_time;
struct timeval activity_time;