Already shown to a few people, but since pledge(2) aborts on non-dev, let's check upfront that we're of the right type.
I don't think this requires a bump. It doesn't really change the interface, just makes it stricter. Index: opendev.3 =================================================================== RCS file: /build/data/openbsd/cvs/src/lib/libutil/opendev.3,v retrieving revision 1.22 diff -u -p -r1.22 opendev.3 --- opendev.3 15 Jan 2015 19:06:32 -0000 1.22 +++ opendev.3 10 Mar 2016 11:51:27 -0000 @@ -93,7 +93,9 @@ it is modified to point at the fully exp The .Fn opendev return value and errors are the same as the return value and errors of -.Xr open 2 . +.Xr open 2 , +plus +.Er EFTYPE . .Sh SEE ALSO .Xr open 2 , .Xr getrawpartition 3 , Index: opendev.c =================================================================== RCS file: /build/data/openbsd/cvs/src/lib/libutil/opendev.c,v retrieving revision 1.15 diff -u -p -r1.15 opendev.c --- opendev.c 30 Jun 2011 15:04:58 -0000 1.15 +++ opendev.c 8 Mar 2016 22:30:44 -0000 @@ -38,6 +38,7 @@ #include <sys/limits.h> #include <sys/disk.h> #include <sys/dkio.h> +#include <sys/stat.h> #include "util.h" @@ -50,6 +51,7 @@ opendev(const char *path, int oflags, in { static char namebuf[PATH_MAX]; struct dk_diskmap dm; + struct stat st; char *slash, *prefix; int fd; @@ -106,5 +108,17 @@ opendev(const char *path, int oflags, in if (realpath) *realpath = namebuf; + if (fd != -1) { + if (fstat(fd, &st) == -1) { + close(fd); + return (-1); + } + if ((dflags & OPENDEV_BLCK) ? !S_ISBLK(st.st_mode) : + !S_ISCHR(st.st_mode)) { + close(fd); + errno = EFTYPE; + return (-1); + } + } return (fd); }