mirror of
https://github.com/tmux/tmux.git
synced 2025-04-09 02:18:48 +00:00
Merge branch 'obsd-master'
This commit is contained in:
commit
486421ceff
@ -135,7 +135,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
||||
c->session = s;
|
||||
status_timer_start(c);
|
||||
notify_attached_session_changed(c);
|
||||
session_update_activity(s);
|
||||
session_update_activity(s, NULL);
|
||||
server_redraw_client(c);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
} else {
|
||||
@ -180,7 +180,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
|
||||
c->session = s;
|
||||
status_timer_start(c);
|
||||
notify_attached_session_changed(c);
|
||||
session_update_activity(s);
|
||||
session_update_activity(s, NULL);
|
||||
server_redraw_client(c);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
|
||||
|
@ -277,7 +277,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
c->session = s;
|
||||
status_timer_start(c);
|
||||
notify_attached_session_changed(c);
|
||||
session_update_activity(s);
|
||||
session_update_activity(s, NULL);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
@ -176,7 +176,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Start or stop timers when name or status options changed. */
|
||||
/* Start or stop timers if necessary. */
|
||||
if (strcmp(oe->name, "automatic-rename") == 0) {
|
||||
RB_FOREACH(w, windows, &windows) {
|
||||
if (options_get_number(&w->options, "automatic-rename"))
|
||||
|
@ -128,7 +128,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
c->last_session = c->session;
|
||||
c->session = s;
|
||||
status_timer_start(c);
|
||||
session_update_activity(s);
|
||||
session_update_activity(s, NULL);
|
||||
|
||||
recalculate_sizes();
|
||||
server_check_unattached();
|
||||
|
8
names.c
8
names.c
@ -50,10 +50,6 @@ window_name_callback(unused int fd, unused short events, void *data)
|
||||
if (w->active == NULL)
|
||||
return;
|
||||
|
||||
if (~w->active->flags & PANE_CHANGED)
|
||||
return;
|
||||
w->active->flags &= ~PANE_CHANGED;
|
||||
|
||||
if (!options_get_number(&w->options, "automatic-rename")) {
|
||||
if (event_initialized(&w->name_timer))
|
||||
event_del(&w->name_timer);
|
||||
@ -61,6 +57,10 @@ window_name_callback(unused int fd, unused short events, void *data)
|
||||
}
|
||||
queue_window_name(w);
|
||||
|
||||
if (~w->active->flags & PANE_CHANGED)
|
||||
return;
|
||||
w->active->flags &= ~PANE_CHANGED;
|
||||
|
||||
name = format_window_name(w);
|
||||
if (strcmp(name, w->name) != 0) {
|
||||
window_set_name(w, name);
|
||||
|
@ -560,9 +560,7 @@ server_client_handle_key(struct client *c, int key)
|
||||
/* Update the activity timer. */
|
||||
if (gettimeofday(&c->activity_time, NULL) != 0)
|
||||
fatal("gettimeofday failed");
|
||||
memcpy(&s->last_activity_time, &s->activity_time,
|
||||
sizeof s->last_activity_time);
|
||||
memcpy(&s->activity_time, &c->activity_time, sizeof s->activity_time);
|
||||
session_update_activity(s, &c->activity_time);
|
||||
|
||||
/* Number keys jump to pane in identify mode. */
|
||||
if (c->flags & CLIENT_IDENTIFY && key >= '0' && key <= '9') {
|
||||
@ -990,6 +988,7 @@ server_client_msg_dispatch(struct client *c)
|
||||
struct msg_stdin_data stdindata;
|
||||
const char *data;
|
||||
ssize_t n, datalen;
|
||||
struct session *s;
|
||||
|
||||
if ((n = imsg_read(&c->ibuf)) == -1 || n == 0)
|
||||
return (-1);
|
||||
@ -1073,11 +1072,12 @@ server_client_msg_dispatch(struct client *c)
|
||||
|
||||
if (c->tty.fd == -1) /* exited in the meantime */
|
||||
break;
|
||||
s = c->session;
|
||||
|
||||
if (gettimeofday(&c->activity_time, NULL) != 0)
|
||||
fatal("gettimeofday");
|
||||
if (c->session != NULL)
|
||||
session_update_activity(c->session);
|
||||
if (s != NULL)
|
||||
session_update_activity(s, &c->activity_time);
|
||||
|
||||
tty_start_tty(&c->tty);
|
||||
server_redraw_client(c);
|
||||
|
@ -424,7 +424,7 @@ server_destroy_session(struct session *s)
|
||||
c->session = s_new;
|
||||
status_timer_start(c);
|
||||
notify_attached_session_changed(c);
|
||||
session_update_activity(s_new);
|
||||
session_update_activity(s_new, NULL);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
}
|
||||
|
47
server.c
47
server.c
@ -45,7 +45,6 @@ struct clients clients;
|
||||
int server_fd;
|
||||
int server_shutdown;
|
||||
struct event server_ev_accept;
|
||||
struct event server_ev_second;
|
||||
|
||||
struct session *marked_session;
|
||||
struct winlink *marked_winlink;
|
||||
@ -62,8 +61,6 @@ void server_signal_callback(int, short, void *);
|
||||
void server_child_signal(void);
|
||||
void server_child_exited(pid_t, int);
|
||||
void server_child_stopped(pid_t, int);
|
||||
void server_second_callback(int, short, void *);
|
||||
void server_lock_sessions(void);
|
||||
|
||||
/* Set marked pane. */
|
||||
void
|
||||
@ -162,9 +159,8 @@ server_create_socket(void)
|
||||
int
|
||||
server_start(int lockfd, char *lockfile)
|
||||
{
|
||||
int pair[2];
|
||||
struct timeval tv;
|
||||
char *cause;
|
||||
int pair[2];
|
||||
char *cause;
|
||||
|
||||
/* The first client is special and gets a socketpair; create it. */
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
|
||||
@ -244,11 +240,6 @@ server_start(int lockfd, char *lockfile)
|
||||
|
||||
server_add_accept(0);
|
||||
|
||||
memset(&tv, 0, sizeof tv);
|
||||
tv.tv_sec = 1;
|
||||
evtimer_set(&server_ev_second, server_second_callback, NULL);
|
||||
evtimer_add(&server_ev_second, &tv);
|
||||
|
||||
set_signals(server_signal_callback);
|
||||
server_loop();
|
||||
status_prompt_save_history();
|
||||
@ -499,37 +490,3 @@ server_child_stopped(pid_t pid, int status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle once-per-second timer events. */
|
||||
void
|
||||
server_second_callback(unused int fd, unused short events, unused void *arg)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
server_lock_sessions();
|
||||
|
||||
evtimer_del(&server_ev_second);
|
||||
memset(&tv, 0, sizeof tv);
|
||||
tv.tv_sec = 1;
|
||||
evtimer_add(&server_ev_second, &tv);
|
||||
}
|
||||
|
||||
/* Lock any sessions which have timed out. */
|
||||
void
|
||||
server_lock_sessions(void)
|
||||
{
|
||||
struct session *s;
|
||||
int timeout;
|
||||
time_t t;
|
||||
|
||||
t = time(NULL);
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
if (s->flags & SESSION_UNATTACHED)
|
||||
continue;
|
||||
timeout = options_get_number(&s->options, "lock-after-time");
|
||||
if (timeout > 0 && t > s->activity_time.tv_sec + timeout) {
|
||||
server_lock_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
session.c
65
session.c
@ -32,6 +32,8 @@ struct session_groups session_groups;
|
||||
|
||||
void session_free(int, short, void *);
|
||||
|
||||
void session_lock_timer(int, short, void *);
|
||||
|
||||
struct winlink *session_next_alert(struct winlink *);
|
||||
struct winlink *session_previous_alert(struct winlink *);
|
||||
|
||||
@ -107,14 +109,10 @@ session_create(const char *name, int argc, char **argv, const char *path,
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
|
||||
s = xmalloc(sizeof *s);
|
||||
s = xcalloc(1, sizeof *s);
|
||||
s->references = 1;
|
||||
s->flags = 0;
|
||||
|
||||
if (gettimeofday(&s->creation_time, NULL) != 0)
|
||||
fatal("gettimeofday failed");
|
||||
session_update_activity(s);
|
||||
|
||||
s->cwd = dup(cwd);
|
||||
|
||||
s->curw = NULL;
|
||||
@ -132,6 +130,10 @@ session_create(const char *name, int argc, char **argv, const char *path,
|
||||
memcpy(s->tio, tio, sizeof *s->tio);
|
||||
}
|
||||
|
||||
if (gettimeofday(&s->creation_time, NULL) != 0)
|
||||
fatal("gettimeofday failed");
|
||||
session_update_activity(s, &s->creation_time);
|
||||
|
||||
s->sx = sx;
|
||||
s->sy = sy;
|
||||
|
||||
@ -148,6 +150,10 @@ session_create(const char *name, int argc, char **argv, const char *path,
|
||||
}
|
||||
RB_INSERT(sessions, &sessions, s);
|
||||
|
||||
if (gettimeofday(&s->creation_time, NULL) != 0)
|
||||
fatal("gettimeofday failed");
|
||||
session_update_activity(s, &s->creation_time);
|
||||
|
||||
if (argc >= 0) {
|
||||
wl = session_new(s, NULL, argc, argv, path, cwd, idx, cause);
|
||||
if (wl == NULL) {
|
||||
@ -182,8 +188,10 @@ session_free(unused int fd, unused short events, void *arg)
|
||||
|
||||
log_debug("sesson %s freed (%d references)", s->name, s->references);
|
||||
|
||||
if (s->references == 0)
|
||||
if (s->references == 0) {
|
||||
free(s->name);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Destroy a session. */
|
||||
@ -199,6 +207,9 @@ session_destroy(struct session *s)
|
||||
|
||||
free(s->tio);
|
||||
|
||||
if (event_initialized(&s->lock_timer))
|
||||
event_del(&s->lock_timer);
|
||||
|
||||
session_group_remove(s);
|
||||
environ_free(&s->environ);
|
||||
options_free(&s->options);
|
||||
@ -223,12 +234,46 @@ session_check_name(const char *name)
|
||||
return (*name != '\0' && name[strcspn(name, ":.")] == '\0');
|
||||
}
|
||||
|
||||
/* Update session active time. */
|
||||
/* Lock session if it has timed out. */
|
||||
void
|
||||
session_update_activity(struct session *s)
|
||||
session_lock_timer(unused int fd, unused short events, void *arg)
|
||||
{
|
||||
if (gettimeofday(&s->activity_time, NULL) != 0)
|
||||
fatal("gettimeofday");
|
||||
struct session *s = arg;
|
||||
|
||||
if (s->flags & SESSION_UNATTACHED)
|
||||
return;
|
||||
|
||||
log_debug("session %s locked, activity time %lld", s->name,
|
||||
(long long)s->activity_time.tv_sec);
|
||||
|
||||
server_lock_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
|
||||
/* Update activity time. */
|
||||
void
|
||||
session_update_activity(struct session *s, struct timeval *from)
|
||||
{
|
||||
struct timeval *last = &s->last_activity_time;
|
||||
struct timeval tv;
|
||||
|
||||
memcpy(last, &s->activity_time, sizeof *last);
|
||||
if (from == NULL)
|
||||
gettimeofday(&s->activity_time, NULL);
|
||||
else
|
||||
memcpy(&s->activity_time, from, sizeof s->activity_time);
|
||||
|
||||
if (evtimer_initialized(&s->lock_timer))
|
||||
evtimer_del(&s->lock_timer);
|
||||
else
|
||||
evtimer_set(&s->lock_timer, session_lock_timer, s);
|
||||
|
||||
if (~s->flags & SESSION_UNATTACHED) {
|
||||
timerclear(&tv);
|
||||
tv.tv_sec = options_get_number(&s->options, "lock-after-time");
|
||||
if (tv.tv_sec != 0)
|
||||
evtimer_add(&s->lock_timer, &tv);
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the next usable session. */
|
||||
|
4
tmux.h
4
tmux.h
@ -997,6 +997,8 @@ struct session {
|
||||
struct timeval activity_time;
|
||||
struct timeval last_activity_time;
|
||||
|
||||
struct event lock_timer;
|
||||
|
||||
u_int sx;
|
||||
u_int sy;
|
||||
|
||||
@ -2252,7 +2254,7 @@ struct session *session_create(const char *, int, char **, const char *,
|
||||
void session_destroy(struct session *);
|
||||
void session_unref(struct session *);
|
||||
int session_check_name(const char *);
|
||||
void session_update_activity(struct session *);
|
||||
void session_update_activity(struct session *, struct timeval *);
|
||||
struct session *session_next_session(struct session *);
|
||||
struct session *session_previous_session(struct session *);
|
||||
struct winlink *session_new(struct session *, const char *, int, char **,
|
||||
|
Loading…
Reference in New Issue
Block a user