walk

A re-creation of the 9front utility walk(1) for UNIX
Log | Files | Refs

commit 6f32155892803fc214920feaea631754a26cf420
parent 4ffe035822b41f6aa37479a566c47a1fc95c7288
Author: Jacob R. Edwards <n/a>
Date:   Mon,  5 Dec 2022 13:02:59 -0600

Add pledge(2) and unveil(2) on OpenBSD

Diffstat:
Mwalk.c | 23++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/walk.c b/walk.c @@ -196,6 +196,12 @@ main(int argc, char *argv[]) enum { DIR = 1, NOTDIR } type; +#ifdef __OpenBSD__ + int i; + + if (pledge("stdio rpath unveil", NULL)) + die("pledge"); +#endif type = 0; exec = 0; @@ -250,15 +256,26 @@ main(int argc, char *argv[]) argv += optind; argc -= optind; - if (!vbuf && setvbuf(stdout, NULL, 0, _IOFBF)) - perror("setvbuf _IOFBF"); - if (argc) { offset = 0; } else { offset = 2; argv = (char *[]){ ".", NULL }; + ++argc; } + +#ifdef __OpenBSD__ + /* NOTE: the error for ENOENT is more helpful when running OpenBSD */ + for (i = 0; i < argc; ++i) + if (unveil(argv[i], "r")) + die(argv[i]); + if (unveil(NULL, NULL)) + die("unveil"); +#endif + + if (!vbuf && setvbuf(stdout, NULL, 0, _IOFBF)) + perror("setvbuf _IOFBF"); + fts = fts_open(argv, FTS_PHYSICAL, NULL); if (!fts) die("fts open");