]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
The incorrect order of fcntl() parameters resulted in the inability to clear O_NONBLOCK
authorLeefancy <lijian01@kylinos.cn>
Wed, 4 Mar 2026 09:30:12 +0000 (17:30 +0800)
committerLeefancy <lijian01@kylinos.cn>
Sat, 7 Mar 2026 08:11:02 +0000 (16:11 +0800)
Signed-off-by: Leefancy <lijian01@kylinos.cn>
term-utils/ttymsg.c

index ef7e35899f63fbc8bc4da7600d66bb2b42fe7ab2..37ab94c196e978018c78d951a71028b4c276442d 100644 (file)
@@ -136,6 +136,7 @@ ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout) {
                }
                if (errno == EWOULDBLOCK) {
                        int cpid, flags;
+                       int rc;
                        sigset_t sigmask;
 
                        if (forked) {
@@ -161,8 +162,14 @@ ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout) {
                        sigemptyset(&sigmask);
                        sigprocmask (SIG_SETMASK, &sigmask, NULL);
                        alarm((u_int)tmout);
-                       flags = fcntl(fd, F_GETFL);
-                       fcntl(flags, F_SETFL, (long) (flags & ~O_NONBLOCK));
+                       rc = flags = fcntl(fd, F_GETFL);
+                       if (rc >= 0)
+                               rc = fcntl(fd, F_SETFL, (long) (flags & ~O_NONBLOCK));
+                       if (rc < 0) {
+                               warn(_("fcntl failed: %s"), device); 
+                               close_fd(fd);
+                               _exit(EXIT_FAILURE);
+                       }
                        continue;
                }
                /*