From 371db886b48b2a8366e8dc15319875ae220c0830 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 8 May 2017 11:50:23 +0800 Subject: [PATCH] Close client fd using thread local storage --- su_client.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/su_client.c b/su_client.c index cd6312be7..2b4bda7a8 100644 --- a/su_client.c +++ b/su_client.c @@ -26,6 +26,7 @@ #define ATTY_ERR 4 struct ucred su_credentials; +static __thread int client_fd; static void sighandler(int sig) { restore_stdin(); @@ -52,6 +53,8 @@ static void sighandler(int sig) { static void sigpipe_handler(int sig) { LOGD("su: Client killed unexpectedly\n"); + close(client_fd); + pthread_exit(NULL); } void su_daemon_receiver(int client) { @@ -69,6 +72,9 @@ void su_daemon_receiver(int client) { return; } else if (child != 0) { + // For sighandler to close it + client_fd = client; + // Wait result LOGD("su: wait_result waiting for %d\n", child); int status, code;