mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Add new-session -X and attach-session -x to send SIGHUP to parent when
detaching (like detach-client -P). From Colin Watson in GitHub issue 1773.
This commit is contained in:
		| @@ -37,8 +37,8 @@ const struct cmd_entry cmd_attach_session_entry = { | |||||||
| 	.name = "attach-session", | 	.name = "attach-session", | ||||||
| 	.alias = "attach", | 	.alias = "attach", | ||||||
|  |  | ||||||
| 	.args = { "c:dErt:", 0, 0 }, | 	.args = { "c:dErt:x", 0, 0 }, | ||||||
| 	.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE, | 	.usage = "[-dErx] [-c working-directory] " CMD_TARGET_SESSION_USAGE, | ||||||
|  |  | ||||||
| 	/* -t is special */ | 	/* -t is special */ | ||||||
|  |  | ||||||
| @@ -48,7 +48,7 @@ const struct cmd_entry cmd_attach_session_entry = { | |||||||
|  |  | ||||||
| enum cmd_retval | enum cmd_retval | ||||||
| cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, | cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, | ||||||
|     int rflag, const char *cflag, int Eflag) |     int xflag, int rflag, const char *cflag, int Eflag) | ||||||
| { | { | ||||||
| 	struct cmd_find_state	*current = &item->shared->current; | 	struct cmd_find_state	*current = &item->shared->current; | ||||||
| 	enum cmd_find_type	 type; | 	enum cmd_find_type	 type; | ||||||
| @@ -58,6 +58,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, | |||||||
| 	struct winlink		*wl; | 	struct winlink		*wl; | ||||||
| 	struct window_pane	*wp; | 	struct window_pane	*wp; | ||||||
| 	char			*cause; | 	char			*cause; | ||||||
|  | 	enum msgtype		 msgtype; | ||||||
|  |  | ||||||
| 	if (RB_EMPTY(&sessions)) { | 	if (RB_EMPTY(&sessions)) { | ||||||
| 		cmdq_error(item, "no sessions"); | 		cmdq_error(item, "no sessions"); | ||||||
| @@ -102,11 +103,15 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, | |||||||
|  |  | ||||||
| 	c->last_session = c->session; | 	c->last_session = c->session; | ||||||
| 	if (c->session != NULL) { | 	if (c->session != NULL) { | ||||||
| 		if (dflag) { | 		if (dflag || xflag) { | ||||||
|  | 			if (xflag) | ||||||
|  | 				msgtype = MSG_DETACHKILL; | ||||||
|  | 			else | ||||||
|  | 				msgtype = MSG_DETACH; | ||||||
| 			TAILQ_FOREACH(c_loop, &clients, entry) { | 			TAILQ_FOREACH(c_loop, &clients, entry) { | ||||||
| 				if (c_loop->session != s || c == c_loop) | 				if (c_loop->session != s || c == c_loop) | ||||||
| 					continue; | 					continue; | ||||||
| 				server_client_detach(c_loop, MSG_DETACH); | 				server_client_detach(c_loop, msgtype); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		if (!Eflag) | 		if (!Eflag) | ||||||
| @@ -131,11 +136,15 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, | |||||||
| 		if (rflag) | 		if (rflag) | ||||||
| 			c->flags |= CLIENT_READONLY; | 			c->flags |= CLIENT_READONLY; | ||||||
|  |  | ||||||
| 		if (dflag) { | 		if (dflag || xflag) { | ||||||
|  | 			if (xflag) | ||||||
|  | 				msgtype = MSG_DETACHKILL; | ||||||
|  | 			else | ||||||
|  | 				msgtype = MSG_DETACH; | ||||||
| 			TAILQ_FOREACH(c_loop, &clients, entry) { | 			TAILQ_FOREACH(c_loop, &clients, entry) { | ||||||
| 				if (c_loop->session != s || c == c_loop) | 				if (c_loop->session != s || c == c_loop) | ||||||
| 					continue; | 					continue; | ||||||
| 				server_client_detach(c_loop, MSG_DETACH); | 				server_client_detach(c_loop, msgtype); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		if (!Eflag) | 		if (!Eflag) | ||||||
| @@ -169,6 +178,6 @@ cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item) | |||||||
| 	struct args	*args = self->args; | 	struct args	*args = self->args; | ||||||
|  |  | ||||||
| 	return (cmd_attach_session(item, args_get(args, 't'), | 	return (cmd_attach_session(item, args_get(args, 't'), | ||||||
| 	    args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'), | 	    args_has(args, 'd'), args_has(args, 'x'), args_has(args, 'r'), | ||||||
| 	    args_has(args, 'E'))); | 	    args_get(args, 'c'), args_has(args, 'E'))); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -39,8 +39,8 @@ const struct cmd_entry cmd_new_session_entry = { | |||||||
| 	.name = "new-session", | 	.name = "new-session", | ||||||
| 	.alias = "new", | 	.alias = "new", | ||||||
|  |  | ||||||
| 	.args = { "Ac:dDEF:n:Ps:t:x:y:", 0, -1 }, | 	.args = { "Ac:dDEF:n:Ps:t:x:Xy:", 0, -1 }, | ||||||
| 	.usage = "[-AdDEP] [-c start-directory] [-F format] [-n window-name] " | 	.usage = "[-AdDEPX] [-c start-directory] [-F format] [-n window-name] " | ||||||
| 		 "[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] " | 		 "[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] " | ||||||
| 		 "[-y height] [command]", | 		 "[-y height] [command]", | ||||||
|  |  | ||||||
| @@ -105,7 +105,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) | |||||||
| 			if (args_has(args, 'A')) { | 			if (args_has(args, 'A')) { | ||||||
| 				retval = cmd_attach_session(item, | 				retval = cmd_attach_session(item, | ||||||
| 				    newname, args_has(args, 'D'), | 				    newname, args_has(args, 'D'), | ||||||
| 				    0, NULL, args_has(args, 'E')); | 				    args_has(args, 'X'), 0, NULL, | ||||||
|  | 				    args_has(args, 'E')); | ||||||
| 				free(newname); | 				free(newname); | ||||||
| 				return (retval); | 				return (retval); | ||||||
| 			} | 			} | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -918,7 +918,7 @@ section. | |||||||
| The following commands are available to manage clients and sessions: | The following commands are available to manage clients and sessions: | ||||||
| .Bl -tag -width Ds | .Bl -tag -width Ds | ||||||
| .It Xo Ic attach-session | .It Xo Ic attach-session | ||||||
| .Op Fl dEr | .Op Fl dErx | ||||||
| .Op Fl c Ar working-directory | .Op Fl c Ar working-directory | ||||||
| .Op Fl t Ar target-session | .Op Fl t Ar target-session | ||||||
| .Xc | .Xc | ||||||
| @@ -931,6 +931,10 @@ If used from inside, switch the current client. | |||||||
| If | If | ||||||
| .Fl d | .Fl d | ||||||
| is specified, any other clients attached to the session are detached. | is specified, any other clients attached to the session are detached. | ||||||
|  | If | ||||||
|  | .Fl x | ||||||
|  | is given, send SIGHUP to the parent process of the client as well as | ||||||
|  | detaching the client, typically causing it to exit. | ||||||
| .Fl r | .Fl r | ||||||
| signifies the client is read-only (only keys bound to the | signifies the client is read-only (only keys bound to the | ||||||
| .Ic detach-client | .Ic detach-client | ||||||
| @@ -1048,7 +1052,7 @@ command. | |||||||
| Lock all clients attached to | Lock all clients attached to | ||||||
| .Ar target-session . | .Ar target-session . | ||||||
| .It Xo Ic new-session | .It Xo Ic new-session | ||||||
| .Op Fl AdDEP | .Op Fl AdDEPX | ||||||
| .Op Fl c Ar start-directory | .Op Fl c Ar start-directory | ||||||
| .Op Fl F Ar format | .Op Fl F Ar format | ||||||
| .Op Fl n Ar window-name | .Op Fl n Ar window-name | ||||||
| @@ -1105,6 +1109,12 @@ already exists; in this case, | |||||||
| behaves like | behaves like | ||||||
| .Fl d | .Fl d | ||||||
| to | to | ||||||
|  | .Ic attach-session , | ||||||
|  | and | ||||||
|  | .Fl X | ||||||
|  | behaves like | ||||||
|  | .Fl x | ||||||
|  | to | ||||||
| .Ic attach-session . | .Ic attach-session . | ||||||
| .Pp | .Pp | ||||||
| If | If | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -2009,7 +2009,7 @@ extern const struct cmd_entry *cmd_table[]; | |||||||
|  |  | ||||||
| /* cmd-attach-session.c */ | /* cmd-attach-session.c */ | ||||||
| enum cmd_retval	 cmd_attach_session(struct cmdq_item *, const char *, int, int, | enum cmd_retval	 cmd_attach_session(struct cmdq_item *, const char *, int, int, | ||||||
| 		     const char *, int); | 		     int, const char *, int); | ||||||
|  |  | ||||||
| /* cmd-parse.c */ | /* cmd-parse.c */ | ||||||
| void	    	 cmd_parse_empty(struct cmd_parse_input *); | void	    	 cmd_parse_empty(struct cmd_parse_input *); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm