summaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2011-03-19 23:27:35 +0000
committerTiago Cunha <tcunha@gmx.com>2011-03-19 23:27:35 +0000
commitd0cca3924ec7d04321259264b23d0e083f2414c5 (patch)
treea50a2f8880052862058ea994886e0f184c280933 /client.c
parent34bb013b92a61233cc9feed7866a660e22693265 (diff)
Sync OpenBSD patchset 863:
Add a -P option to detach to HUP the client's parent process (usually causing it to exit as well).
Diffstat (limited to 'client.c')
-rw-r--r--client.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/client.c b/client.c
index fe7a7e54..b03433ba 100644
--- a/client.c
+++ b/client.c
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.101 2011-01-21 23:44:13 tcunha Exp $ */
+/* $Id: client.c,v 1.102 2011-03-19 23:27:35 tcunha 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;
@@ -194,8 +196,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);
}
@@ -436,12 +444,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 &&