From b1a4a1a2b95c708009b1557dc03f453bd1ae8ddd Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 10 Aug 2024 22:03:59 -0600 Subject: [PATCH] dj(1): use entirely-stdio error messages for OpenBSD functions --- src/dj.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dj.c b/src/dj.c index e4ddd71..ad1dc49 100644 --- a/src/dj.c +++ b/src/dj.c @@ -108,8 +108,10 @@ Io_write(struct Io *io) { } static int -oserr(char *e, int n) { - (void)fprintf(stderr, "%s: %s: %s\n", program_name, e, strerror(n)); +oserr(char *e, int n) { /* program_name: [failing component:] error */ + (void)fprintf(stderr, "%s: ", program_name); + if (e != NULL) { (void)fprintf(stderr, "%s: ", e); } + (void)fprintf(stderr, "%s\n", strerror(n)); return EX_OSERR; } @@ -170,7 +172,7 @@ usage(char *argv0) { int main(int argc, char *argv[]) { #ifdef __OpenBSD__ if (pledge("cpath rpath stdio unveil wpath", NULL) == -1) { - return oserr("pledge", errno); + return oserr(NULL", errno); } #endif @@ -222,7 +224,7 @@ int main(int argc, char *argv[]) { if (i == 0) { perms = "r"; } if (unveil(optarg, perms) == -1) { - return oserr("unveil", errno); + return oserr(NULL, errno); } #endif @@ -266,7 +268,7 @@ int main(int argc, char *argv[]) { } } #ifdef __OpenBSD__ - if (unveil(NULL, NULL) == -1) { return oserr("unveil", errno); } + if (unveil(NULL, NULL) == -1) { return oserr(NULL, errno); } #endif assert(io->fd != STDIN_FILENO || io->fl == read_flags);