summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-12-22 13:05:33 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:49:43 +0200
commitcef2ebd7970895b0d1186bf5f6b8cbe0ee455ff4 (patch)
tree22b9c9d336dc9f30a95971c467bb444a728a5fdc /src
parent6b31c632bc5ce9b89031db22252443795ed576b7 (diff)
terminal-util: return first error, not last in make_stdio()
Just a minor tweak, making sure we execute as much as we can of the funciton, but return the first error instead of the last we encounter. This is usuelly how we do things when we have functions that continue on the first error, so let's do it like that here too.
Diffstat (limited to 'src')
-rw-r--r--src/basic/terminal-util.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index 9ef007d30..3ece0697f 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -887,25 +887,24 @@ bool on_tty(void) {
}
int make_stdio(int fd) {
- int r, s, t;
+ int r = 0;
assert(fd >= 0);
- r = dup2(fd, STDIN_FILENO);
- s = dup2(fd, STDOUT_FILENO);
- t = dup2(fd, STDERR_FILENO);
+ if (dup2(fd, STDIN_FILENO) < 0 && r >= 0)
+ r = -errno;
+ if (dup2(fd, STDOUT_FILENO) < 0 && r >= 0)
+ r = -errno;
+ if (dup2(fd, STDERR_FILENO) < 0 && r >= 0)
+ r = -errno;
if (fd >= 3)
safe_close(fd);
- if (r < 0 || s < 0 || t < 0)
- return -errno;
-
- /* Explicitly unset O_CLOEXEC, since if fd was < 3, then
- * dup2() was a NOP and the bit hence possibly set. */
+ /* Explicitly unset O_CLOEXEC, since if fd was < 3, then dup2() was a NOP and the bit hence possibly set. */
stdio_unset_cloexec();
- return 0;
+ return r;
}
int make_null_stdio(void) {