Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add pledge(2) support on OpenBSD
On other platforms, this will be a no-op. Fixes #164.
  • Loading branch information
worr committed Oct 7, 2018
1 parent b365987 commit a3dbe9d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion freebsd/Makefile
Expand Up @@ -27,6 +27,7 @@ all: spectrwm libswmhack.so.$(LVERS)
spectrwm.c:
ln -sf ../spectrwm.c
ln -sf ../version.h
ln -sf ../linux/pledge.h

swm_hack.c:
ln -sf ../lib/swm_hack.c
Expand All @@ -50,7 +51,7 @@ install: all
ln -sf spectrwm $(SWM_BINDIR)/scrotwm

clean:
rm -f spectrwm *.o *.so libswmhack.so.* spectrwm.c swm_hack.c version.h
rm -f spectrwm *.o *.so libswmhack.so.* spectrwm.c swm_hack.c version.h pledge.h

.PHONY: all install clean

Expand Down
1 change: 1 addition & 0 deletions linux/pledge.h
@@ -0,0 +1 @@
#define pledge(promises, execpromises) (0)
3 changes: 2 additions & 1 deletion osx/Makefile
Expand Up @@ -37,6 +37,7 @@ spectrwm.c:
ln -sf ../linux/tree.h
ln -sf ../spectrwm.c
ln -sf ../version.h
ln -sf ../linux/pledge.h

swm_hack.c:
ln -sf ../lib/swm_hack.c
Expand Down Expand Up @@ -64,6 +65,6 @@ install: all
ln -sf libswmhack.so.0.0 $(DESTDIR)$(LIBDIR)/libswmhack.so

clean:
rm -f spectrwm *.o *.so libswmhack.so.* spectrwm.c swm_hack.c tree.h version.h
rm -f spectrwm *.o *.so libswmhack.so.* spectrwm.c swm_hack.c tree.h version.h pledge.h

.PHONY: all install clean
12 changes: 12 additions & 0 deletions spectrwm.c
Expand Up @@ -54,6 +54,9 @@
#include <fcntl.h>
#include <locale.h>
#include <paths.h>
#if !defined(__OpenBSD__)
#include "pledge.h"
#endif
#include <pwd.h>
#include <regex.h>
#include <signal.h>
Expand Down Expand Up @@ -3880,6 +3883,9 @@ spawn(int ws_idx, union arg *args, bool close_fd)
if (args == NULL || args->argv[0] == NULL)
return;

if (pledge("stdio proc exec", NULL) == -1)
err(1, "pledge");

DNPRINTF(SWM_D_MISC, "%s\n", args->argv[0]);

close(xcb_get_file_descriptor(conn));
Expand Down Expand Up @@ -12469,6 +12475,9 @@ main(int argc, char *argv[])
if (setlocale(LC_CTYPE, "") == NULL || setlocale(LC_TIME, "") == NULL)
warnx("no locale support");

if (pledge("stdio rpath proc exec getpw dns unix", NULL) == -1)
err(1, "pledge");

/* handle some signals */
bzero(&sact, sizeof(sact));
sigemptyset(&sact.sa_mask);
Expand All @@ -12495,6 +12504,9 @@ main(int argc, char *argv[])
xcb_prefetch_extension_data(conn, &xcb_randr_id);
xfd = xcb_get_file_descriptor(conn);

if (pledge("stdio rpath proc exec getpw", NULL) == -1)
err(1, "pledge");

/* look for local and global conf file */
pwd = getpwuid(getuid());
if (pwd == NULL)
Expand Down

0 comments on commit a3dbe9d

Please sign in to comment.