summaryrefslogtreecommitdiff
path: root/src/basic/fd-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-28 10:00:26 +0100
committerLennart Poettering <lennart@poettering.net>2018-03-02 11:42:10 +0100
commitaa11e28bf2866cc8634b5706dfcd07f0e5579e17 (patch)
treeb0e865d429c2c449c68ff41521a98a8c0e87b46e /src/basic/fd-util.h
parent9711b1adc737457aa7c44c45b8103e428b6bdd54 (diff)
downloadsystemd-aa11e28bf2866cc8634b5706dfcd07f0e5579e17.tar.gz
fd-util: add new call rearrange_stdio()
Quite often we need to set up a number of fds as stdin/stdout/stderr of a process we are about to start. Add a generic implementation for a routine doing that that takes care to do so properly: 1. Can handle the case where stdin/stdout/stderr where previously closed, and the fds to set as stdin/stdout/stderr hence likely in the 0..2 range. handling this properly is nasty, since we need to first move the fds out of this range in order to later move them back in, to make things fully robust. 2. Can optionally open /dev/null in case for one or more of the fds, in a smart way, sharing the open file if possible between multiple of the fds. 3. Guarantees that O_CLOEXEC is not set on the three fds, even if the fds already were in the 0..2 range and hence possibly weren't moved.
Diffstat (limited to 'src/basic/fd-util.h')
-rw-r--r--src/basic/fd-util.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h
index 4e8d9bc40a..b687f1a555 100644
--- a/src/basic/fd-util.h
+++ b/src/basic/fd-util.h
@@ -100,3 +100,5 @@ int acquire_data_fd(const void *data, size_t size, unsigned flags);
IN_SET(r, ENOTCONN, ECONNRESET, ECONNREFUSED, ECONNABORTED, EPIPE, ENETUNREACH)
int fd_move_above_stdio(int fd);
+
+int rearrange_stdio(int original_input_fd, int original_output_fd, int original_error_fd);