mirror of
https://github.com/linux-msm/cdba.git
synced 2026-02-25 13:11:56 -08:00
cdba-server: sanitise file descriptors before device_close()
If we got to device_close(), the parent SSH might have been exited, making standard file descriptors unusable. Rebind them to /dev/null, so that any output during device_close (both from the cdba server and the helpers) doesn't cause SIGPIPE. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
This commit is contained in:
@@ -406,6 +406,17 @@ int main(int argc, char **argv)
|
||||
|
||||
done:
|
||||
|
||||
/* if we got here, stdin/out/err might be not accessible anymore */
|
||||
ret = open("/dev/null", O_RDWR);
|
||||
if (ret >= 0) {
|
||||
close(STDIN_FILENO);
|
||||
dup2(ret, STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
dup2(ret, STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
dup2(ret, STDERR_FILENO);
|
||||
}
|
||||
|
||||
if (selected_device)
|
||||
device_close(selected_device);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user