From: Lennart Poettering Date: Tue, 20 Aug 2024 08:32:14 +0000 (+0200) Subject: terminal-util: don't assume errno is correctly set when using isatty_safe() X-Git-Tag: v257-rc1~674^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aae47bf7a352f2ae8cca14187b31e6a00a01bd93;p=thirdparty%2Fsystemd.git terminal-util: don't assume errno is correctly set when using isatty_safe() let's instead generate ENOTTY on our own. This is more correct with out coding style (since we generally do not propagate errors via errno), and also addresses #34039 as side effect. (#34039 really needs to be fixed in musl though, too, this is just a work-around as side-effect). Fixes: #34039 --- diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 4219ac5ee9f..d6de92ee89d 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -287,7 +287,7 @@ int open_terminal(const char *name, int mode) { } if (!isatty_safe(fd)) - return negative_errno(); + return -ENOTTY; return TAKE_FD(fd); } @@ -1508,7 +1508,7 @@ int vt_restore(int fd) { assert(fd >= 0); if (!isatty_safe(fd)) - return log_debug_errno(errno, "Asked to restore the VT for an fd that does not refer to a terminal: %m"); + return log_debug_errno(SYNTHETIC_ERRNO(ENOTTY), "Asked to restore the VT for an fd that does not refer to a terminal: %m"); if (ioctl(fd, KDSETMODE, KD_TEXT) < 0) RET_GATHER(ret, log_debug_errno(errno, "Failed to set VT to text mode, ignoring: %m")); @@ -1535,7 +1535,7 @@ int vt_release(int fd, bool restore) { * VT-switching modes. */ if (!isatty_safe(fd)) - return log_debug_errno(errno, "Asked to release the VT for an fd that does not refer to a terminal: %m"); + return log_debug_errno(SYNTHETIC_ERRNO(ENOTTY), "Asked to release the VT for an fd that does not refer to a terminal: %m"); if (ioctl(fd, VT_RELDISP, 1) < 0) return -errno; diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index acce71b1a88..9ad5597b05f 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -95,7 +95,7 @@ static int verify_tty(const char *name) { return -errno; if (!isatty_safe(fd)) - return -errno; + return -ENOTTY; return 0; } diff --git a/src/shared/wall.c b/src/shared/wall.c index c5d6439db67..119d18f5a46 100644 --- a/src/shared/wall.c +++ b/src/shared/wall.c @@ -32,7 +32,7 @@ static int write_to_terminal(const char *tty, const char *message) { return -errno; if (!isatty_safe(fd)) - return -errno; + return -ENOTTY; return loop_write_full(fd, message, SIZE_MAX, TIMEOUT_USEC); }