shithub: riscv

Download patch

ref: 20883bd7de7097936fe87e5fce4d08033ea6c88c
parent: 2185188f8360ea1952c7339c2702a16f15b12be1
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri May 23 22:09:52 EDT 2014

cpu: remove duplicate environment and chdir($home) code (thanks qrstuv)

newns() (called by auth_chuid()) already prepares the
environment variables and puts us in a sane working
directory (as specified by the namespace file).

--- a/sys/src/cmd/cpu.c
+++ b/sys/src/cmd/cpu.c
@@ -335,7 +335,7 @@
 void
 remoteside(int old)
 {
-	char user[MaxStr], home[MaxStr], buf[MaxStr], xdir[MaxStr], cmd[MaxStr];
+	char user[MaxStr], buf[MaxStr], xdir[MaxStr], cmd[MaxStr];
 	int i, n, fd, badchdir, gotcmd;
 
 	rfork(RFENVG);
@@ -364,11 +364,6 @@
 	if(fd < 0)
 		fatal("srvauth: %r");
 
-	/* Set environment values for the user */
-	putenv("user", user);
-	snprint(home, sizeof(home), "/usr/%s", user);
-	putenv("home", home);
-
 	/* Now collect invoking cpu's current directory or possibly a command */
 	gotcmd = 0;
 	if(readstr(fd, xdir, sizeof(xdir)) < 0)
@@ -380,15 +375,11 @@
 			fatal("dir: %r");
 	}
 
-	/* Establish the new process at the current working directory of the
-	 * gnot */
+	/* Establish the new process at the current working directory of the gnot */
 	badchdir = 0;
-	if(strcmp(xdir, "NO") == 0)
-		chdir(home);
-	else if(chdir(xdir) < 0) {
-		badchdir = 1;
-		chdir(home);
-	}
+	if(strcmp(xdir, "NO") != 0)
+		if(chdir(xdir) < 0)
+			badchdir = 1;
 
 	/* Start the gnot serving its namespace */
 	writestr(fd, "FS", "FS", 0);