mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Add a -P option to detach to HUP the client's parent process (usually
causing it to exit as well).
This commit is contained in:
		
							
								
								
									
										19
									
								
								client.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								client.c
									
									
									
									
									
								
							@@ -36,6 +36,7 @@ struct imsgbuf	client_ibuf;
 | 
				
			|||||||
struct event	client_event;
 | 
					struct event	client_event;
 | 
				
			||||||
const char     *client_exitmsg;
 | 
					const char     *client_exitmsg;
 | 
				
			||||||
int		client_exitval;
 | 
					int		client_exitval;
 | 
				
			||||||
 | 
					enum msgtype	client_exittype;
 | 
				
			||||||
int		client_attached;
 | 
					int		client_attached;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int		client_connect(char *, int);
 | 
					int		client_connect(char *, int);
 | 
				
			||||||
@@ -100,6 +101,7 @@ client_main(int argc, char **argv, int flags)
 | 
				
			|||||||
	struct cmd_list		*cmdlist;
 | 
						struct cmd_list		*cmdlist;
 | 
				
			||||||
	struct msg_command_data	 cmddata;
 | 
						struct msg_command_data	 cmddata;
 | 
				
			||||||
	int			 cmdflags, fd;
 | 
						int			 cmdflags, fd;
 | 
				
			||||||
 | 
						pid_t			 ppid;
 | 
				
			||||||
	enum msgtype		 msg;
 | 
						enum msgtype		 msg;
 | 
				
			||||||
	char			*cause;
 | 
						char			*cause;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -192,8 +194,14 @@ client_main(int argc, char **argv, int flags)
 | 
				
			|||||||
	event_dispatch();
 | 
						event_dispatch();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Print the exit message, if any, and exit. */
 | 
						/* Print the exit message, if any, and exit. */
 | 
				
			||||||
	if (client_attached && client_exitmsg != NULL && !login_shell)
 | 
						if (client_attached) {
 | 
				
			||||||
		printf("[%s]\n", client_exitmsg);
 | 
							if (client_exitmsg != NULL && !login_shell)
 | 
				
			||||||
 | 
								printf("[%s]\n", client_exitmsg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ppid = getppid();
 | 
				
			||||||
 | 
							if (client_exittype == MSG_DETACHKILL && ppid > 1)
 | 
				
			||||||
 | 
								kill(ppid, SIGHUP);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return (client_exitval);
 | 
						return (client_exitval);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -434,12 +442,17 @@ client_dispatch_attached(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		log_debug("client got %d", imsg.hdr.type);
 | 
							log_debug("client got %d", imsg.hdr.type);
 | 
				
			||||||
		switch (imsg.hdr.type) {
 | 
							switch (imsg.hdr.type) {
 | 
				
			||||||
 | 
							case MSG_DETACHKILL:
 | 
				
			||||||
		case MSG_DETACH:
 | 
							case MSG_DETACH:
 | 
				
			||||||
			if (datalen != 0)
 | 
								if (datalen != 0)
 | 
				
			||||||
				fatalx("bad MSG_DETACH size");
 | 
									fatalx("bad MSG_DETACH size");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								client_exittype = imsg.hdr.type;
 | 
				
			||||||
 | 
								if (imsg.hdr.type == MSG_DETACHKILL)
 | 
				
			||||||
 | 
									client_exitmsg = "detached and SIGHUP";
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									client_exitmsg = "detached";
 | 
				
			||||||
			client_write_server(MSG_EXITING, NULL, 0);
 | 
								client_write_server(MSG_EXITING, NULL, 0);
 | 
				
			||||||
			client_exitmsg = "detached";
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case MSG_EXIT:
 | 
							case MSG_EXIT:
 | 
				
			||||||
			if (datalen != 0 &&
 | 
								if (datalen != 0 &&
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,8 +28,8 @@ int	cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const struct cmd_entry cmd_detach_client_entry = {
 | 
					const struct cmd_entry cmd_detach_client_entry = {
 | 
				
			||||||
	"detach-client", "detach",
 | 
						"detach-client", "detach",
 | 
				
			||||||
	"t:", 0, 0,
 | 
						"t:P", 0, 0,
 | 
				
			||||||
	CMD_TARGET_CLIENT_USAGE,
 | 
						"[-P] " CMD_TARGET_CLIENT_USAGE,
 | 
				
			||||||
	CMD_READONLY,
 | 
						CMD_READONLY,
 | 
				
			||||||
	NULL,
 | 
						NULL,
 | 
				
			||||||
	NULL,
 | 
						NULL,
 | 
				
			||||||
@@ -45,7 +45,10 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
 | 
						if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
 | 
				
			||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	server_write_client(c, MSG_DETACH, NULL, 0);
 | 
						if (args_has(args, 'P'))
 | 
				
			||||||
 | 
							server_write_client(c, MSG_DETACHKILL, NULL, 0);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							server_write_client(c, MSG_DETACH, NULL, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								tmux.1
									
									
									
									
									
								
							@@ -550,10 +550,17 @@ If no server is started,
 | 
				
			|||||||
.Ic attach-session
 | 
					.Ic attach-session
 | 
				
			||||||
will attempt to start it; this will fail unless sessions are created in the
 | 
					will attempt to start it; this will fail unless sessions are created in the
 | 
				
			||||||
configuration file.
 | 
					configuration file.
 | 
				
			||||||
.It Ic detach-client Op Fl t Ar target-client
 | 
					.It Xo Ic detach-client
 | 
				
			||||||
 | 
					.Op Fl P
 | 
				
			||||||
 | 
					.Op Fl t Ar target-client
 | 
				
			||||||
 | 
					.Xc
 | 
				
			||||||
.D1 (alias: Ic detach )
 | 
					.D1 (alias: Ic detach )
 | 
				
			||||||
Detach the current client if bound to a key, or the specified client with
 | 
					Detach the current client if bound to a key, or the specified client with
 | 
				
			||||||
.Fl t .
 | 
					.Fl t .
 | 
				
			||||||
 | 
					If
 | 
				
			||||||
 | 
					.Fl P
 | 
				
			||||||
 | 
					is given, send SIGHUP to the parent process of the client, typically causing it
 | 
				
			||||||
 | 
					to exit.
 | 
				
			||||||
.It Ic has-session Op Fl t Ar target-session
 | 
					.It Ic has-session Op Fl t Ar target-session
 | 
				
			||||||
.D1 (alias: Ic has )
 | 
					.D1 (alias: Ic has )
 | 
				
			||||||
Report an error and exit with 1 if the specified session does not exist.
 | 
					Report an error and exit with 1 if the specified session does not exist.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user