mirror of
https://github.com/tmate-io/tmate.git
synced 2024-12-23 23:29:15 +01:00
Sync OpenBSD patchset 353:
New lock-client and lock-session commands to lock an individual client or all clients attached to a session respectively.
This commit is contained in:
parent
804b8696a4
commit
88c3b9c989
53
cmd-lock-client.c
Normal file
53
cmd-lock-client.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* $Id: cmd-lock-client.c,v 1.1 2009-09-25 17:51:39 tcunha 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);
|
||||
}
|
53
cmd-lock-session.c
Normal file
53
cmd-lock-session.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* $Id: cmd-lock-session.c,v 1.1 2009-09-25 17:51:39 tcunha 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);
|
||||
}
|
4
cmd.c
4
cmd.c
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd.c,v 1.117 2009-09-23 15:00:08 tcunha Exp $ */
|
||||
/* $Id: cmd.c,v 1.118 2009-09-25 17:51:39 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -60,7 +60,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,
|
||||
|
57
server-fn.c
57
server-fn.c
@ -1,4 +1,4 @@
|
||||
/* $Id: server-fn.c,v 1.90 2009-09-23 15:00:08 tcunha Exp $ */
|
||||
/* $Id: server-fn.c,v 1.91 2009-09-25 17:51:39 tcunha 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,21 +166,46 @@ server_lock(void)
|
||||
continue;
|
||||
if (c->flags & CLIENT_SUSPENDED)
|
||||
continue;
|
||||
|
||||
cmd = options_get_string(&c->session->options, "lock-command");
|
||||
if (strlcpy(lockdata.cmd,
|
||||
cmd, sizeof lockdata.cmd) >= sizeof lockdata.cmd)
|
||||
continue;
|
||||
|
||||
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);
|
||||
server_lock_client(c);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
server_lock_client(struct client *c)
|
||||
{
|
||||
const char *cmd;
|
||||
size_t cmdlen;
|
||||
struct msg_lock_data 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
|
||||
server_kill_window(struct window *w)
|
||||
{
|
||||
|
17
tmux.1
17
tmux.1
@ -1,4 +1,4 @@
|
||||
.\" $Id: tmux.1,v 1.173 2009-09-23 15:18:56 tcunha Exp $
|
||||
.\" $Id: tmux.1,v 1.174 2009-09-25 17:51:39 tcunha 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
|
||||
|
6
tmux.h
6
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.455 2009-09-25 17:45:46 tcunha Exp $ */
|
||||
/* $Id: tmux.h,v 1.456 2009-09-25 17:51:39 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -1324,7 +1324,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;
|
||||
@ -1455,6 +1457,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(
|
||||
|
Loading…
Reference in New Issue
Block a user