summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-09-24 14:17:10 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-09-24 14:17:10 +0000
commit42045432f0b34aeb1b9a32011cd6f98f018f9256 (patch)
treedeb279c053f3b4dd7a13021e382fc16f29e50025 /usr.bin
parent61cb204ee2a8390925d6a7361c9a7719156bf6e9 (diff)
New lock-client and lock-session commands to lock an individual client or all
clients attached to a session respectively.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/Makefile5
-rw-r--r--usr.bin/tmux/cmd-lock-client.c53
-rw-r--r--usr.bin/tmux/cmd-lock-session.c53
-rw-r--r--usr.bin/tmux/cmd.c4
-rw-r--r--usr.bin/tmux/server-fn.c51
-rw-r--r--usr.bin/tmux/tmux.117
-rw-r--r--usr.bin/tmux/tmux.h6
7 files changed, 169 insertions, 20 deletions
diff --git a/usr.bin/tmux/Makefile b/usr.bin/tmux/Makefile
index 694d6247fec..4d7ef1cee3f 100644
--- a/usr.bin/tmux/Makefile
+++ b/usr.bin/tmux/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.17 2009/09/23 06:18:47 nicm Exp $
+# $OpenBSD: Makefile,v 1.18 2009/09/24 14:17:09 nicm Exp $
PROG= tmux
SRCS= attributes.c buffer-poll.c buffer.c cfg.c client-fn.c \
@@ -12,7 +12,8 @@ SRCS= attributes.c buffer-poll.c buffer.c cfg.c client-fn.c \
cmd-last-window.c cmd-link-window.c cmd-list-buffers.c \
cmd-list-clients.c cmd-list-commands.c cmd-list-keys.c \
cmd-list-sessions.c cmd-list-windows.c cmd-list.c cmd-load-buffer.c \
- cmd-lock-server.c cmd-move-window.c cmd-new-session.c cmd-new-window.c \
+ cmd-lock-server.c cmd-lock-client.c cmd-lock-session.c \
+ cmd-move-window.c cmd-new-session.c cmd-new-window.c \
cmd-next-layout.c cmd-next-window.c cmd-paste-buffer.c \
cmd-previous-layout.c cmd-previous-window.c cmd-refresh-client.c \
cmd-rename-session.c cmd-rename-window.c cmd-resize-pane.c \
diff --git a/usr.bin/tmux/cmd-lock-client.c b/usr.bin/tmux/cmd-lock-client.c
new file mode 100644
index 00000000000..2bb550c2191
--- /dev/null
+++ b/usr.bin/tmux/cmd-lock-client.c
@@ -0,0 +1,53 @@
+/* $OpenBSD: cmd-lock-client.c,v 1.1 2009/09/24 14:17:09 nicm Exp $ */
+
+/*
+ * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include "tmux.h"
+
+/*
+ * Lock a single client.
+ */
+
+int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_lock_client_entry = {
+ "lock-client", "lockc",
+ CMD_TARGET_CLIENT_USAGE,
+ 0, 0,
+ cmd_target_init,
+ cmd_target_parse,
+ cmd_lock_client_exec,
+ cmd_target_free,
+ cmd_target_print
+};
+
+int
+cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_target_data *data = self->data;
+ struct client *c;
+
+ if ((c = cmd_find_client(ctx, data->target)) == NULL)
+ return (-1);
+
+ server_lock_client(c);
+ recalculate_sizes();
+
+ return (0);
+}
diff --git a/usr.bin/tmux/cmd-lock-session.c b/usr.bin/tmux/cmd-lock-session.c
new file mode 100644
index 00000000000..f22c16023ae
--- /dev/null
+++ b/usr.bin/tmux/cmd-lock-session.c
@@ -0,0 +1,53 @@
+/* $OpenBSD: cmd-lock-session.c,v 1.1 2009/09/24 14:17:09 nicm Exp $ */
+
+/*
+ * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include "tmux.h"
+
+/*
+ * Lock all clients attached to a session.
+ */
+
+int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_lock_session_entry = {
+ "lock-session", "locks",
+ CMD_TARGET_SESSION_USAGE,
+ 0, 0,
+ cmd_target_init,
+ cmd_target_parse,
+ cmd_lock_session_exec,
+ cmd_target_free,
+ cmd_target_print
+};
+
+int
+cmd_lock_session_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_target_data *data = self->data;
+ struct session *s;
+
+ if ((s = cmd_find_session(ctx, data->target)) == NULL)
+ return (-1);
+
+ server_lock_session(s);
+ recalculate_sizes();
+
+ return (0);
+}
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index 6c10d355729..e1fa8f89c0b 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.18 2009/09/23 06:18:47 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.19 2009/09/24 14:17:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -61,7 +61,9 @@ const struct cmd_entry *cmd_table[] = {
&cmd_list_sessions_entry,
&cmd_list_windows_entry,
&cmd_load_buffer_entry,
+ &cmd_lock_client_entry,
&cmd_lock_server_entry,
+ &cmd_lock_session_entry,
&cmd_move_window_entry,
&cmd_new_session_entry,
&cmd_new_window_entry,
diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c
index 10717b6b717..1a0f0a6aa3d 100644
--- a/usr.bin/tmux/server-fn.c
+++ b/usr.bin/tmux/server-fn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-fn.c,v 1.22 2009/09/23 06:18:47 nicm Exp $ */
+/* $OpenBSD: server-fn.c,v 1.23 2009/09/24 14:17:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -157,10 +157,8 @@ server_status_window(struct window *w)
void
server_lock(void)
{
- struct client *c;
- const char *cmd;
- struct msg_lock_data lockdata;
- u_int i;
+ struct client *c;
+ u_int i;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
@@ -168,19 +166,44 @@ server_lock(void)
continue;
if (c->flags & CLIENT_SUSPENDED)
continue;
+ server_lock_client(c);
+ }
+}
- cmd = options_get_string(&c->session->options, "lock-command");
- if (strlcpy(lockdata.cmd,
- cmd, sizeof lockdata.cmd) >= sizeof lockdata.cmd)
+void
+server_lock_session(struct session *s)
+{
+ struct client *c;
+ u_int i;
+
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c == NULL || c->session == NULL || c->session != s)
+ continue;
+ if (c->flags & CLIENT_SUSPENDED)
continue;
+ server_lock_client(c);
+ }
+}
- tty_stop_tty(&c->tty);
- tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_SMCUP));
- tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_CLEAR));
+void
+server_lock_client(struct client *c)
+{
+ const char *cmd;
+ size_t cmdlen;
+ struct msg_lock_data lockdata;
- c->flags |= CLIENT_SUSPENDED;
- server_write_client(c, MSG_LOCK, &lockdata, sizeof lockdata);
- }
+ cmd = options_get_string(&c->session->options, "lock-command");
+ cmdlen = strlcpy(lockdata.cmd, cmd, sizeof lockdata.cmd);
+ if (cmdlen >= sizeof lockdata.cmd)
+ return;
+
+ tty_stop_tty(&c->tty);
+ tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_SMCUP));
+ tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_CLEAR));
+
+ c->flags |= CLIENT_SUSPENDED;
+ server_write_client(c, MSG_LOCK, &lockdata, sizeof lockdata);
}
void
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index bf31ed49b7a..472fce3a5b0 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.91 2009/09/23 12:03:31 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.92 2009/09/24 14:17:09 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: September 23 2009 $
+.Dd $Mdocdate: September 24 2009 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -392,6 +392,19 @@ List the syntax of all commands supported by
.It Ic list-sessions
.D1 (alias: Ic ls )
List all sessions managed by the server.
+.It Xo Ic lock-client
+.Op Fl t Ar target-client
+.Xc
+Lock
+.Ar target-client ,
+see the
+.Ic lock-server
+command.
+.It Xo Ic lock-session
+.Op Fl t Ar target-session
+.Xc
+Lock all clients attached to
+.Ar target-session .
.It Xo Ic new-session
.Op Fl d
.Op Fl n Ar window-name
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 7bf679bf47b..5996e364a9a 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.117 2009/09/23 14:42:48 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.118 2009/09/24 14:17:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1326,7 +1326,9 @@ extern const struct cmd_entry cmd_list_keys_entry;
extern const struct cmd_entry cmd_list_sessions_entry;
extern const struct cmd_entry cmd_list_windows_entry;
extern const struct cmd_entry cmd_load_buffer_entry;
+extern const struct cmd_entry cmd_lock_client_entry;
extern const struct cmd_entry cmd_lock_server_entry;
+extern const struct cmd_entry cmd_lock_session_entry;
extern const struct cmd_entry cmd_move_window_entry;
extern const struct cmd_entry cmd_new_session_entry;
extern const struct cmd_entry cmd_new_window_entry;
@@ -1457,6 +1459,8 @@ void server_status_session(struct session *);
void server_redraw_window(struct window *);
void server_status_window(struct window *);
void server_lock(void);
+void server_lock_session(struct session *);
+void server_lock_client(struct client *);
int server_unlock(const char *);
void server_kill_window(struct window *);
int server_link_window(