Index: lib/libdpv/dialog_util.c =================================================================== --- lib/libdpv/dialog_util.c +++ lib/libdpv/dialog_util.c @@ -84,7 +84,7 @@ static void tty_maxsize_update(void) { - int fd = STDIN_FILENO; + int doclose = 0, fd = STDIN_FILENO; struct termios t; if (maxsize == NULL) { @@ -93,12 +93,18 @@ memset((void *)maxsize, '\0', sizeof(struct winsize)); } - if (!isatty(fd)) + if (!isatty(fd)) { fd = open("/dev/tty", O_RDONLY); + if (fd < 0) + err(EXIT_FAILURE, "Unable to open /dev/tty"); + doclose = 1; + } if ((tcgetattr(fd, &t) < 0) || (ioctl(fd, TIOCGWINSZ, maxsize) < 0)) { maxsize->ws_row = TTY_DEFAULT_ROWS; maxsize->ws_col = TTY_DEFAULT_COLS; } + if (doclose) + (void)close(fd); } /* @@ -141,7 +147,11 @@ } /* Read in the line returned from Xdialog(1) */ - if ((fgets(rbuf, LINE_MAX, f) == NULL) || (pclose(f) < 0)) + if (fgets(rbuf, LINE_MAX, f) == NULL) { + (void)pclose(f); + return; + } + if (pclose(f) < 0) return; /* Check for X11-related errors */