From 10b7f7706b5c89c19a1aed3dce95249d89ffe9db Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 10 Aug 2024 22:16:06 -0600 Subject: [PATCH] dj(1): tweak OpenBSD functions --- src/dj.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/dj.c b/src/dj.c index ad1dc49..6d6a117 100644 --- a/src/dj.c +++ b/src/dj.c @@ -170,12 +170,6 @@ usage(char *argv0) { } int main(int argc, char *argv[]) { -#ifdef __OpenBSD__ - if (pledge("cpath rpath stdio unveil wpath", NULL) == -1) { - return oserr(NULL", errno); - } -#endif - int align; /* low 8b used, negative if no alignment is being done */ int count; /* -1 if dj(1) runs until no more reads are possible */ char *fmt; /* set to fmt_asv (default) or fmt_human (-H) */ @@ -183,6 +177,12 @@ int main(int argc, char *argv[]) { bool retry; /* false if exits on partial reads or writes */ struct Io io[2 /* { in, out } */]; +#ifdef __OpenBSD__ + if (pledge("cpath rpath stdio unveil wpath", NULL) == -1) { + return oserr(NULL, errno); + } +#endif + /* Set defaults. */ align = -1; count = -1; @@ -217,13 +217,9 @@ int main(int argc, char *argv[]) { break; } else { int fd; + #ifdef __OpenBSD__ - char *perms = "wc"; - - /* modify perms in-place to read-only */ - if (i == 0) { perms = "r"; } - - if (unveil(optarg, perms) == -1) { + if (unveil(optarg, i == 0 ? "r" : "wc") == -1) { return oserr(NULL, errno); } #endif @@ -267,6 +263,7 @@ int main(int argc, char *argv[]) { } } } + #ifdef __OpenBSD__ if (unveil(NULL, NULL) == -1) { return oserr(NULL, errno); } #endif