fsck_ffs has a ^T signal handler which opens /dev/tty late. Hoist that
authorderaadt <deraadt@openbsd.org>
Thu, 15 Oct 2015 03:10:05 +0000 (03:10 +0000)
committerderaadt <deraadt@openbsd.org>
Thu, 15 Oct 2015 03:10:05 +0000 (03:10 +0000)
opening to before the pledge, and cache the fd.
looked over by millert

sbin/fsck_ffs/main.c
sbin/fsck_ffs/utilities.c

index 611da7f..24043a1 100644 (file)
@@ -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);
 
index 6ddee8e..dc1e9fa 100644 (file)
@@ -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;
 }