summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-31 22:51:29 -0500
committerJune McEnroe <june@causal.agency>2018-12-31 22:51:29 -0500
commit715f2cdf2f880b64cb453d353574a7e45de6e1b5 (patch)
tree3954deba2a28f992b857a66a443c76ea2b3cc419
parentHandle ERR from getch (diff)
downloadplay-715f2cdf2f880b64cb453d353574a7e45de6e1b5.tar.gz
play-715f2cdf2f880b64cb453d353574a7e45de6e1b5.zip
Use capsicum on FreeBSD
-rw-r--r--play.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/play.c b/play.c
index 23011f6..3814d0f 100644
--- a/play.c
+++ b/play.c
@@ -25,6 +25,10 @@
 #include <sysexits.h>
 #include <time.h>
 
+#ifdef __FreeBSD__
+#include <sys/capsicum.h>
+#endif
+
 typedef unsigned uint;
 
 uint play2048(void);
@@ -152,10 +156,25 @@ static void draw(size_t new) {
 }
 
 int main(void) {
-	struct Score new = { .date = time(NULL) };
-	new.score = play2048();
-
+	curse();
 	FILE *file = scoresOpen("2048.scores");
+
+#ifdef __FreeBSD__
+	int error = cap_enter();
+	if (error) err(EX_OSERR, "cap_enter");
+
+	cap_rights_t rights;
+	cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_SEEK, CAP_FLOCK);
+
+	error = cap_rights_limit(fileno(file), &rights);
+	if (error) err(EX_OSERR, "cap_rights_limit");
+#endif
+
+	struct Score new = {
+		.date = time(NULL),
+		.score = play2048(),
+	};
+
 	scoresRead(file);
 	size_t index = scoresInsert(new);