summaryrefslogtreecommitdiff
path: root/client/main.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2016-02-04 11:59:12 -0800
committerJosh Gao <jmgao@google.com>2016-02-08 16:59:10 -0800
commitab1fdb6f74e465ae964ee56182f89aaf8685ebb1 (patch)
tree64f16dc921f24f3cef076faaf4bb59b0ed1d34fb /client/main.cpp
parent51e7cc427e3ba3daaac886f03e571ca6d36f47d9 (diff)
downloadadb-ab1fdb6f74e465ae964ee56182f89aaf8685ebb1.tar.gz
adb: make ctrl-c when spawning a daemon not kill the daemon.
Previously, using ctrl-c in a command that needs to spawn a daemon because one isn't already available would kill the daemon along with the foreground process. Bug: http://b/26982628 Change-Id: I7fefc531c3e4895423e7b466322b5426d01dc9ef
Diffstat (limited to 'client/main.cpp')
-rw-r--r--client/main.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/client/main.cpp b/client/main.cpp
index b7b30c5..6397c52 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -21,6 +21,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
// We only build the affinity WAR code for Linux.
#if defined(__linux__)
@@ -125,6 +126,13 @@ int adb_server_main(int is_daemon, int server_port, int ack_reply_fd) {
close_stdin();
setup_daemon_logging();
+#if !defined(_WIN32)
+ // Set the process group so that ctrl-c in the spawning process doesn't kill us.
+ // Do this here instead of after the fork so that a ctrl-c between the "starting server" and
+ // "done starting server" messages gets a chance to terminate the server.
+ setpgrp();
+#endif
+
// Any error output written to stderr now goes to adb.log. We could
// keep around a copy of the stderr fd and use that to write any errors
// encountered by the following code, but that is probably overkill.