-/* $NetBSD: cd.c,v 1.13 1995/05/11 21:28:49 christos Exp $ */
+/* $NetBSD: cd.c,v 1.14 1995/11/19 23:27:37 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
#if 0
static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95";
#else
-static char rcsid[] = "$NetBSD: cd.c,v 1.13 1995/05/11 21:28:49 christos Exp $";
+static char rcsid[] = "$NetBSD: cd.c,v 1.14 1995/11/19 23:27:37 christos Exp $";
#endif
#endif /* not lint */
#include "redir.h"
#include "mystring.h"
#include "show.h"
+#include "cd.h"
STATIC int docd __P((char *, int));
STATIC char *getcomponent __P((void));
STATIC void updatepwd __P((char *));
-STATIC void getpwd __P((void));
-char *curdir; /* current working directory */
+char *curdir = NULL; /* current working directory */
char *prevdir; /* previous working directory */
STATIC char *cdcomppath;
-/*
- * If we already know the current directory, this routine returns
- * immediately.
- */
#define MAXPWD 256
-STATIC void
-getpwd() {
+/*
+ * Find out what the current directory is. If we already know the current
+ * directory, this routine returns immediately.
+ */
+void
+getpwd()
+{
char buf[MAXPWD];
- char *p;
- int i;
- int status;
- struct job *jp;
- int pip[2];
if (curdir)
return;
+ /*
+ * Things are a bit complicated here; we could have just used
+ * getcwd, but traditionally getcwd is implemented using popen
+ * to /bin/pwd. This creates a problem for us, since we cannot
+ * keep track of the job if it is being ran behind our backs.
+ * So we re-implement getcwd(), and we suppress interrupts
+ * throughout the process. This is not completely safe, since
+ * the user can still break out of it by killing the pwd program.
+ * We still try to use getcwd for systems that we know have a
+ * c implementation of getcwd, that does not open a pipe to
+ * /bin/pwd.
+ */
+#if defined(__NetBSD__) || defined(__svr4__)
if (getcwd(buf, sizeof(buf)) == NULL)
error("getcwd() failed");
+#else
+ {
+ char *p;
+ int i;
+ int status;
+ struct job *jp;
+ int pip[2];
+
+ INTOFF;
+ if (pipe(pip) < 0)
+ error("Pipe call failed");
+ jp = makejob((union node *)NULL, 1);
+ if (forkshell(jp, (union node *)NULL, FORK_NOJOB) == 0) {
+ (void) close(pip[0]);
+ if (pip[1] != 1) {
+ close(1);
+ copyfd(pip[1], 1);
+ close(pip[1]);
+ }
+ (void) execl("/bin/pwd", "pwd", (char *)0);
+ error("Cannot exec /bin/pwd");
+ }
+ (void) 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;
+ }
+ (void) 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';
+ }
+#endif
curdir = savestr(buf);
+ INTON;
}
-/* $NetBSD: input.c,v 1.18 1995/10/06 21:38:18 christos Exp $ */
+/* $NetBSD: input.c,v 1.19 1995/10/19 04:14:37 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
#if 0
static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95";
#else
-static char rcsid[] = "$NetBSD: input.c,v 1.18 1995/10/06 21:38:18 christos Exp $";
+static char rcsid[] = "$NetBSD: input.c,v 1.19 1995/10/19 04:14:37 christos Exp $";
#endif
#endif /* not lint */
savec = *q;
*q = '\0';
+#ifndef NO_HISTORY
if (parsefile->fd == 0 && hist && something) {
INTOFF;
history(hist, whichprompt == 1 ? H_ENTER : H_ADD, parsenextc);
INTON;
}
+#endif
if (vflag) {
out2str(parsenextc);
-/* $NetBSD: main.c,v 1.22 1995/09/11 17:05:44 christos Exp $ */
+/* $NetBSD: main.c,v 1.23 1995/11/19 23:27:42 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
#if 0
static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95";
#else
-static char rcsid[] = "$NetBSD: main.c,v 1.22 1995/09/11 17:05:44 christos Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.23 1995/11/19 23:27:42 christos Exp $";
#endif
#endif /* not lint */
#include "init.h"
#include "mystring.h"
#include "exec.h"
+#include "cd.h"
#define PROFILE 0
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
-/* $NetBSD: parser.c,v 1.26 1995/05/17 00:05:25 christos Exp $ */
+/* $NetBSD: parser.c,v 1.27 1995/10/19 04:14:41 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
#if 0
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
#else
-static char rcsid[] = "$NetBSD: parser.c,v 1.26 1995/05/17 00:05:25 christos Exp $";
+static char rcsid[] = "$NetBSD: parser.c,v 1.27 1995/10/19 04:14:41 christos Exp $";
#endif
#endif /* not lint */
if (!oldstyle && (readtoken() != TRP))
synexpect(TRP);
(*nlpp)->n = n;
- /* Start reading from old file again. */
- if (oldstyle)
+ if (oldstyle) {
+ /*
+ * Start reading from old file again, ignoring any pushed back
+ * tokens left from the backquote parsing
+ */
popfile();
+ tokpushback = 0;
+ }
while (stackblocksize() <= savelen)
growstackblock();
STARTSTACKSTR(out);