1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Similarly, for sessions use a callback to free rather than checking

every loop.
This commit is contained in:
nicm 2015-06-05 18:18:32 +00:00
parent 10e90ae01f
commit 641a9cd3f5
5 changed files with 32 additions and 28 deletions

View File

@ -123,7 +123,7 @@ notify_drain(void)
if (ne->client != NULL) if (ne->client != NULL)
server_client_unref(ne->client); server_client_unref(ne->client);
if (ne->session != NULL) if (ne->session != NULL)
ne->session->references--; session_unref(ne->session);
if (ne->window != NULL) if (ne->window != NULL)
window_remove_ref(ne->window); window_remove_ref(ne->window);

View File

@ -58,7 +58,6 @@ int server_create_socket(void);
void server_loop(void); void server_loop(void);
int server_should_shutdown(void); int server_should_shutdown(void);
void server_send_shutdown(void); void server_send_shutdown(void);
void server_clean_dead(void);
void server_accept_callback(int, short, void *); void server_accept_callback(int, short, void *);
void server_signal_callback(int, short, void *); void server_signal_callback(int, short, void *);
void server_child_signal(void); void server_child_signal(void);
@ -204,7 +203,6 @@ server_start(int lockfd, char *lockfile)
RB_INIT(&all_window_panes); RB_INIT(&all_window_panes);
TAILQ_INIT(&clients); TAILQ_INIT(&clients);
RB_INIT(&sessions); RB_INIT(&sessions);
RB_INIT(&dead_sessions);
TAILQ_INIT(&session_groups); TAILQ_INIT(&session_groups);
mode_key_init_trees(); mode_key_init_trees();
key_bindings_init(); key_bindings_init();
@ -264,8 +262,6 @@ server_loop(void)
server_window_loop(); server_window_loop();
server_client_loop(); server_client_loop();
server_clean_dead();
} }
} }
@ -317,21 +313,6 @@ server_send_shutdown(void)
session_destroy(s); session_destroy(s);
} }
/* Free dead, unreferenced clients and sessions. */
void
server_clean_dead(void)
{
struct session *s, *s1;
RB_FOREACH_SAFE(s, sessions, &dead_sessions, s1) {
if (s->references != 0)
continue;
RB_REMOVE(sessions, &dead_sessions, s);
free(s->name);
free(s);
}
}
/* Update socket execute permissions based on whether sessions are attached. */ /* Update socket execute permissions based on whether sessions are attached. */
void void
server_update_socket(void) server_update_socket(void)

View File

@ -27,12 +27,12 @@
#include "tmux.h" #include "tmux.h"
/* Global session list. */
struct sessions sessions; struct sessions sessions;
struct sessions dead_sessions;
u_int next_session_id; u_int next_session_id;
struct session_groups session_groups; struct session_groups session_groups;
void session_free(int, short, void *);
struct winlink *session_next_alert(struct winlink *); struct winlink *session_next_alert(struct winlink *);
struct winlink *session_previous_alert(struct winlink *); struct winlink *session_previous_alert(struct winlink *);
@ -109,7 +109,7 @@ session_create(const char *name, int argc, char **argv, const char *path,
struct winlink *wl; struct winlink *wl;
s = xmalloc(sizeof *s); s = xmalloc(sizeof *s);
s->references = 0; s->references = 1;
s->flags = 0; s->flags = 0;
if (gettimeofday(&s->creation_time, NULL) != 0) if (gettimeofday(&s->creation_time, NULL) != 0)
@ -164,6 +164,29 @@ session_create(const char *name, int argc, char **argv, const char *path,
return (s); return (s);
} }
/* Remove a reference from a session. */
void
session_unref(struct session *s)
{
log_debug("session %s has %d references", s->name, s->references);
s->references--;
if (s->references == 0)
event_once(-1, EV_TIMEOUT, session_free, s, NULL);
}
/* Free session. */
void
session_free(unused int fd, unused short events, void *arg)
{
struct session *s = arg;
log_debug("sesson %s freed (%d references)", s->name, s->references);
if (s->references == 0)
free(s);
}
/* Destroy a session. */ /* Destroy a session. */
void void
session_destroy(struct session *s) session_destroy(struct session *s)
@ -191,7 +214,7 @@ session_destroy(struct session *s)
close(s->cwd); close(s->cwd);
RB_INSERT(sessions, &dead_sessions, s); session_unref(s);
} }
/* Check a session name is valid: not empty and no colons or periods. */ /* Check a session name is valid: not empty and no colons or periods. */

2
tmux.h
View File

@ -2259,7 +2259,6 @@ void control_notify_session_close(struct session *);
/* session.c */ /* session.c */
extern struct sessions sessions; extern struct sessions sessions;
extern struct sessions dead_sessions;
extern struct session_groups session_groups; extern struct session_groups session_groups;
int session_cmp(struct session *, struct session *); int session_cmp(struct session *, struct session *);
RB_PROTOTYPE(sessions, session, entry, session_cmp); RB_PROTOTYPE(sessions, session, entry, session_cmp);
@ -2271,6 +2270,7 @@ struct session *session_create(const char *, int, char **, const char *,
int, struct environ *, struct termios *, int, u_int, int, struct environ *, struct termios *, int, u_int,
u_int, char **); u_int, char **);
void session_destroy(struct session *); void session_destroy(struct session *);
void session_unref(struct session *);
int session_check_name(const char *); int session_check_name(const char *);
void session_update_activity(struct session *); void session_update_activity(struct session *);
struct session *session_next_session(struct session *); struct session *session_next_session(struct session *);

View File

@ -209,11 +209,11 @@ window_choose_data_create(int type, struct client *c, struct session *s)
void void
window_choose_data_free(struct window_choose_data *wcd) window_choose_data_free(struct window_choose_data *wcd)
{ {
wcd->start_client->references--; server_client_unref(wcd->start_client);
wcd->start_session->references--; session_unref(wcd->start_session);
if (wcd->tree_session != NULL) if (wcd->tree_session != NULL)
wcd->tree_session->references--; session_unref(wcd->tree_session);
free(wcd->ft_template); free(wcd->ft_template);
format_free(wcd->ft); format_free(wcd->ft);