mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Support SIGUSR2 to stop and start logging for an existing server. Also
we currently only have two log levels so just use -v and -vv rather than -v and -vvvv, and clarify the man page entry for -v.
This commit is contained in:
		
							
								
								
									
										21
									
								
								log.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								log.c
									
									
									
									
									
								
							| @@ -62,12 +62,10 @@ log_open(const char *name) | |||||||
|  |  | ||||||
| 	if (log_level == 0) | 	if (log_level == 0) | ||||||
| 		return; | 		return; | ||||||
|  | 	log_close(); | ||||||
| 	if (log_file != NULL) |  | ||||||
| 		fclose(log_file); |  | ||||||
|  |  | ||||||
| 	xasprintf(&path, "tmux-%s-%ld.log", name, (long)getpid()); | 	xasprintf(&path, "tmux-%s-%ld.log", name, (long)getpid()); | ||||||
| 	log_file = fopen(path, "w"); | 	log_file = fopen(path, "a"); | ||||||
| 	free(path); | 	free(path); | ||||||
| 	if (log_file == NULL) | 	if (log_file == NULL) | ||||||
| 		return; | 		return; | ||||||
| @@ -76,6 +74,21 @@ log_open(const char *name) | |||||||
| 	event_set_log_callback(log_event_cb); | 	event_set_log_callback(log_event_cb); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* Toggle logging. */ | ||||||
|  | void | ||||||
|  | log_toggle(const char *name) | ||||||
|  | { | ||||||
|  | 	if (log_level == 0) { | ||||||
|  | 		log_level = 1; | ||||||
|  | 		log_open(name); | ||||||
|  | 		log_debug("log opened"); | ||||||
|  | 	} else { | ||||||
|  | 		log_debug("log closed"); | ||||||
|  | 		log_level = 0; | ||||||
|  | 		log_close(); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| /* Close logging. */ | /* Close logging. */ | ||||||
| void | void | ||||||
| log_close(void) | log_close(void) | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								proc.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								proc.c
									
									
									
									
									
								
							| @@ -265,3 +265,9 @@ proc_kill_peer(struct tmuxpeer *peer) | |||||||
| { | { | ||||||
| 	peer->flags |= PEER_BAD; | 	peer->flags |= PEER_BAD; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void | ||||||
|  | proc_toggle_log(struct tmuxproc *tp) | ||||||
|  | { | ||||||
|  | 	log_toggle(tp->name); | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								server.c
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								server.c
									
									
									
									
									
								
							| @@ -151,7 +151,7 @@ server_start(struct event_base *base, int lockfd, char *lockfile) | |||||||
| 	} | 	} | ||||||
| 	close(pair[0]); | 	close(pair[0]); | ||||||
|  |  | ||||||
| 	if (log_get_level() > 3) | 	if (log_get_level() > 1) | ||||||
| 		tty_create_log(); | 		tty_create_log(); | ||||||
| 	if (pledge("stdio rpath wpath cpath fattr unix getpw recvfd proc exec " | 	if (pledge("stdio rpath wpath cpath fattr unix getpw recvfd proc exec " | ||||||
| 	    "tty ps", NULL) != 0) | 	    "tty ps", NULL) != 0) | ||||||
| @@ -365,6 +365,9 @@ server_signal(int sig) | |||||||
| 		} | 		} | ||||||
| 		server_add_accept(0); | 		server_add_accept(0); | ||||||
| 		break; | 		break; | ||||||
|  | 	case SIGUSR2: | ||||||
|  | 		proc_toggle_log(server_proc); | ||||||
|  | 		break; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								signal.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								signal.c
									
									
									
									
									
								
							| @@ -29,6 +29,7 @@ static struct event	ev_sigchld; | |||||||
| static struct event	ev_sigcont; | static struct event	ev_sigcont; | ||||||
| static struct event	ev_sigterm; | static struct event	ev_sigterm; | ||||||
| static struct event	ev_sigusr1; | static struct event	ev_sigusr1; | ||||||
|  | static struct event	ev_sigusr2; | ||||||
| static struct event	ev_sigwinch; | static struct event	ev_sigwinch; | ||||||
|  |  | ||||||
| void | void | ||||||
| @@ -59,6 +60,8 @@ set_signals(void (*handler)(int, short, void *), void *arg) | |||||||
| 	signal_add(&ev_sigterm, NULL); | 	signal_add(&ev_sigterm, NULL); | ||||||
| 	signal_set(&ev_sigusr1, SIGUSR1, handler, arg); | 	signal_set(&ev_sigusr1, SIGUSR1, handler, arg); | ||||||
| 	signal_add(&ev_sigusr1, NULL); | 	signal_add(&ev_sigusr1, NULL); | ||||||
|  | 	signal_set(&ev_sigusr2, SIGUSR2, handler, arg); | ||||||
|  | 	signal_add(&ev_sigusr2, NULL); | ||||||
| 	signal_set(&ev_sigwinch, SIGWINCH, handler, arg); | 	signal_set(&ev_sigwinch, SIGWINCH, handler, arg); | ||||||
| 	signal_add(&ev_sigwinch, NULL); | 	signal_add(&ev_sigwinch, NULL); | ||||||
| } | } | ||||||
| @@ -92,6 +95,8 @@ clear_signals(int after_fork) | |||||||
| 			fatal("sigaction failed"); | 			fatal("sigaction failed"); | ||||||
| 		if (sigaction(SIGUSR1, &sigact, NULL) != 0) | 		if (sigaction(SIGUSR1, &sigact, NULL) != 0) | ||||||
| 			fatal("sigaction failed"); | 			fatal("sigaction failed"); | ||||||
|  | 		if (sigaction(SIGUSR2, &sigact, NULL) != 0) | ||||||
|  | 			fatal("sigaction failed"); | ||||||
| 		if (sigaction(SIGWINCH, &sigact, NULL) != 0) | 		if (sigaction(SIGWINCH, &sigact, NULL) != 0) | ||||||
| 			fatal("sigaction failed"); | 			fatal("sigaction failed"); | ||||||
| 	} else { | 	} else { | ||||||
| @@ -100,6 +105,7 @@ clear_signals(int after_fork) | |||||||
| 		event_del(&ev_sigcont); | 		event_del(&ev_sigcont); | ||||||
| 		event_del(&ev_sigterm); | 		event_del(&ev_sigterm); | ||||||
| 		event_del(&ev_sigusr1); | 		event_del(&ev_sigusr1); | ||||||
|  | 		event_del(&ev_sigusr2); | ||||||
| 		event_del(&ev_sigwinch); | 		event_del(&ev_sigwinch); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -199,7 +199,6 @@ characters to the terminal it is running (if not, they are replaced by | |||||||
| .Ql _ ) . | .Ql _ ) . | ||||||
| .It Fl v | .It Fl v | ||||||
| Request verbose logging. | Request verbose logging. | ||||||
| This option may be specified multiple times for increasing verbosity. |  | ||||||
| Log messages will be saved into | Log messages will be saved into | ||||||
| .Pa tmux-client-PID.log | .Pa tmux-client-PID.log | ||||||
| and | and | ||||||
| @@ -207,6 +206,22 @@ and | |||||||
| files in the current directory, where | files in the current directory, where | ||||||
| .Em PID | .Em PID | ||||||
| is the PID of the server or client process. | is the PID of the server or client process. | ||||||
|  | .Pp | ||||||
|  | If | ||||||
|  | .Fl v | ||||||
|  | is specified twice, an additional | ||||||
|  | .Pa tmux-out-PID.log | ||||||
|  | file is generated with a copy of everything | ||||||
|  | .Nm | ||||||
|  | writes to the terminal. | ||||||
|  | .Pp | ||||||
|  | The | ||||||
|  | .Dv SIGUSR2 | ||||||
|  | signal may be sent to the | ||||||
|  | .Nm | ||||||
|  | server process to toggle logging between on (as if | ||||||
|  | .Fl v | ||||||
|  | was given) and off. | ||||||
| .It Ar command Op Ar flags | .It Ar command Op Ar flags | ||||||
| This specifies one of a set of commands used to control | This specifies one of a set of commands used to control | ||||||
| .Nm , | .Nm , | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -1493,6 +1493,7 @@ struct tmuxpeer *proc_add_peer(struct tmuxproc *, int, | |||||||
| 	    void (*)(struct imsg *, void *), void *); | 	    void (*)(struct imsg *, void *), void *); | ||||||
| void	proc_remove_peer(struct tmuxpeer *); | void	proc_remove_peer(struct tmuxpeer *); | ||||||
| void	proc_kill_peer(struct tmuxpeer *); | void	proc_kill_peer(struct tmuxpeer *); | ||||||
|  | void	proc_toggle_log(struct tmuxproc *); | ||||||
|  |  | ||||||
| /* cfg.c */ | /* cfg.c */ | ||||||
| extern int cfg_finished; | extern int cfg_finished; | ||||||
| @@ -2336,6 +2337,7 @@ char   *get_proc_name(int, char *); | |||||||
| void	log_add_level(void); | void	log_add_level(void); | ||||||
| int	log_get_level(void); | int	log_get_level(void); | ||||||
| void	log_open(const char *); | void	log_open(const char *); | ||||||
|  | void	log_toggle(const char *); | ||||||
| void	log_close(void); | void	log_close(void); | ||||||
| void printflike(1, 2) log_debug(const char *, ...); | void printflike(1, 2) log_debug(const char *, ...); | ||||||
| __dead void printflike(1, 2) fatal(const char *, ...); | __dead void printflike(1, 2) fatal(const char *, ...); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm