add OpenBSD pledge(2) support using -DUSE_PLEDGE
3 files changed, 29 insertions(+), 3 deletions(-) | |||
---|---|---|---|
M | config.mk | +7 | -3 |
M | stagit-index.c | +11 | -0 |
M | stagit.c | +11 | -0 |
1@@ -4,6 +4,9 @@
2 PREFIX = /usr/local
3 MANPREFIX = ${PREFIX}/man
4
5+# compiler and linker
6+#CC = cc
7+
8 GITINC = /usr/local/include
9 GITLIB = /usr/local/lib
10
11@@ -23,6 +26,7 @@ LDFLAGS = -s ${LIBS}
12 #CFLAGS = -static -O2 -std=c99 ${INCS}
13 #LDFLAGS = -static -s ${LIBS}
14
15-CPPFLAGS= -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE -D_BSD_SOURCE ${INCS}
16-# compiler and linker
17-#CC = cc
18+CPPFLAGS = -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE -D_BSD_SOURCE ${INCS}
19+
20+# OpenBSD 5.9+: use pledge(2)
21+#CPPFLAGS += -DUSE_PLEDGE
M · stagit-index.c
+11, -0 1@@ -23,6 +23,14 @@ static char description[255] = "Repositories";
2 static char *name = "";
3 static char owner[255];
4
5+#ifndef USE_PLEDGE
6+int
7+pledge(const char *promises, const char *paths[])
8+{
9+ return 0;
10+}
11+#endif
12+
13 /* Escape characters below as HTML 2.0 / XML 1.0. */
14 void
15 xmlencode(FILE *fp, const char *s, size_t len)
16@@ -154,6 +162,9 @@ main(int argc, char *argv[])
17 char path[PATH_MAX], repodirabs[PATH_MAX + 1];
18 int i, ret = 0;
19
20+ if (pledge("stdio rpath", NULL) == -1)
21+ err(1, "pledge");
22+
23 if (argc < 2) {
24 fprintf(stderr, "%s [repodir...]\n", argv[0]);
25 return 1;
M · stagit.c
+11, -0 1@@ -64,6 +64,14 @@ static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + nul byte */
2 static FILE *rcachefp, *wcachefp;
3 static const char *cachefile;
4
5+#ifndef USE_PLEDGE
6+int
7+pledge(const char *promises, const char *paths[])
8+{
9+ return 0;
10+}
11+#endif
12+
13 void
14 deltainfo_free(struct deltainfo *di)
15 {
16@@ -1033,6 +1041,9 @@ main(int argc, char *argv[])
17 size_t n;
18 int i, fd;
19
20+ if (pledge("stdio rpath wpath cpath", NULL) == -1)
21+ err(1, "pledge");
22+
23 for (i = 1; i < argc; i++) {
24 if (argv[i][0] != '-') {
25 if (repodir)