mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 01:34:18 +00:00 
			
		
		
		
	Sync OpenBSD patchset 168:
Both of cmdclient and curclient CAN be NULL - if the command is executed from the configuration file. In this case, attach-session can't do much, and new-session should just assume -d.
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-attach-session.c,v 1.28 2009-07-18 11:06:09 nicm Exp $ */
 | 
					/* $Id: cmd-attach-session.c,v 1.29 2009-07-23 13:25:27 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -55,6 +55,9 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	if ((s = cmd_find_session(ctx, data->target)) == NULL)
 | 
						if ((s = cmd_find_session(ctx, data->target)) == NULL)
 | 
				
			||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ctx->cmdclient == NULL && ctx->curclient == NULL)
 | 
				
			||||||
 | 
							return (0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ctx->cmdclient == NULL) {
 | 
						if (ctx->cmdclient == NULL) {
 | 
				
			||||||
		if (data->chflags & CMD_CHFLAG('d')) {
 | 
							if (data->chflags & CMD_CHFLAG('d')) {
 | 
				
			||||||
			/* 
 | 
								/* 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-new-session.c,v 1.46 2009-07-23 13:19:12 tcunha Exp $ */
 | 
					/* $Id: cmd-new-session.c,v 1.47 2009-07-23 13:25:27 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -114,6 +114,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	struct session			*s;
 | 
						struct session			*s;
 | 
				
			||||||
	struct options			*oo;
 | 
						struct options			*oo;
 | 
				
			||||||
	char				*cmd, *cwd, *cause;
 | 
						char				*cmd, *cwd, *cause;
 | 
				
			||||||
 | 
						int				 detached;
 | 
				
			||||||
	u_int				 sx, sy;
 | 
						u_int				 sx, sy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (data->newname != NULL && session_find(data->newname) != NULL) {
 | 
						if (data->newname != NULL && session_find(data->newname) != NULL) {
 | 
				
			||||||
@@ -122,7 +123,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * There are two cases:
 | 
						 * There are three cases:
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * 1. If cmdclient is non-NULL, new-session has been called from the
 | 
						 * 1. If cmdclient is non-NULL, new-session has been called from the
 | 
				
			||||||
	 *    command-line - cmdclient is to become a new attached, interactive
 | 
						 *    command-line - cmdclient is to become a new attached, interactive
 | 
				
			||||||
@@ -132,12 +133,20 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	 * 2. If cmdclient is NULL, new-session has been called from an
 | 
						 * 2. If cmdclient is NULL, new-session has been called from an
 | 
				
			||||||
	 *    existing client (such as a key binding).
 | 
						 *    existing client (such as a key binding).
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * In both cases, a new additional session needs to be created and
 | 
						 * 3. Both are NULL, the command was in the configuration file. Treat
 | 
				
			||||||
 | 
						 *    this as if -d was given even if it was not.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * In all cases, a new additional session needs to be created and
 | 
				
			||||||
	 * (unless -d) set as the current session for the client.
 | 
						 * (unless -d) set as the current session for the client.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Set -d if no client. */
 | 
				
			||||||
 | 
						detached = data->flag_detached;
 | 
				
			||||||
 | 
						if (ctx->cmdclient == NULL && ctx->curclient == NULL)
 | 
				
			||||||
 | 
							detached = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Open the terminal if necessary. */
 | 
						/* Open the terminal if necessary. */
 | 
				
			||||||
	if (!data->flag_detached && ctx->cmdclient != NULL) {
 | 
						if (!detached && ctx->cmdclient != NULL) {
 | 
				
			||||||
		if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
 | 
							if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
 | 
				
			||||||
			ctx->error(ctx, "not a terminal");
 | 
								ctx->error(ctx, "not a terminal");
 | 
				
			||||||
			return (-1);
 | 
								return (-1);
 | 
				
			||||||
@@ -155,11 +164,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	 * path and command.
 | 
						 * path and command.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	oo = &global_s_options;
 | 
						oo = &global_s_options;
 | 
				
			||||||
	if (ctx->cmdclient == NULL)
 | 
						if (ctx->cmdclient == NULL && ctx->curclient != NULL)
 | 
				
			||||||
		oo = &ctx->curclient->session->options;
 | 
							oo = &ctx->curclient->session->options;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Find new session size and options. */
 | 
						/* Find new session size and options. */
 | 
				
			||||||
	if (data->flag_detached) {
 | 
						if (detached) {
 | 
				
			||||||
		sx = 80;
 | 
							sx = 80;
 | 
				
			||||||
		sy = 25;
 | 
							sy = 25;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
@@ -207,14 +216,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	 * to exit.
 | 
						 * to exit.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (ctx->cmdclient != NULL) {
 | 
						if (ctx->cmdclient != NULL) {
 | 
				
			||||||
		if (!data->flag_detached)
 | 
							if (!detached)
 | 
				
			||||||
			server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
 | 
								server_write_client(ctx->cmdclient, MSG_READY, NULL, 0);
 | 
				
			||||||
		else 
 | 
							else 
 | 
				
			||||||
			server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
 | 
								server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/* Set the client to the new session. */
 | 
						/* Set the client to the new session. */
 | 
				
			||||||
 	if (!data->flag_detached) {
 | 
					 	if (!detached) {
 | 
				
			||||||
		if (ctx->cmdclient != NULL) {
 | 
							if (ctx->cmdclient != NULL) {
 | 
				
			||||||
 			ctx->cmdclient->session = s;
 | 
					 			ctx->cmdclient->session = s;
 | 
				
			||||||
			server_redraw_client(ctx->cmdclient);
 | 
								server_redraw_client(ctx->cmdclient);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: tmux.h,v 1.386 2009-07-23 13:10:38 tcunha Exp $ */
 | 
					/* $Id: tmux.h,v 1.387 2009-07-23 13:25:27 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -861,7 +861,8 @@ struct cmd_ctx {
 | 
				
			|||||||
	 * cmdclient is the client which sent the MSG_COMMAND to the server, if
 | 
						 * cmdclient is the client which sent the MSG_COMMAND to the server, if
 | 
				
			||||||
	 * any. This is NULL unless the command came from the command-line.
 | 
						 * any. This is NULL unless the command came from the command-line.
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * One of curclient or cmdclient is always NULL and the other not.
 | 
						 * cmdclient and curclient may both be NULL if the command is in the
 | 
				
			||||||
 | 
						 * configuration file.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	struct client  *curclient;
 | 
						struct client  *curclient;
 | 
				
			||||||
	struct session *cursession;
 | 
						struct session *cursession;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user