-/* $OpenBSD: log.c,v 1.24 2017/02/04 23:42:53 nicm Exp $ */
+/* $OpenBSD: log.c,v 1.25 2017/06/04 08:25:57 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
if (log_level == 0)
return;
-
- if (log_file != NULL)
- fclose(log_file);
+ log_close();
xasprintf(&path, "tmux-%s-%ld.log", name, (long)getpid());
- log_file = fopen(path, "w");
+ log_file = fopen(path, "a");
free(path);
if (log_file == NULL)
return;
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. */
void
log_close(void)
-/* $OpenBSD: proc.c,v 1.8 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: proc.c,v 1.9 2017/06/04 08:25:57 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
{
peer->flags |= PEER_BAD;
}
+
+void
+proc_toggle_log(struct tmuxproc *tp)
+{
+ log_toggle(tp->name);
+}
-/* $OpenBSD: server.c,v 1.170 2017/04/22 06:13:30 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.171 2017/06/04 08:25:57 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
}
close(pair[0]);
- if (log_get_level() > 3)
+ if (log_get_level() > 1)
tty_create_log();
if (pledge("stdio rpath wpath cpath fattr unix getpw recvfd proc exec "
"tty ps", NULL) != 0)
}
server_add_accept(0);
break;
+ case SIGUSR2:
+ proc_toggle_log(server_proc);
+ break;
}
}
-/* $OpenBSD: signal.c,v 1.10 2016/10/10 21:29:23 nicm Exp $ */
+/* $OpenBSD: signal.c,v 1.11 2017/06/04 08:25:57 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
static struct event ev_sigcont;
static struct event ev_sigterm;
static struct event ev_sigusr1;
+static struct event ev_sigusr2;
static struct event ev_sigwinch;
void
signal_add(&ev_sigterm, NULL);
signal_set(&ev_sigusr1, SIGUSR1, handler, arg);
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_add(&ev_sigwinch, NULL);
}
fatal("sigaction failed");
if (sigaction(SIGUSR1, &sigact, NULL) != 0)
fatal("sigaction failed");
+ if (sigaction(SIGUSR2, &sigact, NULL) != 0)
+ fatal("sigaction failed");
if (sigaction(SIGWINCH, &sigact, NULL) != 0)
fatal("sigaction failed");
} else {
event_del(&ev_sigcont);
event_del(&ev_sigterm);
event_del(&ev_sigusr1);
+ event_del(&ev_sigusr2);
event_del(&ev_sigwinch);
}
}
-.\" $OpenBSD: tmux.1,v 1.557 2017/06/04 08:02:20 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.558 2017/06/04 08:25:57 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
.Ql _ ) .
.It Fl v
Request verbose logging.
-This option may be specified multiple times for increasing verbosity.
Log messages will be saved into
.Pa tmux-client-PID.log
and
files in the current directory, where
.Em PID
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
This specifies one of a set of commands used to control
.Nm ,
-/* $OpenBSD: tmux.h,v 1.779 2017/05/31 11:00:00 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.780 2017/06/04 08:25:57 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
void (*)(struct imsg *, void *), void *);
void proc_remove_peer(struct tmuxpeer *);
void proc_kill_peer(struct tmuxpeer *);
+void proc_toggle_log(struct tmuxproc *);
/* cfg.c */
extern int cfg_finished;
void log_add_level(void);
int log_get_level(void);
void log_open(const char *);
+void log_toggle(const char *);
void log_close(void);
void printflike(1, 2) log_debug(const char *, ...);
__dead void printflike(1, 2) fatal(const char *, ...);