From: nicm Date: Wed, 19 Apr 2017 14:00:28 +0000 (+0000) Subject: Add a suspend helper function, and do not allow detaching or suspending X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=34cdbc315659f2709866223d02f747925527c162;p=openbsd Add a suspend helper function, and do not allow detaching or suspending while already doing so. --- diff --git a/usr.bin/tmux/cmd-detach-client.c b/usr.bin/tmux/cmd-detach-client.c index ade9447a79c..7db1d489b32 100644 --- a/usr.bin/tmux/cmd-detach-client.c +++ b/usr.bin/tmux/cmd-detach-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-detach-client.c,v 1.30 2017/01/13 10:12:12 nicm Exp $ */ +/* $OpenBSD: cmd-detach-client.c,v 1.31 2017/04/19 14:00:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -67,9 +67,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) const char *cmd = args_get(args, 'E'); if (self->entry == &cmd_suspend_client_entry) { - tty_stop_tty(&c->tty); - c->flags |= CLIENT_SUSPENDED; - proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0); + server_client_suspend(c); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index e053b5df07c..a88c065e527 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.219 2017/04/19 06:52:27 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.220 2017/04/19 14:00:28 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -49,7 +49,7 @@ static void server_client_dispatch_command(struct client *, struct imsg *); static void server_client_dispatch_identify(struct client *, struct imsg *); static void server_client_dispatch_shell(struct client *); -/* Idenfity mode callback. */ +/* Identify mode callback. */ static void server_client_callback_identify(__unused int fd, __unused short events, void *data) { @@ -325,15 +325,30 @@ server_client_free(__unused int fd, __unused short events, void *arg) } } +/* Suspend a client. */ +void +server_client_suspend(struct client *c) +{ + struct session *s = c->session; + + if (s == NULL || (c->flags & CLIENT_DETACHING)) + return; + + tty_stop_tty(&c->tty); + c->flags |= CLIENT_SUSPENDED; + proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0); +} + /* Detach a client. */ void server_client_detach(struct client *c, enum msgtype msgtype) { - struct session *s = c->session; + struct session *s = c->session; - if (s == NULL) + if (s == NULL || (c->flags & CLIENT_DETACHING)) return; + c->flags |= CLIENT_DETACHING; notify_client("client-detached", c); proc_send_s(c->peer, msgtype, s->name); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 87b9a86602e..627e9567744 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.739 2017/04/19 06:52:27 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.740 2017/04/19 14:00:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1338,7 +1338,7 @@ struct client { #define CLIENT_DEAD 0x200 #define CLIENT_BORDERS 0x400 #define CLIENT_READONLY 0x800 -/* 0x1000 unused */ +#define CLIENT_DETACHING 0x1000 #define CLIENT_CONTROL 0x2000 #define CLIENT_CONTROLCONTROL 0x4000 #define CLIENT_FOCUSED 0x8000 @@ -1838,6 +1838,7 @@ void server_client_create(int); int server_client_open(struct client *, char **); void server_client_unref(struct client *); void server_client_lost(struct client *); +void server_client_suspend(struct client *); void server_client_detach(struct client *, enum msgtype); void server_client_exec(struct client *, const char *); void server_client_loop(void);