Subject: Change to sh(1) working out pwd on startup?
To: None <tech-userlevel@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-userlevel
Date: 04/18/2006 23:18:39
The fix for bin/31548 (sh setting PWD on startup) broke the
regression test in regress/sys/kern/umount.  That regression test
runs a shell script in a directory that has been "umount -f"'d,
and now fails to start the shell.

Starting a shell in a directory that doesn't exist does this:

	dbau1500 166# sh
	getcwd() failed: Not a directory
	Exit 2

The "Exit 2" is printed by tcsh.  Starting ksh does:

	dbau1500 167# ksh
	ksh: Cannot determine current working directory
	#

The following patch changes sh's behaviour to:

	dbau1500 168# /NetBSD/src-virgin/bin/sh/obj.evbmips/sh
	Cannot determine current working directory
	# pwd
	pwd: getcwd() failed: Not a directory
	#

OK to apply?

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/

Index: cd.c
===================================================================
RCS file: /cvsroot/src/bin/sh/cd.c,v
retrieving revision 1.38
diff -d -p -u -r1.38 cd.c
--- cd.c	26 Nov 2005 21:44:43 -0000	1.38
+++ cd.c	18 Apr 2006 13:13:53 -0000
@@ -335,8 +335,11 @@ pwdcmd(int argc, char **argv)
 void
 initpwd(void)
 {
-	getpwd(0);
-	setvar("PWD", curdir, VEXPORT);
+	getpwd(1);
+	if (curdir)
+		setvar("PWD", curdir, VEXPORT);
+	else
+		sh_warnx("Cannot determine current working directory");
 }
 
 #define MAXPWD 256