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
Index: disklabel.c
===================================================================
RCS file: /cvs/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.214
diff -u -p -r1.214 disklabel.c
--- disklabel.c 25 Nov 2015 17:17:38 -0000 1.214
+++ disklabel.c 27 May 2016 15:13:25 -0000
@@ -119,6 +119,7 @@ main(int argc, char *argv[])
int ch, f, error = 0;
FILE *t;
char *autotable = NULL;
+ struct stat sb;
getphysmem();
@@ -211,6 +212,9 @@ main(int argc, char *argv[])
&specname);
if (f < 0)
err(4, "%s", specname);
+ fstat(f, &sb);
+ if (!S_ISBLK(sb.st_mode) && !S_ISCHR(sb.st_mode))
+ errx(1, "%s is not a device", dkname);
if (autotable != NULL)
parse_autotable(autotable);