dslinux/user/busybox/shell msh.c

stsp stsp at user.in-berlin.de
Wed Jun 28 16:57:58 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/busybox/shell
In directory antilope:/tmp/cvs-serv21942

Modified Files:
	msh.c 
Log Message:
Look up proper value for $HOME in /etc/passwd.
Change cwd to $HOME on startup.


Index: msh.c
===================================================================
RCS file: /cvsroot/dslinux/dslinux/user/busybox/shell/msh.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- msh.c	20 Feb 2006 14:13:34 -0000	1.2
+++ msh.c	28 Jun 2006 14:57:55 -0000	1.3
@@ -44,6 +44,7 @@
 #include <sys/times.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <pwd.h>
 
 #include "cmdedit.h"
 #include "busybox.h"
@@ -825,6 +826,8 @@
 	int cflag;
 	char *name, **ap;
 	int (*iof) (struct ioarg *);
+	uid_t uid;
+	struct passwd *pw;
 
 	DBGPRINTF(("MSH_MAIN: argc %d, environ 0x%x\n", argc, environ));
 
@@ -844,10 +847,24 @@
 	export(shell);
 
 	homedir = lookup("HOME");
+	uid = getuid();
+	pw = NULL;
+	do {
+		if ((pw = getpwent()) != NULL) {
+			if (pw->pw_uid == uid) {
+				setval(homedir, pw->pw_dir);
+				break;
+			}
+		}
+	} while (pw != NULL);
+	endpwent();
+
 	if (homedir->value == null)
 		setval(homedir, "/");
 	export(homedir);
 
+	chdir(homedir->value); /* Ignore return value. homedir should be sane. */
+
 	setval(lookup("$"), putn(getpid()));
 
 	path = lookup("PATH");




More information about the dslinux-commit mailing list