From: Leefancy Date: Wed, 4 Mar 2026 09:30:12 +0000 (+0800) Subject: The incorrect order of fcntl() parameters resulted in the inability to clear O_NONBLOCK X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3734e047579fe0b8c254e579a4eaa8de9a026e13;p=thirdparty%2Futil-linux.git The incorrect order of fcntl() parameters resulted in the inability to clear O_NONBLOCK Signed-off-by: Leefancy --- diff --git a/term-utils/ttymsg.c b/term-utils/ttymsg.c index ef7e35899..37ab94c19 100644 --- a/term-utils/ttymsg.c +++ b/term-utils/ttymsg.c @@ -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; } /*