Bläddra i källkod

Pledge on OpenBSD

Hiltjo Posthuma 6 år sedan
förälder
incheckning
30ce2cc002
2 ändrade filer med 14 tillägg och 0 borttagningar
  1. 6 0
      config.mk
  2. 8 0
      st.c

+ 6 - 0
config.mk

@@ -23,6 +23,12 @@ CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
 STCFLAGS = $(INCS) $(CPPFLAGS) $(CFLAGS)
 STLDFLAGS = $(LIBS) $(LDFLAGS)
 
+# OpenBSD:
+#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
+#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
+#       `pkg-config --libs fontconfig` \
+#       `pkg-config --libs freetype2`
+
 # compiler and linker
 # CC = c99
 

+ 8 - 0
st.c

@@ -28,6 +28,10 @@
  #include <libutil.h>
 #endif
 
+#ifndef __OpenBSD__
+#define pledge(a,b) 0
+#endif
+
 /* Arbitrary sizes */
 #define UTF_INVALID   0xFFFD
 #define UTF_SIZ       4
@@ -806,9 +810,13 @@ ttynew(char *line, char *cmd, char *out, char **args)
 			die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
 		close(s);
 		close(m);
+		if (pledge("stdio getpw proc exec", NULL) == -1)
+			die("pledge\n");
 		execsh(cmd, args);
 		break;
 	default:
+		if (pledge("stdio rpath tty proc", NULL) == -1)
+			die("pledge\n");
 		close(s);
 		cmdfd = m;
 		signal(SIGCHLD, sigchld);