Skip to content

Commit

Permalink
Use /dev/null instead of closing fds
Browse files Browse the repository at this point in the history
Some adb commands do not like when stdin, stdout or stderr are closed
(they hang forever). Open /dev/null for each.
  • Loading branch information
rom1v committed Sep 25, 2022
1 parent 4a5cdcd commit 00e9e69
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions app/src/sys/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ sc_process_execute_p(const char *const argv[], sc_pid *pid, unsigned flags,
close(in[0]);
}
close(in[1]);
} else {
int devnull = open("/dev/null", O_RDONLY | O_CREAT, 0666);
if (devnull != -1) {
dup2(devnull, STDIN_FILENO);
} else {
LOGE("Could not open /dev/null for stdin");
}
}
// Do not close stdin in the child process, this makes adb fail on Linux

if (pout) {
if (out[1] != STDOUT_FILENO) {
Expand All @@ -102,8 +108,12 @@ sc_process_execute_p(const char *const argv[], sc_pid *pid, unsigned flags,
}
close(out[0]);
} else if (!inherit_stdout) {
// Close stdout in the child process
close(STDOUT_FILENO);
int devnull = open("/dev/null", O_WRONLY | O_CREAT, 0666);
if (devnull != -1) {
dup2(devnull, STDOUT_FILENO);
} else {
LOGE("Could not open /dev/null for stdout");
}
}

if (perr) {
Expand All @@ -113,8 +123,12 @@ sc_process_execute_p(const char *const argv[], sc_pid *pid, unsigned flags,
}
close(err[0]);
} else if (!inherit_stderr) {
// Close stderr in the child process
close(STDERR_FILENO);
int devnull = open("/dev/null", O_WRONLY | O_CREAT, 0666);
if (devnull != -1) {
dup2(devnull, STDERR_FILENO);
} else {
LOGE("Could not open /dev/null for stderr");
}
}

close(internal[0]);
Expand Down

0 comments on commit 00e9e69

Please sign in to comment.