source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: merge pledge(2) support from OpenBSD
@ 2015-11-06 17:34 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-11-06 17:34 UTC (permalink / raw)
  To: source

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 <unistd.h>
+
+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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-06 17:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-06 17:34 mdocml: merge pledge(2) support from OpenBSD schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).