summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1995-11-22 10:32:52 +0000
committerderaadt <deraadt@openbsd.org>1995-11-22 10:32:52 +0000
commitae8f68c4a7c2f557bbb94bc357693d44edbb57dd (patch)
treef908339ac303e5813d3b2f0e11068b82d40d53ac
parentfrom netbsd: (diff)
downloadwireguard-openbsd-ae8f68c4a7c2f557bbb94bc357693d44edbb57dd.tar.xz
wireguard-openbsd-ae8f68c4a7c2f557bbb94bc357693d44edbb57dd.zip
handle "cd -" causing crash if used as first sh command; from scottr@Plexus.COM; netbsd pr#1760
-rw-r--r--bin/sh/cd.c39
-rw-r--r--bin/sh/main.c2
2 files changed, 6 insertions, 35 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index f11b9ad4d10..c8a13573fc8 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -328,10 +328,8 @@ pwdcmd(argc, argv)
/*
- * Run /bin/pwd to find out what the current directory is. We suppress
- * interrupts throughout most of this, but the user can still break out
- * of it by killing the pwd program. If we already know the current
- * directory, this routine returns immediately.
+ * If we already know the current directory, this routine returns
+ * immediately.
*/
#define MAXPWD 256
@@ -347,36 +345,7 @@ getpwd() {
if (curdir)
return;
- INTOFF;
- if (pipe(pip) < 0)
- error("Pipe call failed");
- jp = makejob((union node *)NULL, 1);
- if (forkshell(jp, (union node *)NULL, FORK_NOJOB) == 0) {
- close(pip[0]);
- if (pip[1] != 1) {
- close(1);
- copyfd(pip[1], 1);
- close(pip[1]);
- }
- execl("/bin/pwd", "pwd", (char *)0);
- error("Cannot exec /bin/pwd");
- }
- close(pip[1]);
- pip[1] = -1;
- p = buf;
- while ((i = read(pip[0], p, buf + MAXPWD - p)) > 0
- || (i == -1 && errno == EINTR)) {
- if (i > 0)
- p += i;
- }
- close(pip[0]);
- pip[0] = -1;
- status = waitforjob(jp);
- if (status != 0)
- error((char *)0);
- if (i < 0 || p == buf || p[-1] != '\n')
- error("pwd command failed");
- p[-1] = '\0';
+ if (getcwd(buf, sizeof(buf)) == NULL)
+ error("getcwd() failed");
curdir = savestr(buf);
- INTON;
}
diff --git a/bin/sh/main.c b/bin/sh/main.c
index caa4bdf99de..f11a9a60897 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -91,6 +91,7 @@ extern int etext();
STATIC void read_profile __P((char *));
STATIC char *find_dot_file __P((char *));
+STATIC void getpwd __P((void));
/*
* Main routine. We initialize things, parse the arguments, execute
@@ -159,6 +160,7 @@ main(argc, argv)
init();
setstackmark(&smark);
procargs(argc, argv);
+ getpwd();
if (argv[0] && argv[0][0] == '-') {
state = 1;
read_profile("/etc/profile");