Hi all,

new versions of all four patches attached. Changes:

- Added dummy pledge definition on other platforms
- Added xpledge, refactored
- Added rpath to final pledge in dwm; turns out xfont sometimes wants
  new fonts at runtime.

Cheers!
K.

diff --git a/dmenu.c b/dmenu.c
index e0c2f80..72f8207 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <ctype.h>
+#include <errno.h>
 #include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -15,6 +16,13 @@
 #endif
 #include <X11/Xft/Xft.h>
 
+/* portability */
+#ifdef __OpenBSD__
+#include <unistd.h>
+#else
+int pledge(const char *promises, const char *paths[]) { return 0; }
+#endif
+
 #include "drw.h"
 #include "util.h"
 
@@ -491,11 +499,21 @@ readstdin(void)
 	lines = MIN(lines, i);
 }
 
+void
+xpledge(const char *promises, const char *paths[])
+{
+	if (pledge(promises, paths) < 0) {
+		die("dmenu: pledge: %s (%s)\n", strerror(errno), promises);
+	}
+}
+
 static void
 run(void)
 {
 	XEvent ev;
 
+	xpledge("stdio", NULL);
+
 	while (!XNextEvent(dpy, &ev)) {
 		if (XFilterEvent(&ev, win))
 			continue;
@@ -654,6 +672,8 @@ main(int argc, char *argv[])
 		else
 			usage();
 
+	xpledge("stdio rpath dns unix", NULL);
+
 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
 		fputs("warning: no locale support\n", stderr);
 	if (!(dpy = XOpenDisplay(NULL)))
@@ -668,6 +688,8 @@ main(int argc, char *argv[])
 		die("no fonts could be loaded.\n");
 	drw_setscheme(drw, &scheme[SchemeNorm]);
 
+	xpledge("stdio rpath", NULL);
+
 	if (fast) {
 		grabkeyboard();
 		readstdin();
diff --git a/dwm.c b/dwm.c
index ff7e096..efd5d12 100644
--- a/dwm.c
+++ b/dwm.c
@@ -57,6 +57,11 @@
 #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
 #define TEXTW(X)                (drw_text(drw, 0, 0, 0, 0, (X), 0) + drw->fonts[0]->h)
 
+/* portability */
+#ifndef __OpenBSD__
+int pledge(const char *promises, const char *paths[]) { return 0; }
+#endif
+
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
 enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
@@ -232,6 +237,7 @@ static Monitor *wintomon(Window w);
 static int xerror(Display *dpy, XErrorEvent *ee);
 static int xerrordummy(Display *dpy, XErrorEvent *ee);
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
+static void xpledge(const char *promises, const char *paths[]);
 static void zoom(const Arg *arg);
 
 /* variables */
@@ -2112,6 +2118,14 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
 }
 
 void
+xpledge(const char *promises, const char *paths[])
+{
+	if (pledge(promises, paths) < 0) {
+		die("dwm: pledge: %s (%s)\n", strerror(errno), promises);
+	}
+}
+
+void
 zoom(const Arg *arg)
 {
 	Client *c = selmon->sel;
@@ -2132,13 +2146,16 @@ main(int argc, char *argv[])
 		die("dwm-"VERSION "\n");
 	else if (argc != 1)
 		die("usage: dwm [-v]\n");
+	xpledge("stdio rpath dns unix prot_exec proc exec", NULL);
 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
 		fputs("warning: no locale support\n", stderr);
 	if (!(dpy = XOpenDisplay(NULL)))
 		die("dwm: cannot open display\n");
+	xpledge("stdio rpath prot_exec proc exec", NULL);
 	checkotherwm();
 	setup();
 	scan();
+	xpledge("stdio rpath proc exec", NULL);
 	run();
 	cleanup();
 	XCloseDisplay(dpy);
diff --git a/st.c b/st.c
index 27536d2..5b18b58 100644
--- a/st.c
+++ b/st.c
@@ -45,6 +45,9 @@ char *argv0;
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
  #include <libutil.h>
 #endif
+#ifndef __OpenBSD__
+int pledge(const char *promises, const char *paths[]) { return 0; }
+#endif
 
 
 /* XEMBED messages */
@@ -368,6 +371,7 @@ static void execsh(void);
 static void stty(void);
 static void sigchld(int);
 static void run(void);
+static void xpledge(const char *promises, const char *paths[]);
 
 static void csidump(void);
 static void csihandle(void);
@@ -4224,6 +4228,8 @@ run(void)
 	struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
 	long deltatime;
 
+	xpledge("stdio rpath wpath tty proc getpw exec", NULL);
+
 	/* Waiting for window mapping */
 	do {
 		XNextEvent(xw.dpy, &ev);
@@ -4247,6 +4253,8 @@ run(void)
 	clock_gettime(CLOCK_MONOTONIC, &last);
 	lastblink = last;
 
+	xpledge("stdio rpath tty proc", NULL);
+
 	for (xev = actionfps;;) {
 		FD_ZERO(&rfd);
 		FD_SET(cmdfd, &rfd);
@@ -4336,6 +4344,14 @@ usage(void)
 	    " [stty_args ...]\n", argv0, argv0);
 }
 
+void
+xpledge(const char *promises, const char *paths[])
+{
+	if (pledge(promises, paths) < 0) {
+		die("st: pledge: %s (%s)\n", strerror(errno), promises);
+	}
+}
+
 int
 main(int argc, char *argv[])
 {
diff --git a/slock.c b/slock.c
index c9cdee2..d8b9913 100644
--- a/slock.c
+++ b/slock.c
@@ -23,6 +23,10 @@
 #include <bsd_auth.h>
 #endif
 
+#ifndef __OpenBSD__
+int pledge(const char *promises, const char *paths[]) { return 0; }
+#endif
+
 enum {
 	INIT,
 	INPUT,
@@ -280,6 +284,14 @@ usage(void)
 	exit(1);
 }
 
+void
+xpledge(const char *promises, const char *paths[])
+{
+	if (pledge(promises, paths) < 0) {
+		die("slock: pledge: %s (%s)\n", strerror(errno), promises);
+	}
+}
+
 int
 main(int argc, char **argv) {
 #ifndef HAVE_BSD_AUTH
@@ -299,6 +311,8 @@ main(int argc, char **argv) {
 	dontkillme();
 #endif
 
+	xpledge("stdio dns unix rpath prot_exec getpw proc exec", NULL);
+
 	if (!getpwuid(getuid()))
 		die("no passwd entry for you\n");
 
@@ -334,6 +348,8 @@ main(int argc, char **argv) {
 		die("execvp %s failed: %s\n", argv[1], strerror(errno));
 	}
 
+	xpledge("stdio rpath getpw proc exec", NULL);
+
 	/* Everything is now blank. Now wait for the correct password. */
 #ifdef HAVE_BSD_AUTH
 	readpw(dpy);

Reply via email to