From: michaels Date: Thu, 27 Feb 1997 23:32:56 +0000 (+0000) Subject: fix pr system/124, reported by Janjaap van Velthooven (janjaap@stack.nl). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fd899314eda5ca263ae03cc0e84c0a66661ce0ac;p=openbsd fix pr system/124, reported by Janjaap van Velthooven (janjaap@stack.nl). --- diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c index 5ee70128781..5fd79f791e3 100644 --- a/bin/pax/ar_io.c +++ b/bin/pax/ar_io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ar_io.c,v 1.10 1997/02/20 06:54:31 tholo Exp $ */ +/* $OpenBSD: ar_io.c,v 1.11 1997/02/27 23:32:56 michaels Exp $ */ /* $NetBSD: ar_io.c,v 1.5 1996/03/26 23:54:13 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: ar_io.c,v 1.10 1997/02/20 06:54:31 tholo Exp $"; +static char rcsid[] = "$OpenBSD: ar_io.c,v 1.11 1997/02/27 23:32:56 michaels Exp $"; #endif #endif /* not lint */ @@ -165,6 +165,9 @@ ar_open(name) if (arfd < 0) return(-1); + if (chdname != NULL) + if (chdir(chdname) != 0) + syswarn(1, errno, "Failed chdir to %s", chdname); /* * set up is based on device type */ diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c index 164b4470163..9ebc7dc1586 100644 --- a/bin/pax/ar_subs.c +++ b/bin/pax/ar_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ar_subs.c,v 1.5 1997/01/24 19:41:19 millert Exp $ */ +/* $OpenBSD: ar_subs.c,v 1.6 1997/02/27 23:32:57 michaels 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.5 1997/01/24 19:41:19 millert Exp $"; +static char rcsid[] = "$OpenBSD: ar_subs.c,v 1.6 1997/02/27 23:32:57 michaels Exp $"; #endif #endif /* not lint */ @@ -294,13 +294,10 @@ extract() /* * if required, chdir around. */ - if ((arcn->pat != NULL) && (arcn->pat->chdnam != NULL)) { - if (chdir(arcn->pat->chdnam) < 0) { + if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL)) + if (chdir(arcn->pat->chdname) != 0) syswarn(1, errno, "Cannot chdir to %s", - arcn->pat->chdnam); - return; - } - } + arcn->pat->chdname); /* * all ok, extract this member based on type @@ -351,12 +348,9 @@ extract() /* * if required, chdir around. */ - if ((arcn->pat != NULL) && (arcn->pat->chdnam != NULL)) { - if (chdir(cwdpt) < 0) { - syswarn(0, errno, "Can't chdir to %s", cwdpt); - return; - } - } + if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL)) + if (chdir(cwdpt) != 0) + syswarn(1, errno, "Can't chdir to %s", cwdpt); } /* diff --git a/bin/pax/extern.h b/bin/pax/extern.h index c417a13827c..1bedec50087 100644 --- a/bin/pax/extern.h +++ b/bin/pax/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.9 1997/01/26 10:33:22 downsj Exp $ */ +/* $OpenBSD: extern.h,v 1.10 1997/02/27 23:32:57 michaels Exp $ */ /* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */ /*- @@ -192,6 +192,7 @@ void options __P((register int, register char **)); OPLIST * opt_next __P((void)); int opt_add __P((register char *)); int bad_opt __P((void)); +char *chdname; /* * pat_rep.c diff --git a/bin/pax/options.c b/bin/pax/options.c index a451228903c..513af6962e8 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.14 1997/02/20 06:54:34 tholo Exp $ */ +/* $OpenBSD: options.c,v 1.15 1997/02/27 23:32:58 michaels Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: options.c,v 1.14 1997/02/20 06:54:34 tholo Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.15 1997/02/27 23:32:58 michaels Exp $"; #endif #endif /* not lint */ @@ -599,7 +599,6 @@ tar_options(argc, argv) { register int c; int fstdin = 0; - char *chdnam = (char *)NULL; /* * process option flags @@ -723,7 +722,7 @@ tar_options(argc, argv) */ break; case 'C': - chdnam = optarg; + chdname = optarg; break; case 'H': /* @@ -797,37 +796,32 @@ tar_options(argc, argv) default: { int sawpat = 0; - + while (*argv != (char *)NULL) { - if (!strcmp(*argv, "-C")) { + if (strcmp(*argv, "-C") == 0) { if(*++argv == (char *)NULL) break; - chdnam = *argv++; + chdname = *argv++; continue; } - if (pat_add(*argv++, chdnam) < 0) + if (pat_add(*argv++, chdname) < 0) tar_usage(); sawpat++; } - /* - * If there were no patterns, but there was a chdir, - * we do it now. - */ - if ((sawpat == 0) && (chdnam != (char *)NULL)) { - if (chdir(chdnam) < 0) { - syswarn(0, errno, "Can't chdir to %s", - chdnam); - exit(exit_val); - } - } + * if patterns were added, we are doing chdir() + * on a file-by-file basis, else, just one + * global chdir (if any) after opening input. + */ + if (sawpat > 0) + chdname = NULL; } break; case ARCHIVE: case APPND: - if (chdnam != (char *)NULL) { /* initial chdir() */ - if (ftree_add(chdnam, 1) < 0) + if (chdname != (char *)NULL) { /* initial chdir() */ + if (ftree_add(chdname, 1) < 0) tar_usage(); } diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c index d4755558738..afe44a41030 100644 --- a/bin/pax/pat_rep.c +++ b/bin/pax/pat_rep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pat_rep.c,v 1.5 1996/10/27 06:45:12 downsj Exp $ */ +/* $OpenBSD: pat_rep.c,v 1.6 1997/02/27 23:32:59 michaels Exp $ */ /* $NetBSD: pat_rep.c,v 1.4 1995/03/21 09:07:33 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)pat_rep.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.5 1996/10/27 06:45:12 downsj Exp $"; +static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.6 1997/02/27 23:32:59 michaels Exp $"; #endif #endif /* not lint */ @@ -234,12 +234,12 @@ rep_add(str) #if __STDC__ int -pat_add(char *str, char *chdnam) +pat_add(char *str, char *chdname) #else int -pat_add(str, chdnam) +pat_add(str, chdname) char *str; - char *chdnam; + char *chdname; #endif { register PATTERN *pt; @@ -267,15 +267,8 @@ pat_add(str, chdnam) pt->plen = strlen(str); pt->fow = NULL; pt->flgs = 0; - if (chdnam != (char *)NULL) { - pt->chdnam = strdup(chdnam); - if (pt->chdnam == (char *)NULL) { - paxwarn(1, - "Unable to allocate memory for pattern string"); - return(-1); - } - } else - pt->chdnam = (char *)NULL; + pt->chdname = chdname; + if (pathead == NULL) { pattail = pathead = pt; return(0); @@ -441,8 +434,6 @@ pat_sel(arcn) return(-1); } *ppt = pt->fow; - if (pt->chdnam != (char *)NULL) - (void)free(pt->chdnam); (void)free((char *)pt); arcn->pat = NULL; return(0); diff --git a/bin/pax/pax.h b/bin/pax/pax.h index 50a2aac10e4..1930aa6d3cf 100644 --- a/bin/pax/pax.h +++ b/bin/pax/pax.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pax.h,v 1.6 1996/12/09 12:00:16 deraadt Exp $ */ +/* $OpenBSD: pax.h,v 1.7 1997/02/27 23:32:59 michaels Exp $ */ /* $NetBSD: pax.h,v 1.3 1995/03/21 09:07:41 cgd Exp $ */ /*- @@ -166,7 +166,7 @@ typedef struct { typedef struct pattern { char *pstr; /* pattern to match, user supplied */ char *pend; /* end of a prefix match */ - char *chdnam; + char *chdname; /* the dir to change to if not NULL. */ int plen; /* length of pstr */ int flgs; /* processing/state flags */ #define MTCH 0x1 /* pattern has been matched */