From 6bf323b97a11194d6186f8db2ee4a5eaca8d0141 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Mon, 8 Feb 2016 22:36:42 -0800 Subject: [PATCH] adb: setsid() for adb host server. To create a daemon for adb host server, we should call setsid() for the daemon process. However, previously we call setsid() for the adb client process, which results in nothing but EPERM error. Bug: 26982628 Change-Id: I2763ae3d5a243706927d7ef6af5095138c0ce2d8 --- adb/adb.cpp | 2 -- adb/client/main.cpp | 10 ++++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/adb/adb.cpp b/adb/adb.cpp index 58ccd0a70..cb54d04e0 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -883,8 +883,6 @@ int launch_server(int server_port) fprintf(stderr, "ADB server didn't ACK\n" ); return -1; } - - setsid(); } #endif /* !defined(_WIN32) */ return 0; diff --git a/adb/client/main.cpp b/adb/client/main.cpp index 6397c5239..27b7109e2 100644 --- a/adb/client/main.cpp +++ b/adb/client/main.cpp @@ -127,10 +127,12 @@ int adb_server_main(int is_daemon, int server_port, int ack_reply_fd) { 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(); + // Start a new session for the daemon. 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. + if (setsid() == -1) { + fatal("setsid() failed: %s", strerror(errno)); + } #endif // Any error output written to stderr now goes to adb.log. We could