summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-07-24 23:19:22 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-07-24 23:19:22 +0000
commitde3d490b81a105ff74841598e34686c148c2c49b (patch)
tree89e7ea58b014c4332c71713af895261ab0d9554a /bin
parentbfe23ee41b6ac3ff84998118d604dd58f425a9fc (diff)
Stash fd of cwd instead of using getcwd() to stash path.
This works in cases where the parent dir is not readable.
Diffstat (limited to 'bin')
-rw-r--r--bin/pax/ar_subs.c9
-rw-r--r--bin/pax/extern.h4
-rw-r--r--bin/pax/ftree.c12
-rw-r--r--bin/pax/pax.c13
4 files changed, 20 insertions, 18 deletions
diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
index e3229427c66..ce994dcf4be 100644
--- a/bin/pax/ar_subs.c
+++ b/bin/pax/ar_subs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar_subs.c,v 1.9 1997/07/23 19:15:54 kstailey Exp $ */
+/* $OpenBSD: ar_subs.c,v 1.10 1997/07/24 23:19:17 millert Exp $ */
/* $NetBSD: ar_subs.c,v 1.5 1995/03/21 09:07:06 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ar_subs.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: ar_subs.c,v 1.9 1997/07/23 19:15:54 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: ar_subs.c,v 1.10 1997/07/24 23:19:17 millert Exp $";
#endif
#endif /* not lint */
@@ -349,8 +349,9 @@ extract()
* if required, chdir around.
*/
if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
- if (chdir(cwdpt) != 0)
- syswarn(1, errno, "Can't chdir to %s", cwdpt);
+ if (fchdir(cwdfd) != 0)
+ syswarn(1, errno,
+ "Can't fchdir to starting directory");
}
/*
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index 64b7c8a903f..6fbf7b88a32 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.13 1997/06/04 00:15:15 millert Exp $ */
+/* $OpenBSD: extern.h,v 1.14 1997/07/24 23:19:18 millert Exp $ */
/* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */
/*-
@@ -210,6 +210,7 @@ int set_dest __P((register ARCHD *, char *, int));
extern int act;
extern FSUB *frmt;
extern int cflag;
+extern int cwdfd;
extern int dflag;
extern int iflag;
extern int kflag;
@@ -237,7 +238,6 @@ extern int docrc;
extern char *dirptr;
extern char *ltmfrmt;
extern char *argv0;
-extern char *cwdpt;
int main __P((int, char **));
void sig_cleanup __P((int));
diff --git a/bin/pax/ftree.c b/bin/pax/ftree.c
index ed846c5ddf7..2823c5df8eb 100644
--- a/bin/pax/ftree.c
+++ b/bin/pax/ftree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftree.c,v 1.5 1997/06/04 00:15:16 millert Exp $ */
+/* $OpenBSD: ftree.c,v 1.6 1997/07/24 23:19:19 millert Exp $ */
/* $NetBSD: ftree.c,v 1.4 1995/03/21 09:07:21 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ftree.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: ftree.c,v 1.5 1997/06/04 00:15:16 millert Exp $";
+static char rcsid[] = "$OpenBSD: ftree.c,v 1.6 1997/07/24 23:19:19 millert Exp $";
#endif
#endif /* not lint */
@@ -328,10 +328,10 @@ ftree_arg()
else if ((ftcur = ftcur->fow) == NULL)
return(-1);
if (ftcur->chflg) {
- /* First chdir() back... */
- if (chdir(cwdpt) < 0) {
- syswarn(1, errno, "Can't chdir to %s",
- cwdpt);
+ /* First fchdir() back... */
+ if (fchdir(cwdfd) < 0) {
+ syswarn(1, errno,
+ "Can't fchdir to starting directory");
return(-1);
}
if (chdir(ftcur->fname) < 0) {
diff --git a/bin/pax/pax.c b/bin/pax/pax.c
index bdb164ea585..a47f0976080 100644
--- a/bin/pax/pax.c
+++ b/bin/pax/pax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pax.c,v 1.8 1997/07/23 19:15:58 kstailey Exp $ */
+/* $OpenBSD: pax.c,v 1.9 1997/07/24 23:19:21 millert Exp $ */
/* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */
/*-
@@ -48,7 +48,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: pax.c,v 1.8 1997/07/23 19:15:58 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: pax.c,v 1.9 1997/07/24 23:19:21 millert Exp $";
#endif
#endif /* not lint */
@@ -62,6 +62,7 @@ static char rcsid[] = "$OpenBSD: pax.c,v 1.8 1997/07/23 19:15:58 kstailey Exp $"
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
+#include <fcntl.h>
#include "pax.h"
#include "extern.h"
static int gen_init __P((void));
@@ -76,6 +77,7 @@ static int gen_init __P((void));
int act = DEFOP; /* read/write/append/copy */
FSUB *frmt = NULL; /* archive format type */
int cflag; /* match all EXCEPT pattern/file */
+int cwdfd; /* starting cwd */
int dflag; /* directory member match only */
int iflag; /* interactive file/archive rename */
int kflag; /* do not overwrite existing files */
@@ -103,7 +105,6 @@ int docrc; /* check/create file crc */
char *dirptr; /* destination dir in a copy */
char *ltmfrmt; /* -v locale time format (if any) */
char *argv0; /* root of argv[0] */
-char *cwdpt; /* starting cwd */
sigset_t s_mask; /* signal mask for cleanup critical sect */
/*
@@ -239,9 +240,9 @@ main(argc, argv)
/*
* Keep a reference to cwd, so we can always come back home.
*/
- cwdpt = getcwd(NULL, 0);
- if (cwdpt == NULL) {
- syswarn(0, errno, "Can't get current working directory.");
+ cwdfd = open(".", O_RDONLY);
+ if (cwdfd < 0) {
+ syswarn(0, errno, "Can't open current working directory.");
return(exit_val);
}