mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Sync OpenBSD patchset 696:
Make signal handler setup/teardown two common functions instead of six, and reset SIGCHLD after fork to fix problems with some shells. From Romain Francoise.
This commit is contained in:
		
							
								
								
									
										27
									
								
								client.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								client.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: client.c,v 1.90 2009-12-04 22:14:47 tcunha Exp $ */
 | 
					/* $Id: client.c,v 1.91 2010-05-14 14:30:00 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -176,35 +176,12 @@ client_update_event(void)
 | 
				
			|||||||
__dead void
 | 
					__dead void
 | 
				
			||||||
client_main(void)
 | 
					client_main(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct event		ev_sigcont, ev_sigterm, ev_sigwinch;
 | 
					 | 
				
			||||||
	struct sigaction	sigact;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	logfile("client");
 | 
						logfile("client");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Note: event_init() has already been called. */
 | 
						/* Note: event_init() has already been called. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set up signals. */
 | 
						/* Set up signals. */
 | 
				
			||||||
	memset(&sigact, 0, sizeof sigact);
 | 
						set_signals(client_signal);
 | 
				
			||||||
	sigemptyset(&sigact.sa_mask);
 | 
					 | 
				
			||||||
	sigact.sa_flags = SA_RESTART;
 | 
					 | 
				
			||||||
	sigact.sa_handler = SIG_IGN;
 | 
					 | 
				
			||||||
	if (sigaction(SIGINT, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGPIPE, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR1, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR2, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGTSTP, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	signal_set(&ev_sigcont, SIGCONT, client_signal, NULL);
 | 
					 | 
				
			||||||
	signal_add(&ev_sigcont, NULL);
 | 
					 | 
				
			||||||
	signal_set(&ev_sigterm, SIGTERM, client_signal, NULL);
 | 
					 | 
				
			||||||
	signal_add(&ev_sigterm, NULL);
 | 
					 | 
				
			||||||
	signal_set(&ev_sigwinch, SIGWINCH, client_signal, NULL);
 | 
					 | 
				
			||||||
	signal_add(&ev_sigwinch, NULL);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * imsg_read in the first client poll loop (before the terminal has
 | 
						 * imsg_read in the first client poll loop (before the terminal has
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: cmd-pipe-pane.c,v 1.10 2009-12-04 22:14:47 tcunha Exp $ */
 | 
					/* $Id: cmd-pipe-pane.c,v 1.11 2010-05-14 14:30:01 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -90,7 +90,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	case 0:
 | 
						case 0:
 | 
				
			||||||
		/* Child process. */
 | 
							/* Child process. */
 | 
				
			||||||
		close(pipe_fd[0]);
 | 
							close(pipe_fd[0]);
 | 
				
			||||||
		server_signal_clear();
 | 
							clear_signals();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
 | 
							if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
 | 
				
			||||||
			_exit(1);
 | 
								_exit(1);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								job.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								job.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: job.c,v 1.16 2010-04-06 21:59:19 nicm Exp $ */
 | 
					/* $Id: job.c,v 1.17 2010-05-14 14:30:01 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -148,7 +148,7 @@ job_run(struct job *job)
 | 
				
			|||||||
	case -1:
 | 
						case -1:
 | 
				
			||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
	case 0:		/* child */
 | 
						case 0:		/* child */
 | 
				
			||||||
		server_signal_clear();
 | 
							clear_signals();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		environ_push(&global_environ);
 | 
							environ_push(&global_environ);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										68
									
								
								server.c
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								server.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: server.c,v 1.239 2010-04-08 07:54:43 nicm Exp $ */
 | 
					/* $Id: server.c,v 1.240 2010-05-14 14:30:01 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -48,9 +48,6 @@ struct clients	 dead_clients;
 | 
				
			|||||||
int		 server_fd;
 | 
					int		 server_fd;
 | 
				
			||||||
int		 server_shutdown;
 | 
					int		 server_shutdown;
 | 
				
			||||||
struct event	 server_ev_accept;
 | 
					struct event	 server_ev_accept;
 | 
				
			||||||
struct event	 server_ev_sigterm;
 | 
					 | 
				
			||||||
struct event	 server_ev_sigusr1;
 | 
					 | 
				
			||||||
struct event	 server_ev_sigchld;
 | 
					 | 
				
			||||||
struct event	 server_ev_second;
 | 
					struct event	 server_ev_second;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int		 server_create_socket(void);
 | 
					int		 server_create_socket(void);
 | 
				
			||||||
@@ -143,6 +140,11 @@ server_start(char *path)
 | 
				
			|||||||
	if (daemon(1, 0) != 0)
 | 
						if (daemon(1, 0) != 0)
 | 
				
			||||||
		fatal("daemon failed");
 | 
							fatal("daemon failed");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* event_init() was called in our parent, need to reinit. */
 | 
				
			||||||
 | 
						if (event_reinit(ev_base) != 0)
 | 
				
			||||||
 | 
							fatal("event_reinit failed");
 | 
				
			||||||
 | 
						clear_signals();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	logfile("server");
 | 
						logfile("server");
 | 
				
			||||||
	log_debug("server started, pid %ld", (long) getpid());
 | 
						log_debug("server started, pid %ld", (long) getpid());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -174,7 +176,6 @@ server_start(char *path)
 | 
				
			|||||||
	if (setenv("EVENT_NOPOLL", "1", 1) != 0)
 | 
						if (setenv("EVENT_NOPOLL", "1", 1) != 0)
 | 
				
			||||||
		fatal("setenv failed");
 | 
							fatal("setenv failed");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	event_init();
 | 
					 | 
				
			||||||
#ifdef HAVE_BROKEN_KQUEUE
 | 
					#ifdef HAVE_BROKEN_KQUEUE
 | 
				
			||||||
	unsetenv("EVENT_NOKQUEUE");
 | 
						unsetenv("EVENT_NOKQUEUE");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -220,7 +221,7 @@ server_start(char *path)
 | 
				
			|||||||
	evtimer_set(&server_ev_second, server_second_callback, NULL);
 | 
						evtimer_set(&server_ev_second, server_second_callback, NULL);
 | 
				
			||||||
	evtimer_add(&server_ev_second, &tv);
 | 
						evtimer_add(&server_ev_second, &tv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	server_signal_set();
 | 
						set_signals(server_signal_callback);
 | 
				
			||||||
	server_loop();
 | 
						server_loop();
 | 
				
			||||||
	exit(0);
 | 
						exit(0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -359,61 +360,6 @@ server_accept_callback(int fd, short events, unused void *data)
 | 
				
			|||||||
	server_client_create(newfd);
 | 
						server_client_create(newfd);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Set up server signal handling. */
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
server_signal_set(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct sigaction	 sigact;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	memset(&sigact, 0, sizeof sigact);
 | 
					 | 
				
			||||||
	sigemptyset(&sigact.sa_mask);
 | 
					 | 
				
			||||||
	sigact.sa_flags = SA_RESTART;
 | 
					 | 
				
			||||||
	sigact.sa_handler = SIG_IGN;
 | 
					 | 
				
			||||||
	if (sigaction(SIGINT, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGPIPE, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR2, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGTSTP, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGHUP, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	signal_set(&server_ev_sigchld, SIGCHLD, server_signal_callback, NULL);
 | 
					 | 
				
			||||||
	signal_add(&server_ev_sigchld, NULL);
 | 
					 | 
				
			||||||
	signal_set(&server_ev_sigterm, SIGTERM, server_signal_callback, NULL);
 | 
					 | 
				
			||||||
	signal_add(&server_ev_sigterm, NULL);
 | 
					 | 
				
			||||||
	signal_set(&server_ev_sigusr1, SIGUSR1, server_signal_callback, NULL);
 | 
					 | 
				
			||||||
	signal_add(&server_ev_sigusr1, NULL);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Destroy server signal events. */
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
server_signal_clear(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct sigaction	 sigact;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	memset(&sigact, 0, sizeof sigact);
 | 
					 | 
				
			||||||
	sigemptyset(&sigact.sa_mask);
 | 
					 | 
				
			||||||
	sigact.sa_flags = SA_RESTART;
 | 
					 | 
				
			||||||
	sigact.sa_handler = SIG_DFL;
 | 
					 | 
				
			||||||
	if (sigaction(SIGINT, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGPIPE, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR2, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGTSTP, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGHUP, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	signal_del(&server_ev_sigchld);
 | 
					 | 
				
			||||||
	signal_del(&server_ev_sigterm);
 | 
					 | 
				
			||||||
	signal_del(&server_ev_sigusr1);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Signal handler. */
 | 
					/* Signal handler. */
 | 
				
			||||||
/* ARGSUSED */
 | 
					/* ARGSUSED */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										88
									
								
								signal.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								signal.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					/* $Id: signal.c,v 1.1 2010-05-14 14:30:01 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
 | 
					 * Copyright (c) 2010 Romain Francoise <rfrancoise@debian.org>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Permission to use, copy, modify, and distribute this software for any
 | 
				
			||||||
 | 
					 * purpose with or without fee is hereby granted, provided that the above
 | 
				
			||||||
 | 
					 * copyright notice and this permission notice appear in all copies.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 | 
				
			||||||
 | 
					 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 | 
				
			||||||
 | 
					 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 | 
				
			||||||
 | 
					 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
 | 
				
			||||||
 | 
					 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 | 
				
			||||||
 | 
					 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <signal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "tmux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct event	ev_sigchld;
 | 
				
			||||||
 | 
					struct event	ev_sigcont;
 | 
				
			||||||
 | 
					struct event	ev_sigterm;
 | 
				
			||||||
 | 
					struct event	ev_sigusr1;
 | 
				
			||||||
 | 
					struct event	ev_sigwinch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					set_signals(void(*handler)(int, short, unused void *))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sigaction	sigact;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(&sigact, 0, sizeof sigact);
 | 
				
			||||||
 | 
						sigemptyset(&sigact.sa_mask);
 | 
				
			||||||
 | 
						sigact.sa_flags = SA_RESTART;
 | 
				
			||||||
 | 
						sigact.sa_handler = SIG_IGN;
 | 
				
			||||||
 | 
						if (sigaction(SIGINT, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGPIPE, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGUSR2, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGTSTP, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGHUP, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						signal_set(&ev_sigchld, SIGCHLD, handler, NULL);
 | 
				
			||||||
 | 
						signal_add(&ev_sigchld, NULL);
 | 
				
			||||||
 | 
						signal_set(&ev_sigcont, SIGCONT, handler, NULL);
 | 
				
			||||||
 | 
						signal_add(&ev_sigcont, NULL);
 | 
				
			||||||
 | 
						signal_set(&ev_sigterm, SIGTERM, handler, NULL);
 | 
				
			||||||
 | 
						signal_add(&ev_sigterm, NULL);
 | 
				
			||||||
 | 
						signal_set(&ev_sigusr1, SIGUSR1, handler, NULL);
 | 
				
			||||||
 | 
						signal_add(&ev_sigusr1, NULL);
 | 
				
			||||||
 | 
						signal_set(&ev_sigwinch, SIGWINCH, handler, NULL);
 | 
				
			||||||
 | 
						signal_add(&ev_sigwinch, NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					clear_signals(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sigaction	sigact;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(&sigact, 0, sizeof sigact);
 | 
				
			||||||
 | 
						sigemptyset(&sigact.sa_mask);
 | 
				
			||||||
 | 
						sigact.sa_flags = SA_RESTART;
 | 
				
			||||||
 | 
						sigact.sa_handler = SIG_DFL;
 | 
				
			||||||
 | 
						if (sigaction(SIGINT, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGPIPE, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGUSR2, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGTSTP, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
						if (sigaction(SIGHUP, &sigact, NULL) != 0)
 | 
				
			||||||
 | 
							fatal("sigaction failed");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						event_del(&ev_sigchld);
 | 
				
			||||||
 | 
						event_del(&ev_sigcont);
 | 
				
			||||||
 | 
						event_del(&ev_sigterm);
 | 
				
			||||||
 | 
						event_del(&ev_sigusr1);
 | 
				
			||||||
 | 
						event_del(&ev_sigwinch);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										76
									
								
								tmux.c
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								tmux.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: tmux.c,v 1.206 2010-05-14 14:18:54 tcunha Exp $ */
 | 
					/* $Id: tmux.c,v 1.207 2010-05-14 14:30:01 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -18,6 +18,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
 | 
					#include <sys/wait.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <errno.h>
 | 
					#include <errno.h>
 | 
				
			||||||
#include <event.h>
 | 
					#include <event.h>
 | 
				
			||||||
@@ -40,6 +41,8 @@ struct options	 global_s_options;	/* session options */
 | 
				
			|||||||
struct options	 global_w_options;	/* window options */
 | 
					struct options	 global_w_options;	/* window options */
 | 
				
			||||||
struct environ	 global_environ;
 | 
					struct environ	 global_environ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct event_base *ev_base;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int		 debug_level;
 | 
					int		 debug_level;
 | 
				
			||||||
time_t		 start_time;
 | 
					time_t		 start_time;
 | 
				
			||||||
char		*socket_path;
 | 
					char		*socket_path;
 | 
				
			||||||
@@ -57,11 +60,8 @@ 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;
 | 
				
			||||||
struct event	 main_ev_sigterm;
 | 
					 | 
				
			||||||
int	         main_exitval;
 | 
					int	         main_exitval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void		 main_set_signals(void);
 | 
					 | 
				
			||||||
void		 main_clear_signals(void);
 | 
					 | 
				
			||||||
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 *);
 | 
				
			||||||
void		 main_dispatch(const char *);
 | 
					void		 main_dispatch(const char *);
 | 
				
			||||||
@@ -241,7 +241,6 @@ main(int argc, char **argv)
 | 
				
			|||||||
	struct keylist		*keylist;
 | 
						struct keylist		*keylist;
 | 
				
			||||||
	struct env_data		 envdata;
 | 
						struct env_data		 envdata;
 | 
				
			||||||
	struct msg_command_data	 cmddata;
 | 
						struct msg_command_data	 cmddata;
 | 
				
			||||||
	struct sigaction	 sigact;
 | 
					 | 
				
			||||||
	char			*s, *shellcmd, *path, *label, *home, *cause;
 | 
						char			*s, *shellcmd, *path, *label, *home, *cause;
 | 
				
			||||||
	char			 cwd[MAXPATHLEN], **var;
 | 
						char			 cwd[MAXPATHLEN], **var;
 | 
				
			||||||
	void			*buf;
 | 
						void			*buf;
 | 
				
			||||||
@@ -541,12 +540,8 @@ main(int argc, char **argv)
 | 
				
			|||||||
		exit(1);
 | 
							exit(1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Catch SIGCHLD to avoid a zombie when starting the server. */
 | 
						ev_base = event_init();
 | 
				
			||||||
	memset(&sigact, 0, sizeof sigact);
 | 
						set_signals(main_signal);
 | 
				
			||||||
	sigemptyset(&sigact.sa_mask);
 | 
					 | 
				
			||||||
	sigact.sa_handler = SIG_IGN;
 | 
					 | 
				
			||||||
	if (sigaction(SIGCHLD, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Initialise the client socket/start the server. */
 | 
						/* Initialise the client socket/start the server. */
 | 
				
			||||||
	if ((main_ibuf = client_init(path, cmdflags, flags)) == NULL)
 | 
						if ((main_ibuf = client_init(path, cmdflags, flags)) == NULL)
 | 
				
			||||||
@@ -561,7 +556,6 @@ main(int argc, char **argv)
 | 
				
			|||||||
	if (setenv("EVENT_NOPOLL", "1", 1) != 0)
 | 
						if (setenv("EVENT_NOPOLL", "1", 1) != 0)
 | 
				
			||||||
		fatal("setenv failed");
 | 
							fatal("setenv failed");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	event_init();
 | 
					 | 
				
			||||||
#ifdef HAVE_BROKEN_KQUEUE
 | 
					#ifdef HAVE_BROKEN_KQUEUE
 | 
				
			||||||
	unsetenv("EVENT_NOKQUEUE");
 | 
						unsetenv("EVENT_NOKQUEUE");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -571,8 +565,6 @@ main(int argc, char **argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	imsg_compose(main_ibuf, msg, PROTOCOL_VERSION, -1, -1, buf, len);
 | 
						imsg_compose(main_ibuf, msg, PROTOCOL_VERSION, -1, -1, buf, len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	main_set_signals();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	events = EV_READ;
 | 
						events = EV_READ;
 | 
				
			||||||
	if (main_ibuf->w.queued > 0)
 | 
						if (main_ibuf->w.queued > 0)
 | 
				
			||||||
		events |= EV_WRITE;
 | 
							events |= EV_WRITE;
 | 
				
			||||||
@@ -581,65 +573,23 @@ main(int argc, char **argv)
 | 
				
			|||||||
	main_exitval = 0;
 | 
						main_exitval = 0;
 | 
				
			||||||
	event_dispatch();
 | 
						event_dispatch();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	main_clear_signals();
 | 
						clear_signals();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	client_main();	/* doesn't return */
 | 
						client_main();	/* doesn't return */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					 | 
				
			||||||
main_set_signals(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct sigaction	sigact;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	memset(&sigact, 0, sizeof sigact);
 | 
					 | 
				
			||||||
	sigemptyset(&sigact.sa_mask);
 | 
					 | 
				
			||||||
	sigact.sa_flags = SA_RESTART;
 | 
					 | 
				
			||||||
	sigact.sa_handler = SIG_IGN;
 | 
					 | 
				
			||||||
	if (sigaction(SIGINT, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGPIPE, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR1, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR2, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGTSTP, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	signal_set(&main_ev_sigterm, SIGTERM, main_signal, NULL);
 | 
					 | 
				
			||||||
	signal_add(&main_ev_sigterm, NULL);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					 | 
				
			||||||
main_clear_signals(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct sigaction	sigact;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	memset(&sigact, 0, sizeof sigact);
 | 
					 | 
				
			||||||
	sigemptyset(&sigact.sa_mask);
 | 
					 | 
				
			||||||
	sigact.sa_flags = SA_RESTART;
 | 
					 | 
				
			||||||
	sigact.sa_handler = SIG_DFL;
 | 
					 | 
				
			||||||
	if (sigaction(SIGINT, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGPIPE, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR1, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGUSR2, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
	if (sigaction(SIGTSTP, &sigact, NULL) != 0)
 | 
					 | 
				
			||||||
		fatal("sigaction failed");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	event_del(&main_ev_sigterm);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ARGSUSED */
 | 
					/* ARGSUSED */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
main_signal(int sig, unused short events, unused void *data)
 | 
					main_signal(int sig, unused short events, unused void *data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						int	status;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (sig) {
 | 
						switch (sig) {
 | 
				
			||||||
	case SIGTERM:
 | 
						case SIGTERM:
 | 
				
			||||||
		exit(1);
 | 
							exit(1);
 | 
				
			||||||
 | 
						case SIGCHLD:
 | 
				
			||||||
 | 
							waitpid(WAIT_ANY, &status, WNOHANG);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -718,7 +668,7 @@ main_dispatch(const char *shellcmd)
 | 
				
			|||||||
			memcpy(&shelldata, imsg.data, sizeof shelldata);
 | 
								memcpy(&shelldata, imsg.data, sizeof shelldata);
 | 
				
			||||||
			shelldata.shell[(sizeof shelldata.shell) - 1] = '\0';
 | 
								shelldata.shell[(sizeof shelldata.shell) - 1] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			main_clear_signals();
 | 
								clear_signals();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			shell_exec(shelldata.shell, shellcmd);
 | 
								shell_exec(shelldata.shell, shellcmd);
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: tmux.h,v 1.555 2010-04-06 21:59:19 nicm Exp $ */
 | 
					/* $Id: tmux.h,v 1.556 2010-05-14 14:30:01 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -1252,6 +1252,7 @@ extern struct options global_options;
 | 
				
			|||||||
extern struct options global_s_options;
 | 
					extern struct options global_s_options;
 | 
				
			||||||
extern struct options global_w_options;
 | 
					extern struct options global_w_options;
 | 
				
			||||||
extern struct environ global_environ;
 | 
					extern struct environ global_environ;
 | 
				
			||||||
 | 
					extern struct event_base *ev_base;
 | 
				
			||||||
extern char	*cfg_file;
 | 
					extern char	*cfg_file;
 | 
				
			||||||
extern int	 debug_level;
 | 
					extern int	 debug_level;
 | 
				
			||||||
extern int	 be_quiet;
 | 
					extern int	 be_quiet;
 | 
				
			||||||
@@ -1582,8 +1583,6 @@ const char *key_string_lookup_key(int);
 | 
				
			|||||||
extern struct clients clients;
 | 
					extern struct clients clients;
 | 
				
			||||||
extern struct clients dead_clients;
 | 
					extern struct clients dead_clients;
 | 
				
			||||||
int	 server_start(char *);
 | 
					int	 server_start(char *);
 | 
				
			||||||
void	 server_signal_set(void);
 | 
					 | 
				
			||||||
void	 server_signal_clear(void);
 | 
					 | 
				
			||||||
void	 server_update_socket(void);
 | 
					void	 server_update_socket(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* server-client.c */
 | 
					/* server-client.c */
 | 
				
			||||||
@@ -1899,6 +1898,10 @@ void		 window_choose_ready(struct window_pane *,
 | 
				
			|||||||
void		 queue_window_name(struct window *);
 | 
					void		 queue_window_name(struct window *);
 | 
				
			||||||
char		*default_window_name(struct window *);
 | 
					char		*default_window_name(struct window *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* signal.c */
 | 
				
			||||||
 | 
					void set_signals(void(*handler)(int, short, unused void *));
 | 
				
			||||||
 | 
					void clear_signals(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* session.c */
 | 
					/* session.c */
 | 
				
			||||||
extern struct sessions sessions;
 | 
					extern struct sessions sessions;
 | 
				
			||||||
extern struct sessions dead_sessions;
 | 
					extern struct sessions dead_sessions;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								window.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: window.c,v 1.130 2010-04-06 21:59:19 nicm Exp $ */
 | 
					/* $Id: window.c,v 1.131 2010-05-14 14:30:01 tcunha Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -527,7 +527,7 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		environ_push(env);
 | 
							environ_push(env);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		server_signal_clear();
 | 
							clear_signals();
 | 
				
			||||||
		log_close();
 | 
							log_close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (*wp->cmd != '\0') {
 | 
							if (*wp->cmd != '\0') {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user