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:
Dmitry Baryshkov
2023-09-23 18:28:16 +03:00
parent 310004badb
commit a0de781e1b

View File

@@ -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);