From 72ef8d00bcb7cbdc0eb77b39c6bdc521d0bd3010 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 10 Aug 2024 15:22:07 -0600 Subject: [PATCH] npc(1): adds pledge(2) support --- src/npc.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/npc.c b/src/npc.c index 7ef760a..ca16171 100644 --- a/src/npc.c +++ b/src/npc.c @@ -19,8 +19,13 @@ #include /* fprintf(3), fputs(3), getc(3), perror(3), putc(3), stdin, * stdout, EOF */ -#include /* EX_IOERR, EX_OK, EX_USAGE */ -#include /* getopt(3) */ +#include /* EX_IOERR, EX_OK, EX_OSERR, EX_USAGE */ +#include /* pledge(2), getopt(3) */ + +#ifdef __OpenBSD__ +# include /* errno */ +# include /* strerror(3) */ +#endif char *program_name = "npc"; @@ -39,13 +44,22 @@ usage(char *argv0) { } int main(int argc, char *argv[]) { +#ifdef __OpenBSD__ + program_name = argv[0] == NULL ? program_name : argv[0]; + + if (pledge("stdio", NULL) == -1) { + (void)fprintf(stderr, "%s: %s\n", program_name, strerror(errno)); + return EX_OSERR; + } +#endif int c; char showend = 0; /* print a dollar sign before each newline */ char showtab = 0; /* prints tab characters in caret notation */ if (argc > 0) { +#ifndef __OpenBSD__ program_name = argv[0]; - +#endif while ((c = getopt(argc, argv, "et")) != -1) { switch (c){ case 'e': showend = 1; break;