]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
exec-util: use open_terminal() in fork_agent() for safety
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 3 Dec 2024 09:58:11 +0000 (18:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Dec 2024 23:35:16 +0000 (08:35 +0900)
src/shared/exec-util.c

index 725962ef83ce34edf00c6c9520b2ec5299d92469..6ab32bea92026e7ee26b389cd173bd9a477ca823 100644 (file)
@@ -594,9 +594,9 @@ int _fork_agent(const char *name, const int except[], size_t n_except, pid_t *re
                  * that when systemctl is started via popen() or a similar call that expects to read EOF we
                  * actually do generate EOF and not delay this indefinitely by keeping an unused copy of
                  * stdin around. */
-                fd = open("/dev/tty", stdin_is_tty ? O_WRONLY : (stdout_is_tty && stderr_is_tty) ? O_RDONLY : O_RDWR);
+                fd = open_terminal("/dev/tty", stdin_is_tty ? O_WRONLY : (stdout_is_tty && stderr_is_tty) ? O_RDONLY : O_RDWR);
                 if (fd < 0) {
-                        log_error_errno(errno, "Failed to open /dev/tty: %m");
+                        log_error_errno(fd, "Failed to open /dev/tty: %m");
                         _exit(EXIT_FAILURE);
                 }