* stdin around. */
fd = open("/dev/tty", stdin_is_tty ? O_WRONLY : (stdout_is_tty && stderr_is_tty) ? O_RDONLY : O_RDWR);
if (fd < 0) {
- if (errno != ENXIO) {
- log_error_errno(errno, "Failed to open /dev/tty: %m");
- _exit(EXIT_FAILURE);
- }
-
- /* If we get ENXIO here we have no controlling TTY even though stdout/stderr are
- * connected to a TTY. That's a weird setup, but let's handle it gracefully: let's
- * skip the forking of the agents, given the TTY setup is not in order. */
- } else {
- if (!stdin_is_tty && dup2(fd, STDIN_FILENO) < 0) {
- log_error_errno(errno, "Failed to dup2 /dev/tty to STDIN: %m");
- _exit(EXIT_FAILURE);
- }
+ log_error_errno(errno, "Failed to open /dev/tty: %m");
+ _exit(EXIT_FAILURE);
+ }
- if (!stdout_is_tty && dup2(fd, STDOUT_FILENO) < 0) {
- log_error_errno(errno, "Failed to dup2 /dev/tty to STDOUT: %m");
- _exit(EXIT_FAILURE);
- }
+ if (!stdin_is_tty && dup2(fd, STDIN_FILENO) < 0) {
+ log_error_errno(errno, "Failed to dup2 /dev/tty to STDIN: %m");
+ _exit(EXIT_FAILURE);
+ }
- if (!stderr_is_tty && dup2(fd, STDERR_FILENO) < 0) {
- log_error_errno(errno, "Failed to dup2 /dev/tty to STDERR: %m");
- _exit(EXIT_FAILURE);
- }
+ if (!stdout_is_tty && dup2(fd, STDOUT_FILENO) < 0) {
+ log_error_errno(errno, "Failed to dup2 /dev/tty to STDOUT: %m");
+ _exit(EXIT_FAILURE);
+ }
- fd = safe_close_above_stdio(fd);
+ if (!stderr_is_tty && dup2(fd, STDERR_FILENO) < 0) {
+ log_error_errno(errno, "Failed to dup2 /dev/tty to STDERR: %m");
+ _exit(EXIT_FAILURE);
}
+
+ fd = safe_close_above_stdio(fd);
}
/* Count arguments */