On Sat, May 28, 2016 at 09:27:09AM -0600, Theo de Raadt wrote: > > If you try to run disklabel(8) on a file that is not a device, it aborts > > aborts for want of pledge("ioctl"). This diff prints an error message > > and exits cleanly. I return exit code 1 but note that sometimes > > disklabel returns 4; the man page doesn't explain the distinction > > anywhere. > > > > $ disklabel / > > Abort trap (core dumped) > > $ obj/disklabel / > > disklabel: / is not a device > > Surprisingly, your fix won't help. The problem is that opendev() is > after pledge. > > That is incorrect. The pledge should occur after opendev.
Try this instead Index: disklabel.c =================================================================== RCS file: /cvs/src/sbin/disklabel/disklabel.c,v retrieving revision 1.214 diff -u -p -u -p -r1.214 disklabel.c --- disklabel.c 25 Nov 2015 17:17:38 -0000 1.214 +++ disklabel.c 28 May 2016 15:32:11 -0000 @@ -191,6 +191,12 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + dkname = argv[0]; + f = opendev(dkname, (op == READ ? O_RDONLY : O_RDWR), OPENDEV_PART, + &specname); + if (f < 0) + err(4, "%s", specname); + if (op == EDIT || op == EDITOR || aflag) { if (pledge("stdio rpath wpath cpath disklabel proc exec", NULL) == -1) err(1, "pledge"); @@ -205,12 +211,6 @@ main(int argc, char *argv[]) if (argc < 1 || (fstabfile && !(op == EDITOR || op == RESTORE || aflag))) usage(); - - dkname = argv[0]; - f = opendev(dkname, (op == READ ? O_RDONLY : O_RDWR), OPENDEV_PART, - &specname); - if (f < 0) - err(4, "%s", specname); if (autotable != NULL) parse_autotable(autotable);