Skip to content

Commit

Permalink
Add new-session -X and attach-session -x to send SIGHUP to parent when
Browse files Browse the repository at this point in the history
detaching (like detach-client -P). From Colin Watson in GitHub issue
1773.
  • Loading branch information
nicm committed Jun 3, 2019
1 parent 900238a commit 4ca1de1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
27 changes: 18 additions & 9 deletions cmd-attach-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const struct cmd_entry cmd_attach_session_entry = {
.name = "attach-session",
.alias = "attach",

.args = { "c:dErt:", 0, 0 },
.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
.args = { "c:dErt:x", 0, 0 },
.usage = "[-dErx] [-c working-directory] " CMD_TARGET_SESSION_USAGE,

/* -t is special */

Expand All @@ -48,7 +48,7 @@ const struct cmd_entry cmd_attach_session_entry = {

enum cmd_retval
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
int rflag, const char *cflag, int Eflag)
int xflag, int rflag, const char *cflag, int Eflag)
{
struct cmd_find_state *current = &item->shared->current;
enum cmd_find_type type;
Expand All @@ -58,6 +58,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
struct winlink *wl;
struct window_pane *wp;
char *cause;
enum msgtype msgtype;

if (RB_EMPTY(&sessions)) {
cmdq_error(item, "no sessions");
Expand Down Expand Up @@ -102,11 +103,15 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,

c->last_session = c->session;
if (c->session != NULL) {
if (dflag) {
if (dflag || xflag) {
if (xflag)
msgtype = MSG_DETACHKILL;
else
msgtype = MSG_DETACH;
TAILQ_FOREACH(c_loop, &clients, entry) {
if (c_loop->session != s || c == c_loop)
continue;
server_client_detach(c_loop, MSG_DETACH);
server_client_detach(c_loop, msgtype);
}
}
if (!Eflag)
Expand All @@ -131,11 +136,15 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
if (rflag)
c->flags |= CLIENT_READONLY;

if (dflag) {
if (dflag || xflag) {
if (xflag)
msgtype = MSG_DETACHKILL;
else
msgtype = MSG_DETACH;
TAILQ_FOREACH(c_loop, &clients, entry) {
if (c_loop->session != s || c == c_loop)
continue;
server_client_detach(c_loop, MSG_DETACH);
server_client_detach(c_loop, msgtype);
}
}
if (!Eflag)
Expand Down Expand Up @@ -169,6 +178,6 @@ cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = self->args;

return (cmd_attach_session(item, args_get(args, 't'),
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
args_has(args, 'E')));
args_has(args, 'd'), args_has(args, 'x'), args_has(args, 'r'),
args_get(args, 'c'), args_has(args, 'E')));
}
7 changes: 4 additions & 3 deletions cmd-new-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const struct cmd_entry cmd_new_session_entry = {
.name = "new-session",
.alias = "new",

.args = { "Ac:dDEF:n:Ps:t:x:y:", 0, -1 },
.usage = "[-AdDEP] [-c start-directory] [-F format] [-n window-name] "
.args = { "Ac:dDEF:n:Ps:t:x:Xy:", 0, -1 },
.usage = "[-AdDEPX] [-c start-directory] [-F format] [-n window-name] "
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",

Expand Down Expand Up @@ -105,7 +105,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'A')) {
retval = cmd_attach_session(item,
newname, args_has(args, 'D'),
0, NULL, args_has(args, 'E'));
args_has(args, 'X'), 0, NULL,
args_has(args, 'E'));
free(newname);
return (retval);
}
Expand Down
14 changes: 12 additions & 2 deletions tmux.1
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ section.
The following commands are available to manage clients and sessions:
.Bl -tag -width Ds
.It Xo Ic attach-session
.Op Fl dEr
.Op Fl dErx
.Op Fl c Ar working-directory
.Op Fl t Ar target-session
.Xc
Expand All @@ -931,6 +931,10 @@ If used from inside, switch the current client.
If
.Fl d
is specified, any other clients attached to the session are detached.
If
.Fl x
is given, send SIGHUP to the parent process of the client as well as
detaching the client, typically causing it to exit.
.Fl r
signifies the client is read-only (only keys bound to the
.Ic detach-client
Expand Down Expand Up @@ -1048,7 +1052,7 @@ command.
Lock all clients attached to
.Ar target-session .
.It Xo Ic new-session
.Op Fl AdDEP
.Op Fl AdDEPX
.Op Fl c Ar start-directory
.Op Fl F Ar format
.Op Fl n Ar window-name
Expand Down Expand Up @@ -1105,6 +1109,12 @@ already exists; in this case,
behaves like
.Fl d
to
.Ic attach-session ,
and
.Fl X
behaves like
.Fl x
to
.Ic attach-session .
.Pp
If
Expand Down
2 changes: 1 addition & 1 deletion tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ extern const struct cmd_entry *cmd_table[];

/* cmd-attach-session.c */
enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
const char *, int);
int, const char *, int);

/* cmd-parse.c */
void cmd_parse_empty(struct cmd_parse_input *);
Expand Down

0 comments on commit 4ca1de1

Please sign in to comment.