]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: don't assume errno is correctly set when using isatty_safe()
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Aug 2024 08:32:14 +0000 (10:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Aug 2024 08:59:47 +0000 (10:59 +0200)
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
src/basic/terminal-util.c
src/getty-generator/getty-generator.c
src/shared/wall.c

index 4219ac5ee9fa2c9ffaeb39df546fb661388bca0a..d6de92ee89d6c2acc2b23f111ba834b291f28b10 100644 (file)
@@ -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;
index acce71b1a88b19e70ef57b2b3f79c028954443ae..9ad5597b05f2ff154f70a0b6a521ed9261047406 100644 (file)
@@ -95,7 +95,7 @@ static int verify_tty(const char *name) {
                 return -errno;
 
         if (!isatty_safe(fd))
-                return -errno;
+                return -ENOTTY;
 
         return 0;
 }
index c5d6439db67405e1ff840c97ef2cae34c7174f9d..119d18f5a46494b0c291c10a431bc01a30d706ec 100644 (file)
@@ -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);
 }