I think the patch below is a bit cleaner than the one I committed. ok?
----- Forwarded message from Theo Buehler <t...@math.ethz.ch> ----- Date: Sun, 21 Aug 2016 03:27:49 +0200 From: Theo Buehler <t...@math.ethz.ch> To: m...@openbsd.org Subject: Re: fsdb pledge > this is kinda gross, but ok for now. I agree that it isn't very nice. How about this version that passes a flag to setup()? Unless I'm missing something, the only reason for the pledges being conditional on !hotroot() is the mount(2) call in fsck_ffs/main.c:336, where a ro root filesystem is remounted rw in the hotroot() case. In fsdb there's no such remounting, so this conditional pledge wasn't actually right for fsdb anyway. Index: fsdb/fsdb.c =================================================================== RCS file: /var/cvs/src/sbin/fsdb/fsdb.c,v retrieving revision 1.30 diff -u -p -r1.30 fsdb.c --- fsdb/fsdb.c 7 Jun 2016 01:29:38 -0000 1.30 +++ fsdb/fsdb.c 21 Aug 2016 00:27:59 -0000 @@ -103,7 +103,7 @@ main(int argc, char *argv[]) } if (fsys == NULL) usage(); - if (!setup(fsys)) + if (!setup(fsys, 1)) errx(1, "cannot set up file system `%s'", fsys); printf("Editing file system `%s'\nLast Mounted on %s\n", fsys, sblock.fs_fsmnt); Index: fsck_ffs/extern.h =================================================================== RCS file: /var/cvs/src/sbin/fsck_ffs/extern.h,v retrieving revision 1.13 diff -u -p -r1.13 extern.h --- fsck_ffs/extern.h 6 Sep 2014 04:05:40 -0000 1.13 +++ fsck_ffs/extern.h 21 Aug 2016 00:30:20 -0000 @@ -69,7 +69,7 @@ void pinode(ino_t); void propagate(ino_t); int reply(char *); void setinodebuf(ino_t); -int setup(char *); +int setup(char *, int); union dinode * getnextinode(ino_t); void catch(int); void catchquit(int); Index: fsck_ffs/main.c =================================================================== RCS file: /var/cvs/src/sbin/fsck_ffs/main.c,v retrieving revision 1.49 diff -u -p -r1.49 main.c --- fsck_ffs/main.c 24 Nov 2015 21:42:54 -0000 1.49 +++ fsck_ffs/main.c 21 Aug 2016 00:26:53 -0000 @@ -170,7 +170,7 @@ checkfilesys(char *filesys, char *mntpt, if (debug && preen) pwarn("starting\n"); - switch (setup(filesys)) { + switch (setup(filesys, 0)) { case 0: if (preen) pfatal("CAN'T CHECK FILE SYSTEM."); Index: fsck_ffs/setup.c =================================================================== RCS file: /var/cvs/src/sbin/fsck_ffs/setup.c,v retrieving revision 1.61 diff -u -p -r1.61 setup.c --- fsck_ffs/setup.c 20 Aug 2016 15:04:21 -0000 1.61 +++ fsck_ffs/setup.c 21 Aug 2016 00:40:20 -0000 @@ -77,7 +77,7 @@ static const int sbtry[] = SBLOCKSEARCH; static const int altsbtry[] = { 32, 64, 128, 144, 160, 192, 256 }; int -setup(char *dev) +setup(char *dev, int isfsdb) { long cg, size, asked, i, j; size_t bmapsize; @@ -102,7 +102,7 @@ setup(char *dev) strlcpy(rdevname, realdev, sizeof(rdevname)); setcdevname(rdevname, dev, preen); - if (!hotroot()) + if (isfsdb || !hotroot()) if (pledge("stdio rpath wpath getpw tty disklabel", NULL) == -1) err(1, "pledge"); @@ -145,15 +145,13 @@ setup(char *dev) else secsize = DEV_BSIZE; - if (!hotroot()) { + if (isfsdb) { + if (pledge("stdio rpath getpw tty", NULL) == -1) + err(1, "pledge"); + } else if (!hotroot()) { #ifndef SMALL - if (strcmp("fsdb", getprogname()) == 0) { - if (pledge("stdio rpath getpw tty", NULL) == -1) - err(1, "pledge"); - } else { - if (pledge("stdio getpw", NULL) == -1) - err(1, "pledge"); - } + if (pledge("stdio getpw", NULL) == -1) + err(1, "pledge"); #else if (pledge("stdio", NULL) == -1) err(1, "pledge"); ----- End forwarded message -----