Commit 4010e238a0826aba0cbc42d3a0a175d1edb4c547

Stefan Sperling 2020-12-04T23:27:05

make tog call pledge(2) directly in main() instead of per-command All of tog's pledges are currently the same, and they must be the same because tog allows switching between available command views at run-time. ok tracey

diff --git a/tog/tog.c b/tog/tog.c
index 50fefd4..f3eeaf4 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -2645,12 +2645,6 @@ cmd_log(int argc, char *argv[])
 	int ch, log_branches = 0;
 	struct tog_view *view;
 
-#ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc tty exec sendfd unveil",
-	    NULL) == -1)
-		err(1, "pledge");
-#endif
-
 	while ((ch = getopt(argc, argv, "bc:r:")) != -1) {
 		switch (ch) {
 		case 'b':
@@ -3732,11 +3726,6 @@ cmd_diff(int argc, char *argv[])
 	const char *errstr;
 	struct tog_view *view;
 
-#ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc tty exec sendfd unveil",
-	    NULL) == -1)
-		err(1, "pledge");
-#endif
 	while ((ch = getopt(argc, argv, "aC:r:w")) != -1) {
 		switch (ch) {
 		case 'a':
@@ -4634,12 +4623,6 @@ cmd_blame(int argc, char *argv[])
 	int ch;
 	struct tog_view *view;
 
-#ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc tty exec sendfd unveil",
-	    NULL) == -1)
-		err(1, "pledge");
-#endif
-
 	while ((ch = getopt(argc, argv, "c:r:")) != -1) {
 		switch (ch) {
 		case 'c':
@@ -5435,12 +5418,6 @@ cmd_tree(int argc, char *argv[])
 	int ch;
 	struct tog_view *view;
 
-#ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc tty exec sendfd unveil",
-	    NULL) == -1)
-		err(1, "pledge");
-#endif
-
 	while ((ch = getopt(argc, argv, "c:r:")) != -1) {
 		switch (ch) {
 		case 'c':
@@ -6144,12 +6121,6 @@ cmd_ref(int argc, char *argv[])
 	int ch;
 	struct tog_view *view;
 
-#ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc tty exec sendfd unveil",
-	    NULL) == -1)
-		err(1, "pledge");
-#endif
-
 	while ((ch = getopt(argc, argv, "r:")) != -1) {
 		switch (ch) {
 		case 'r':
@@ -6407,6 +6378,12 @@ main(int argc, char *argv[])
 		return 0;
 	}
 
+#ifndef PROFILE
+	if (pledge("stdio rpath wpath cpath flock proc tty exec sendfd unveil",
+	    NULL) == -1)
+		err(1, "pledge");
+#endif
+
 	if (argc == 0) {
 		if (hflag)
 			usage(hflag, 0);