]> git.armaanb.net Git - stagit.git/commitdiff
add OpenBSD pledge(2) support using -DUSE_PLEDGE
authorHiltjo Posthuma <hiltjo@codemadness.org>
Mon, 2 May 2016 22:33:56 +0000 (00:33 +0200)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Mon, 2 May 2016 22:33:56 +0000 (00:33 +0200)
config.mk
stagit-index.c
stagit.c

index 3c1e5d2c44552a84b1aa02e237471d561d096c25..7479a977a0a94f4680fa7e4ef47ad782dc2a5633 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -4,6 +4,9 @@
 PREFIX = /usr/local
 MANPREFIX = ${PREFIX}/man
 
+# compiler and linker
+#CC = cc
+
 GITINC = /usr/local/include
 GITLIB = /usr/local/lib
 
@@ -23,6 +26,7 @@ LDFLAGS = -s ${LIBS}
 #CFLAGS = -static -O2 -std=c99 ${INCS}
 #LDFLAGS = -static -s ${LIBS}
 
-CPPFLAGS= -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE -D_BSD_SOURCE ${INCS}
-# compiler and linker
-#CC = cc
+CPPFLAGS = -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE -D_BSD_SOURCE ${INCS}
+
+# OpenBSD 5.9+: use pledge(2)
+#CPPFLAGS += -DUSE_PLEDGE
index 1d26e0f9a37172ef191acd884df3cea1bbd21f92..afd83204e33af7ee58b233a2be4a9af36824d809 100644 (file)
@@ -23,6 +23,14 @@ static char description[255] = "Repositories";
 static char *name = "";
 static char owner[255];
 
+#ifndef USE_PLEDGE
+int
+pledge(const char *promises, const char *paths[])
+{
+        return 0;
+}
+#endif
+
 /* Escape characters below as HTML 2.0 / XML 1.0. */
 void
 xmlencode(FILE *fp, const char *s, size_t len)
@@ -154,6 +162,9 @@ main(int argc, char *argv[])
        char path[PATH_MAX], repodirabs[PATH_MAX + 1];
        int i, ret = 0;
 
+       if (pledge("stdio rpath", NULL) == -1)
+               err(1, "pledge");
+
        if (argc < 2) {
                fprintf(stderr, "%s [repodir...]\n", argv[0]);
                return 1;
index 1e4d1bbf80c70f9aceaecdfef0b67e60abb6cf9c..9a8c32fa863f7732833883e2f88443af1cc5d28b 100644 (file)
--- a/stagit.c
+++ b/stagit.c
@@ -64,6 +64,14 @@ static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + nul byte */
 static FILE *rcachefp, *wcachefp;
 static const char *cachefile;
 
+#ifndef USE_PLEDGE
+int
+pledge(const char *promises, const char *paths[])
+{
+       return 0;
+}
+#endif
+
 void
 deltainfo_free(struct deltainfo *di)
 {
@@ -1033,6 +1041,9 @@ main(int argc, char *argv[])
        size_t n;
        int i, fd;
 
+       if (pledge("stdio rpath wpath cpath", NULL) == -1)
+               err(1, "pledge");
+
        for (i = 1; i < argc; i++) {
                if (argv[i][0] != '-') {
                        if (repodir)