mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -104,10 +104,13 @@ cmd_if_shell_free(void *data) | |||||||
| { | { | ||||||
| 	struct cmd_if_shell_data	*cdata = data; | 	struct cmd_if_shell_data	*cdata = data; | ||||||
| 	struct cmd_ctx			*ctx = &cdata->ctx; | 	struct cmd_ctx			*ctx = &cdata->ctx; | ||||||
|  | 	struct msg_exit_data		 exitdata; | ||||||
|  |  | ||||||
| 	if (ctx->cmdclient != NULL) { | 	if (ctx->cmdclient != NULL) { | ||||||
| 		ctx->cmdclient->references--; | 		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) | 	if (ctx->curclient != NULL) | ||||||
| 		ctx->curclient->references--; | 		ctx->curclient->references--; | ||||||
|   | |||||||
| @@ -131,10 +131,13 @@ cmd_run_shell_free(void *data) | |||||||
| { | { | ||||||
| 	struct cmd_run_shell_data	*cdata = data; | 	struct cmd_run_shell_data	*cdata = data; | ||||||
| 	struct cmd_ctx			*ctx = &cdata->ctx; | 	struct cmd_ctx			*ctx = &cdata->ctx; | ||||||
|  | 	struct msg_exit_data		 exitdata; | ||||||
|  |  | ||||||
| 	if (ctx->cmdclient != NULL) { | 	if (ctx->cmdclient != NULL) { | ||||||
| 		ctx->cmdclient->references--; | 		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) | 	if (ctx->curclient != NULL) | ||||||
| 		ctx->curclient->references--; | 		ctx->curclient->references--; | ||||||
|   | |||||||
| @@ -664,6 +664,8 @@ server_client_msg_error(struct cmd_ctx *ctx, const char *fmt, ...) | |||||||
|  |  | ||||||
| 	fputc('\n', ctx->cmdclient->stderr_file); | 	fputc('\n', ctx->cmdclient->stderr_file); | ||||||
| 	fflush(ctx->cmdclient->stderr_file); | 	fflush(ctx->cmdclient->stderr_file); | ||||||
|  |  | ||||||
|  | 	ctx->cmdclient->retcode = 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Callback to send print message to client. */ | /* Callback to send print message to client. */ | ||||||
| @@ -703,6 +705,7 @@ server_client_msg_command(struct client *c, struct msg_command_data *data) | |||||||
| { | { | ||||||
| 	struct cmd_ctx	 	ctx; | 	struct cmd_ctx	 	ctx; | ||||||
| 	struct cmd_list	       *cmdlist = NULL; | 	struct cmd_list	       *cmdlist = NULL; | ||||||
|  | 	struct msg_exit_data	exitdata; | ||||||
| 	int			argc; | 	int			argc; | ||||||
| 	char		      **argv, *cause; | 	char		      **argv, *cause; | ||||||
|  |  | ||||||
| @@ -735,15 +738,18 @@ server_client_msg_command(struct client *c, struct msg_command_data *data) | |||||||
| 	} | 	} | ||||||
| 	cmd_free_argv(argc, argv); | 	cmd_free_argv(argc, argv); | ||||||
|  |  | ||||||
| 	if (cmd_list_exec(cmdlist, &ctx) != 1) | 	if (cmd_list_exec(cmdlist, &ctx) != 1) { | ||||||
| 		server_write_client(c, MSG_EXIT, NULL, 0); | 		exitdata.retcode = c->retcode; | ||||||
|  | 		server_write_client(c, MSG_EXIT, &exitdata, sizeof exitdata); | ||||||
|  | 	} | ||||||
| 	cmd_list_free(cmdlist); | 	cmd_list_free(cmdlist); | ||||||
| 	return; | 	return; | ||||||
|  |  | ||||||
| error: | error: | ||||||
| 	if (cmdlist != NULL) | 	if (cmdlist != NULL) | ||||||
| 		cmd_list_free(cmdlist); | 		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. */ | /* Handle identify message. */ | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								tmux.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tmux.c
									
									
									
									
									
								
							| @@ -61,7 +61,6 @@ char 		*makesockpath(const char *); | |||||||
| __dead void	 shell_exec(const char *, const char *); | __dead void	 shell_exec(const char *, const char *); | ||||||
|  |  | ||||||
| struct imsgbuf	*main_ibuf; | struct imsgbuf	*main_ibuf; | ||||||
| int	         main_exitval; |  | ||||||
|  |  | ||||||
| void		 main_signal(int, short, unused void *); | void		 main_signal(int, short, unused void *); | ||||||
| void		 main_callback(int, short, void *); | void		 main_callback(int, short, void *); | ||||||
| @@ -548,7 +547,6 @@ main(int argc, char **argv) | |||||||
| 		events |= EV_WRITE; | 		events |= EV_WRITE; | ||||||
| 	event_once(main_ibuf->fd, events, main_callback, shellcmd, NULL); | 	event_once(main_ibuf->fd, events, main_callback, shellcmd, NULL); | ||||||
|  |  | ||||||
| 	main_exitval = 0; |  | ||||||
| 	event_dispatch(); | 	event_dispatch(); | ||||||
|  |  | ||||||
| 	clear_signals(); | 	clear_signals(); | ||||||
| @@ -597,6 +595,7 @@ main_dispatch(const char *shellcmd) | |||||||
| 	struct imsg		imsg; | 	struct imsg		imsg; | ||||||
| 	ssize_t			n, datalen; | 	ssize_t			n, datalen; | ||||||
| 	struct msg_shell_data	shelldata; | 	struct msg_shell_data	shelldata; | ||||||
|  | 	struct msg_exit_data	exitdata; | ||||||
|  |  | ||||||
| 	if ((n = imsg_read(main_ibuf)) == -1 || n == 0) | 	if ((n = imsg_read(main_ibuf)) == -1 || n == 0) | ||||||
| 		fatalx("imsg_read failed"); | 		fatalx("imsg_read failed"); | ||||||
| @@ -611,10 +610,13 @@ main_dispatch(const char *shellcmd) | |||||||
| 		switch (imsg.hdr.type) { | 		switch (imsg.hdr.type) { | ||||||
| 		case MSG_EXIT: | 		case MSG_EXIT: | ||||||
| 		case MSG_SHUTDOWN: | 		case MSG_SHUTDOWN: | ||||||
|  | 			if (datalen != sizeof exitdata) { | ||||||
| 				if (datalen != 0) | 				if (datalen != 0) | ||||||
| 					fatalx("bad MSG_EXIT size"); | 					fatalx("bad MSG_EXIT size"); | ||||||
|  | 				exit(0); | ||||||
| 			exit(main_exitval); | 			} | ||||||
|  | 			memcpy(&exitdata, imsg.data, sizeof exitdata); | ||||||
|  | 			exit(exitdata.retcode); | ||||||
| 		case MSG_READY: | 		case MSG_READY: | ||||||
| 			if (datalen != 0) | 			if (datalen != 0) | ||||||
| 				fatalx("bad MSG_READY size"); | 				fatalx("bad MSG_READY size"); | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -413,6 +413,10 @@ struct msg_shell_data { | |||||||
| 	char		shell[MAXPATHLEN]; | 	char		shell[MAXPATHLEN]; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | struct msg_exit_data { | ||||||
|  | 	int		retcode; | ||||||
|  | }; | ||||||
|  |  | ||||||
| /* Mode key commands. */ | /* Mode key commands. */ | ||||||
| enum mode_key_cmd { | enum mode_key_cmd { | ||||||
| 	MODEKEY_NONE, | 	MODEKEY_NONE, | ||||||
| @@ -1081,6 +1085,7 @@ struct message_entry { | |||||||
| struct client { | struct client { | ||||||
| 	struct imsgbuf	 ibuf; | 	struct imsgbuf	 ibuf; | ||||||
| 	struct event	 event; | 	struct event	 event; | ||||||
|  | 	int		 retcode; | ||||||
|  |  | ||||||
| 	struct timeval	 creation_time; | 	struct timeval	 creation_time; | ||||||
| 	struct timeval	 activity_time; | 	struct timeval	 activity_time; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Nicholas Marriott
					Nicholas Marriott