From c8fab89f1b5ae8c3752979e1a1004eda8b185687 Mon Sep 17 00:00:00 2001 From: Tao Wu Date: Tue, 20 Sep 2016 17:58:55 -0700 Subject: [PATCH] Ignore setsid error in some cases. If the calling process has already been a leading process of session. setsid just fail with EPERM, ignore such error. Test: killall adb;exec 3>f;adb fork-server server --reply-fd 3 & cat f Change-Id: I1aeac079f29e10aa63ed724b5a43663f25c25ad5 Signed-off-by: Tao Wu --- adb/client/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adb/client/main.cpp b/adb/client/main.cpp index 571c227a6..e428c49bc 100644 --- a/adb/client/main.cpp +++ b/adb/client/main.cpp @@ -129,7 +129,9 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply // 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) { + // setsid will fail with EPERM if it's already been a lead process of new session. + // Ignore such error. + if (setsid() == -1 && errno != EPERM) { fatal("setsid() failed: %s", strerror(errno)); } #endif