diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-01-08 22:25:22 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-01-08 23:23:42 +0100 |
commit | 3b1e80f7cb49971b98552f064c494f98b6243505 (patch) | |
tree | b8f1e7c131cd65282f5fe836d3f23eab282ca42a /src/basic/fd-util.c | |
parent | env-util: add new setenvf() helper (diff) | |
download | systemd-3b1e80f7cb49971b98552f064c494f98b6243505.tar.xz systemd-3b1e80f7cb49971b98552f064c494f98b6243505.zip |
process-util: turn off O_NONBLOCK on stdio fds when rearranging fds
We often create our fds O_NONBLOCK, but when we want to invoke some
program with them as stdin/stdout/stderr we really should turn it off
again.
Diffstat (limited to 'src/basic/fd-util.c')
-rw-r--r-- | src/basic/fd-util.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 1a279690d2..38866ebb78 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -170,6 +170,19 @@ int fd_nonblock(int fd, bool nonblock) { return RET_NERRNO(fcntl(fd, F_SETFL, nflags)); } +int stdio_disable_nonblock(void) { + int ret = 0; + + /* stdin/stdout/stderr really should have O_NONBLOCK, which would confuse apps if left on, as + * write()s might unexpectedly fail with EAGAIN. */ + + RET_GATHER(ret, fd_nonblock(STDIN_FILENO, false)); + RET_GATHER(ret, fd_nonblock(STDOUT_FILENO, false)); + RET_GATHER(ret, fd_nonblock(STDERR_FILENO, false)); + + return ret; +} + int fd_cloexec(int fd, bool cloexec) { int flags, nflags; |