From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id a4ab1354 for ; Fri, 6 Nov 2015 12:34:04 -0500 (EST) Date: Fri, 6 Nov 2015 12:34:04 -0500 (EST) Message-Id: <10372969100144570117.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: merge pledge(2) support from OpenBSD X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- merge pledge(2) support from OpenBSD Modified Files: -------------- mdocml: Makefile configure main.c mandocdb.c Added Files: ----------- mdocml: test-pledge.c Revision Data ------------- Index: mandocdb.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/mandocdb.c,v retrieving revision 1.206 retrieving revision 1.207 diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.206 -r1.207 --- mandocdb.c +++ mandocdb.c @@ -337,6 +337,13 @@ mandocdb(int argc, char *argv[]) size_t j, sz; int ch, i; +#if HAVE_PLEDGE + if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) { + perror("pledge"); + return (int)MANDOCLEVEL_SYSERR; + } +#endif + memset(&conf, 0, sizeof(conf)); memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *)); @@ -410,6 +417,13 @@ mandocdb(int argc, char *argv[]) argc -= optind; argv += optind; +#if HAVE_PLEDGE + if (nodb && pledge("stdio rpath", NULL) == -1) { + perror("pledge"); + return (int)MANDOCLEVEL_SYSERR; + } +#endif + if (OP_CONFFILE == op && argc > 0) { warnx("-C: Too many arguments"); goto usage; @@ -435,6 +449,14 @@ mandocdb(int argc, char *argv[]) * The existing database is usable. Process * all files specified on the command-line. */ +#if HAVE_PLEDGE + if (!nodb && pledge("stdio rpath wpath cpath fattr flock", + NULL) == -1) { + perror("pledge"); + exitcode = (int)MANDOCLEVEL_SYSERR; + goto out; + } +#endif use_all = 1; for (i = 0; i < argc; i++) filescan(argv[i]); --- /dev/null +++ test-pledge.c @@ -0,0 +1,7 @@ +#include + +int +main(void) +{ + return !!pledge("stdio", NULL); +} Index: main.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/main.c,v retrieving revision 1.254 retrieving revision 1.255 diff -Lmain.c -Lmain.c -u -p -r1.254 -r1.255 --- main.c +++ main.c @@ -149,6 +149,11 @@ main(int argc, char *argv[]) return mandocdb(argc, argv); #endif +#if HAVE_PLEDGE + if (pledge("stdio rpath tmppath proc exec flock", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif + /* Search options. */ memset(&conf, 0, sizeof(conf)); @@ -288,6 +293,11 @@ main(int argc, char *argv[]) !isatty(STDOUT_FILENO)) use_pager = 0; +#if HAVE_PLEDGE + if (!use_pager && pledge("stdio rpath flock", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif + /* Parse arguments. */ if (argc > 0) { @@ -414,6 +424,12 @@ main(int argc, char *argv[]) /* mandoc(1) */ +#if HAVE_PLEDGE + if (pledge(use_pager ? "stdio rpath tmppath proc exec" : + "stdio rpath", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif + if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) return (int)MANDOCLEVEL_BADARG; @@ -1004,6 +1020,10 @@ spawn_pager(struct tag_files *tag_files) case 0: break; default: +#if HAVE_PLEDGE + if (pledge("stdio rpath tmppath", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif return pager_pid; } Index: configure =================================================================== RCS file: /home/cvs/mdocml/mdocml/configure,v retrieving revision 1.29 retrieving revision 1.30 diff -Lconfigure -Lconfigure -u -p -r1.29 -r1.30 --- configure +++ configure @@ -50,6 +50,7 @@ HAVE_GETSUBOPT= HAVE_ISBLANK= HAVE_MKDTEMP= HAVE_MMAP= +HAVE_PLEDGE= HAVE_PROGNAME= HAVE_REALLOCARRAY= HAVE_STRCASESTR= @@ -180,6 +181,7 @@ runtest getsubopt GETSUBOPT || true runtest isblank ISBLANK || true runtest mkdtemp MKDTEMP || true runtest mmap MMAP || true +runtest pledge PLEDGE || true runtest progname PROGNAME || true runtest reallocarray REALLOCARRAY || true runtest strcasestr STRCASESTR || true @@ -301,6 +303,7 @@ cat << __HEREDOC__ #define HAVE_ISBLANK ${HAVE_ISBLANK} #define HAVE_MKDTEMP ${HAVE_MKDTEMP} #define HAVE_MMAP ${HAVE_MMAP} +#define HAVE_PLEDGE ${HAVE_PLEDGE} #define HAVE_PROGNAME ${HAVE_PROGNAME} #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY} #define HAVE_STRCASESTR ${HAVE_STRCASESTR} Index: Makefile =================================================================== RCS file: /home/cvs/mdocml/mdocml/Makefile,v retrieving revision 1.473 retrieving revision 1.474 diff -LMakefile -LMakefile -u -p -r1.473 -r1.474 --- Makefile +++ Makefile @@ -28,6 +28,7 @@ TESTSRCS = test-dirent-namlen.c \ test-mkdtemp.c \ test-mmap.c \ test-ohash.c \ + test-pledge.c \ test-progname.c \ test-reallocarray.c \ test-sqlite3.c \ -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv