shithub: riscv

Download patch

ref: 1b5ea51ee1203952900fafc0def48985d900f7a7
parent: 056ad652a41fde51755aedb8119b37fe5946b12c
author: Jacob Moody <moody@posixcafe.org>
date: Tue Jun 7 22:44:35 EDT 2022

auth/box: bind in the binary by default

This prevents stuttering on the command line by
not having to give a -r flag for the binary itself.

--- a/sys/src/cmd/auth/box.c
+++ b/sys/src/cmd/auth/box.c
@@ -54,9 +54,6 @@
 		case '#':
 		case '/':
 			break;
-		case '.':
-			if(names[i][1] == '/')
-				break;
 		default:
 			names[i] = cleanname(smprint("%s/%s", buf, names[i]));
 		}	
@@ -111,19 +108,6 @@
 	binderr(newroot, "/", MREPL);
 }
 
-static void
-run(char **a)
-{
-	exec(a[0], a);
-
-	if(a[0][0] != '/' && a[0][0] != '#' &&
-	  (a[0][0] != '.' || (a[0][1] != '/' &&
-		             (a[0][1] != '.' ||  a[0][2] != '/'))))
-		exec(smprint("/bin/%s", a[0]), a);
-
-	sysfatal("exec: %s: %r", a[0]);
-}
-
 void
 usage(void)
 {
@@ -134,6 +118,8 @@
 void
 main(int argc, char **argv)
 {
+	char *b;
+	Dir *d;
 	char devs[1024];
 	int dfd;
 	char *parts[256];
@@ -164,6 +150,19 @@
 	if(argc == 0)
 		usage();
 
+	b = argv[0];
+	d = dirstat(b);
+	if(d == nil){
+		b = smprint("/bin/%s", b);
+		d = dirstat(b);
+		if(d == nil)
+			sysfatal("could not stat %s %r", argv[0]);
+	}
+	free(d);
+	parts[nparts] = b;
+	mflags[nparts++] = MREPL;
+	argv[0] = b;
+
 	rfork(RFNAMEG|RFENVG);
 	dfd = open("/dev/drivers", OWRITE|OCEXEC);
 	if(dfd < 0)
@@ -188,5 +187,5 @@
 			sysfatal("could not write chdev: %r");
 	}
 	close(dfd);
-	run(argv);
+	exec(argv[0], argv);
 }