From: deraadt Date: Thu, 15 Oct 2015 03:10:05 +0000 (+0000) Subject: fsck_ffs has a ^T signal handler which opens /dev/tty late. Hoist that X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3aa8caa7ef15c9cc2217a0eda7c31db24ad91729;p=openbsd fsck_ffs has a ^T signal handler which opens /dev/tty late. Hoist that opening to before the pledge, and cache the fd. looked over by millert --- diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c index 611da7fb61c..24043a10e93 100644 --- a/sbin/fsck_ffs/main.c +++ b/sbin/fsck_ffs/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.45 2015/10/14 14:33:45 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.46 2015/10/15 03:10:05 deraadt Exp $ */ /* $NetBSD: main.c,v 1.22 1996/10/11 20:15:48 thorpej Exp $ */ /* @@ -129,7 +129,7 @@ main(int argc, char *argv[]) (void)signal(SIGINT, catch); if (preen) (void)signal(SIGQUIT, catchquit); - (void)signal(SIGINFO, catchinfo); + catchinfo(0); (void)checkfilesys(blockcheck(*argv), 0, 0L, 0); diff --git a/sbin/fsck_ffs/utilities.c b/sbin/fsck_ffs/utilities.c index 6ddee8ec8fa..dc1e9fa6680 100644 --- a/sbin/fsck_ffs/utilities.c +++ b/sbin/fsck_ffs/utilities.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utilities.c,v 1.50 2015/09/05 20:07:11 guenther Exp $ */ +/* $OpenBSD: utilities.c,v 1.51 2015/10/15 03:10:05 deraadt Exp $ */ /* $NetBSD: utilities.c,v 1.18 1996/09/27 22:45:20 christos Exp $ */ /* @@ -593,25 +593,25 @@ char *info_filesys = "?"; void catchinfo(int signo) { - int save_errno = errno, fd; + static int info_fd; + int save_errno = errno; struct iovec iov[4]; char buf[1024]; - if (info_fn != NULL && info_fn(buf, sizeof buf)) { - fd = open(_PATH_TTY, O_WRONLY); - if (fd >= 0) { - iov[0].iov_base = info_filesys; - iov[0].iov_len = strlen(info_filesys); - iov[1].iov_base = ": "; - iov[1].iov_len = sizeof ": " - 1; - iov[2].iov_base = buf; - iov[2].iov_len = strlen(buf); - iov[3].iov_base = "\n"; - iov[3].iov_len = sizeof "\n" - 1; - - writev(fd, iov, 4); - close(fd); - } + if (signo == 0) { + info_fd = open(_PATH_TTY, O_WRONLY); + signal(SIGINFO, catchinfo); + } else if (info_fd > 0 && info_fn != NULL && info_fn(buf, sizeof buf)) { + iov[0].iov_base = info_filesys; + iov[0].iov_len = strlen(info_filesys); + iov[1].iov_base = ": "; + iov[1].iov_len = sizeof ": " - 1; + iov[2].iov_base = buf; + iov[2].iov_len = strlen(buf); + iov[3].iov_base = "\n"; + iov[3].iov_len = sizeof "\n" - 1; + + writev(info_fd, iov, 4); } errno = save_errno; }