summaryrefslogtreecommitdiff
path: root/src/basic/terminal-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-28 21:21:33 +0100
committerLennart Poettering <lennart@poettering.net>2018-03-02 11:42:10 +0100
commit8bb2db738e13f67cdfe17afefac5fb03ca68a7e6 (patch)
tree7df514f519d131835801533c71a8d5264cf0baa7 /src/basic/terminal-util.c
parentaa11e28bf2866cc8634b5706dfcd07f0e5579e17 (diff)
downloadsystemd-8bb2db738e13f67cdfe17afefac5fb03ca68a7e6.tar.gz
terminal-util: port some generic code over to rearrange_stdio()
Diffstat (limited to 'src/basic/terminal-util.c')
-rw-r--r--src/basic/terminal-util.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index cdad4cb621..eacfd14677 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -628,9 +628,9 @@ int make_console_stdio(void) {
if (r < 0)
log_warning_errno(r, "Failed to reset terminal, ignoring: %m");
- r = make_stdio(fd);
+ r = rearrange_stdio(fd, fd, fd); /* This invalidates 'fd' both on success and on failure. */
if (r < 0)
- return log_error_errno(r, "Failed to duplicate terminal fd: %m");
+ return log_error_errno(r, "Failed to make terminal stdin/stdout/stderr: %m");
reset_terminal_feature_caches();
@@ -905,40 +905,6 @@ bool on_tty(void) {
return cached_on_tty;
}
-int make_stdio(int fd) {
- int r = 0;
-
- assert(fd >= 0);
-
- if (dup2(fd, STDIN_FILENO) < 0)
- r = -errno;
- if (dup2(fd, STDOUT_FILENO) < 0 && r >= 0)
- r = -errno;
- if (dup2(fd, STDERR_FILENO) < 0 && r >= 0)
- r = -errno;
-
- safe_close_above_stdio(fd);
-
- /* Explicitly unset O_CLOEXEC, since if fd was < 3, then dup2() was a NOP and the bit hence possibly set. */
- stdio_unset_cloexec();
-
- return r;
-}
-
-int make_null_stdio(void) {
- int null_fd, r;
-
- null_fd = open("/dev/null", O_RDWR|O_NOCTTY|O_CLOEXEC);
- if (null_fd < 0)
- return -errno;
-
- r = make_stdio(null_fd);
-
- reset_terminal_feature_caches();
-
- return r;
-}
-
int getttyname_malloc(int fd, char **ret) {
size_t l = 100;
int r;