summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-03-03 08:51:48 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-03-03 08:51:48 +0000
commitdb775783609e0c62e612f4d246c7dce97f12ddc1 (patch)
tree05f1b7e2d7842151184ac32f501ba97e408edc81 /usr.bin
parenta5ac9fede6f5c9cb157cac99c2ff0750e5495482 (diff)
Add a -P option to detach to HUP the client's parent process (usually
causing it to exit as well).
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/client.c21
-rw-r--r--usr.bin/tmux/cmd-detach-client.c11
-rw-r--r--usr.bin/tmux/tmux.113
-rw-r--r--usr.bin/tmux/tmux.h3
4 files changed, 36 insertions, 12 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c
index 65efc40550b..bd729b1f769 100644
--- a/usr.bin/tmux/client.c
+++ b/usr.bin/tmux/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.47 2011/01/08 01:52:36 nicm Exp $ */
+/* $OpenBSD: client.c,v 1.48 2011/03/03 08:51:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -36,6 +36,7 @@ struct imsgbuf client_ibuf;
struct event client_event;
const char *client_exitmsg;
int client_exitval;
+enum msgtype client_exittype;
int client_attached;
int client_connect(char *, int);
@@ -100,6 +101,7 @@ client_main(int argc, char **argv, int flags)
struct cmd_list *cmdlist;
struct msg_command_data cmddata;
int cmdflags, fd;
+ pid_t ppid;
enum msgtype msg;
char *cause;
@@ -192,8 +194,14 @@ client_main(int argc, char **argv, int flags)
event_dispatch();
/* Print the exit message, if any, and exit. */
- if (client_attached && client_exitmsg != NULL && !login_shell)
- printf("[%s]\n", client_exitmsg);
+ if (client_attached) {
+ if (client_exitmsg != NULL && !login_shell)
+ printf("[%s]\n", client_exitmsg);
+
+ ppid = getppid();
+ if (client_exittype == MSG_DETACHKILL && ppid > 1)
+ kill(ppid, SIGHUP);
+ }
return (client_exitval);
}
@@ -434,12 +442,17 @@ client_dispatch_attached(void)
log_debug("client got %d", imsg.hdr.type);
switch (imsg.hdr.type) {
+ case MSG_DETACHKILL:
case MSG_DETACH:
if (datalen != 0)
fatalx("bad MSG_DETACH size");
+ client_exittype = imsg.hdr.type;
+ if (imsg.hdr.type == MSG_DETACHKILL)
+ client_exitmsg = "detached and SIGHUP";
+ else
+ client_exitmsg = "detached";
client_write_server(MSG_EXITING, NULL, 0);
- client_exitmsg = "detached";
break;
case MSG_EXIT:
if (datalen != 0 &&
diff --git a/usr.bin/tmux/cmd-detach-client.c b/usr.bin/tmux/cmd-detach-client.c
index 045d27399bb..ed2f51dedf1 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.6 2011/01/04 00:42:46 nicm Exp $ */
+/* $OpenBSD: cmd-detach-client.c,v 1.7 2011/03/03 08:51:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,8 +28,8 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
- "t:", 0, 0,
- CMD_TARGET_CLIENT_USAGE,
+ "t:P", 0, 0,
+ "[-P] " CMD_TARGET_CLIENT_USAGE,
CMD_READONLY,
NULL,
NULL,
@@ -45,7 +45,10 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
return (-1);
- server_write_client(c, MSG_DETACH, NULL, 0);
+ if (args_has(args, 'P'))
+ server_write_client(c, MSG_DETACHKILL, NULL, 0);
+ else
+ server_write_client(c, MSG_DETACH, NULL, 0);
return (0);
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 05fcee6c72f..7252027d677 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.210 2011/01/14 23:49:23 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.211 2011/03/03 08:51:47 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: January 14 2011 $
+.Dd $Mdocdate: March 3 2011 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -550,10 +550,17 @@ If no server is started,
.Ic attach-session
will attempt to start it; this will fail unless sessions are created in the
configuration file.
-.It Ic detach-client Op Fl t Ar target-client
+.It Xo Ic detach-client
+.Op Fl P
+.Op Fl t Ar target-client
+.Xc
.D1 (alias: Ic detach )
Detach the current client if bound to a key, or the specified client with
.Fl t .
+If
+.Fl P
+is given, send SIGHUP to the parent process of the client, typically causing it
+to exit.
.It Ic has-session Op Fl t Ar target-session
.D1 (alias: Ic has )
Report an error and exit with 1 if the specified session does not exist.
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index a3cf41489dd..ac1b4a379ac 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.271 2011/01/26 01:54:56 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.272 2011/03/03 08:51:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -375,6 +375,7 @@ enum msgtype {
MSG_SHELL,
MSG_STDERR,
MSG_STDOUT,
+ MSG_DETACHKILL
};
/*