mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Three-stage exit process so that [] message printing works on detach etc.
This commit is contained in:
		
							
								
								
									
										16
									
								
								client-msg.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								client-msg.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: client-msg.c,v 1.11 2007-11-27 19:23:33 nicm Exp $ */
 | 
			
		||||
/* $Id: client-msg.c,v 1.12 2007-11-27 20:01:30 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -28,6 +28,7 @@
 | 
			
		||||
int	client_msg_fn_detach(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_error(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_exit(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_exited(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_okay(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
int	client_msg_fn_pause(struct hdr *, struct client_ctx *, char **);
 | 
			
		||||
 | 
			
		||||
@@ -40,6 +41,7 @@ struct client_msg client_msg_table[] = {
 | 
			
		||||
	{ MSG_DETACH, client_msg_fn_detach },
 | 
			
		||||
	{ MSG_ERROR, client_msg_fn_error },
 | 
			
		||||
	{ MSG_EXIT, client_msg_fn_exit },
 | 
			
		||||
	{ MSG_EXITED, client_msg_fn_exited }
 | 
			
		||||
};
 | 
			
		||||
#define NCLIENTMSG (sizeof client_msg_table / sizeof client_msg_table[0])
 | 
			
		||||
 | 
			
		||||
@@ -88,6 +90,18 @@ client_msg_fn_exit(
 | 
			
		||||
	if (hdr->size != 0)
 | 
			
		||||
		fatalx("bad MSG_EXIT size");
 | 
			
		||||
 | 
			
		||||
	client_write_server(cctx, MSG_EXITING, NULL, 0);
 | 
			
		||||
 | 
			
		||||
	return (0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
client_msg_fn_exited(
 | 
			
		||||
    struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
 | 
			
		||||
{
 | 
			
		||||
	if (hdr->size != 0)
 | 
			
		||||
		fatalx("bad MSG_EXITED size");
 | 
			
		||||
 | 
			
		||||
	cctx->flags |= CCTX_EXIT;
 | 
			
		||||
 | 
			
		||||
	return (-1);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								server-msg.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								server-msg.c
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
 | 
			
		||||
/* $Id: server-msg.c,v 1.38 2007-11-27 19:23:34 nicm Exp $ */
 | 
			
		||||
/* $Id: server-msg.c,v 1.39 2007-11-27 20:01:30 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -29,6 +29,7 @@
 | 
			
		||||
int	server_msg_fn_command(struct hdr *, struct client *);
 | 
			
		||||
int	server_msg_fn_identify(struct hdr *, struct client *);
 | 
			
		||||
int	server_msg_fn_resize(struct hdr *, struct client *);
 | 
			
		||||
int	server_msg_fn_exiting(struct hdr *, struct client *);
 | 
			
		||||
 | 
			
		||||
void printflike2 server_msg_fn_command_error(
 | 
			
		||||
    	    struct cmd_ctx *, const char *, ...);
 | 
			
		||||
@@ -44,6 +45,7 @@ const struct server_msg server_msg_table[] = {
 | 
			
		||||
	{ MSG_IDENTIFY, server_msg_fn_identify },
 | 
			
		||||
	{ MSG_COMMAND, server_msg_fn_command },
 | 
			
		||||
	{ MSG_RESIZE, server_msg_fn_resize },
 | 
			
		||||
	{ MSG_EXITING, server_msg_fn_exiting }
 | 
			
		||||
};
 | 
			
		||||
#define NSERVERMSG (sizeof server_msg_table / sizeof server_msg_table[0])
 | 
			
		||||
 | 
			
		||||
@@ -238,3 +240,23 @@ server_msg_fn_resize(struct hdr *hdr, struct client *c)
 | 
			
		||||
 | 
			
		||||
	return (0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
server_msg_fn_exiting(struct hdr *hdr, struct client *c)
 | 
			
		||||
{
 | 
			
		||||
	if (hdr->size != 0)
 | 
			
		||||
		fatalx("bad MSG_EXITING size");
 | 
			
		||||
 | 
			
		||||
	log_debug("exiting msg from client");
 | 
			
		||||
 | 
			
		||||
	c->session = NULL;
 | 
			
		||||
 | 
			
		||||
	if (c->tty.fd != -1)
 | 
			
		||||
		tty_free(&c->tty);
 | 
			
		||||
 | 
			
		||||
	recalculate_sizes();
 | 
			
		||||
 | 
			
		||||
	server_write_client(c, MSG_EXITED, NULL, 0);
 | 
			
		||||
 | 
			
		||||
	return (0);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								server.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								server.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: server.c,v 1.40 2007-11-27 19:23:34 nicm Exp $ */
 | 
			
		||||
/* $Id: server.c,v 1.41 2007-11-27 20:01:30 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -291,7 +291,7 @@ server_handle_clients(struct pollfd **pfd)
 | 
			
		||||
		}
 | 
			
		||||
		(*pfd)++;
 | 
			
		||||
 | 
			
		||||
		if (c != NULL && c->tty.fd != -1) {
 | 
			
		||||
		if (c != NULL && c->tty.fd != -1 && c->session != NULL) {
 | 
			
		||||
			if (buffer_poll(*pfd, c->tty.in, c->tty.out) != 0)
 | 
			
		||||
				server_lost_client(c);
 | 
			
		||||
			else
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: tmux.h,v 1.102 2007-11-27 19:32:15 nicm Exp $ */
 | 
			
		||||
/* $Id: tmux.h,v 1.103 2007-11-27 20:01:30 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -289,6 +289,8 @@ enum hdrtype {
 | 
			
		||||
	MSG_ERROR,
 | 
			
		||||
	MSG_PRINT,
 | 
			
		||||
	MSG_EXIT,
 | 
			
		||||
	MSG_EXITING,
 | 
			
		||||
	MSG_EXITED,
 | 
			
		||||
	MSG_IDENTIFY,
 | 
			
		||||
	MSG_READY,
 | 
			
		||||
	MSG_DETACH,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								tty.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								tty.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
/* $Id: tty.c,v 1.3 2007-11-27 19:43:50 nicm Exp $ */
 | 
			
		||||
/* $Id: tty.c,v 1.4 2007-11-27 20:01:30 nicm Exp $ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
			
		||||
@@ -140,6 +140,8 @@ tty_close(struct tty *tty)
 | 
			
		||||
	tty_keys_free(tty);
 | 
			
		||||
 | 
			
		||||
	close(tty->fd);
 | 
			
		||||
	tty->fd = -1;
 | 
			
		||||
 | 
			
		||||
	buffer_destroy(tty->in);
 | 
			
		||||
	buffer_destroy(tty->out);
 | 
			
		||||
}
 | 
			
		||||
@@ -150,10 +152,14 @@ tty_free(struct tty *tty)
 | 
			
		||||
	if (tty->fd != -1)
 | 
			
		||||
		tty_close(tty);
 | 
			
		||||
 | 
			
		||||
	if (tty->path != NULL)
 | 
			
		||||
	if (tty->path != NULL) {
 | 
			
		||||
		xfree(tty->path);
 | 
			
		||||
	if (tty->term != NULL)
 | 
			
		||||
		tty->path = NULL;
 | 
			
		||||
	}
 | 
			
		||||
	if (tty->term != NULL) {
 | 
			
		||||
		xfree(tty->term);
 | 
			
		||||
		tty->term = NULL;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user