Skip to content

Commit

Permalink
Close client fd using thread local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed May 8, 2017
1 parent 5a41e88 commit 28fe87c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions su_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define ATTY_ERR 4

struct ucred su_credentials;
static __thread int client_fd;

static void sighandler(int sig) {
restore_stdin();
Expand All @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 28fe87c

Please sign in to comment.