Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-6]: src/bin/pax Pullup rev 1.18-1.33 (requested by rafal in tic...
details: https://anonhg.NetBSD.org/src/rev/9e090733aeb8
branches: netbsd-1-6
changeset: 531275:9e090733aeb8
user: jmc <jmc%NetBSD.org@localhost>
date: Wed Apr 07 06:58:26 2004 +0000
description:
Pullup rev 1.18-1.33 (requested by rafal in ticket #1021)
Pullup pax to current version on trunk. Includes many fixes.
diffstat:
bin/pax/pax.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 83 insertions(+), 16 deletions(-)
diffs (210 lines):
diff -r 5124412cd7ea -r 9e090733aeb8 bin/pax/pax.c
--- a/bin/pax/pax.c Wed Apr 07 06:58:22 2004 +0000
+++ b/bin/pax/pax.c Wed Apr 07 06:58:26 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pax.c,v 1.17 2002/01/31 19:27:54 tv Exp $ */
+/* $NetBSD: pax.c,v 1.17.2.1 2004/04/07 06:58:26 jmc Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -16,11 +16,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -37,30 +33,34 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
-#if defined(__COPYRIGHT) && !defined(lint)
+#if !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n");
-#endif /* not lint */
-
-#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
#else
-__RCSID("$NetBSD: pax.c,v 1.17 2002/01/31 19:27:54 tv Exp $");
+__RCSID("$NetBSD: pax.c,v 1.17.2.1 2004/04/07 06:58:26 jmc Exp $");
#endif
#endif /* not lint */
-#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <stdio.h>
+#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
+#include <paths.h>
#include "pax.h"
#include "extern.h"
static int gen_init(void);
@@ -72,11 +72,13 @@
/*
* Variables that can be accessed by any routine within pax
*/
-int act = DEFOP; /* read/write/append/copy */
+int act = ERROR; /* 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 jflag; /* pass through bzip2 */
int kflag; /* do not overwrite existing files */
int lflag; /* use hard links when possible */
int nflag; /* select first archive member match */
@@ -95,14 +97,25 @@
int vfpart; /* is partial verbose output in progress */
int patime = 1; /* preserve file access time */
int pmtime = 1; /* preserve file modification times */
+int nodirs; /* do not create directories as needed */
int pfflags = 1; /* preserve file flags */
int pmode; /* preserve file mode bits */
int pids; /* preserve file uid/gid */
+int rmleadslash = 0; /* remove leading '/' from pathnames */
int exit_val; /* exit value */
int docrc; /* check/create file crc */
+int to_stdout; /* extract to stdout */
char *dirptr; /* destination dir in a copy */
+char *ltmfrmt; /* -v locale time format (if any) */
char *argv0; /* root of argv[0] */
sigset_t s_mask; /* signal mask for cleanup critical sect */
+FILE *listf; /* file pointer to print file list to */
+char *tempfile; /* tempfile to use for mkstemp(3) */
+char *tempbase; /* basename of tempfile to use for mkstemp(3) */
+int forcelocal; /* force local operation even if the name
+ * contains a :
+ */
+int secure = 1; /* don't extract names that contain .. */
/*
* PAX - Portable Archive Interchange
@@ -227,6 +240,40 @@
int
main(int argc, char **argv)
{
+ char *tmpdir;
+ size_t tdlen;
+
+ setprogname(argv[0]);
+
+ listf = stderr;
+
+ /*
+ * Keep a reference to cwd, so we can always come back home.
+ */
+ cwdfd = open(".", O_RDONLY);
+ if (cwdfd < 0) {
+ syswarn(0, errno, "Can't open current working directory.");
+ return(exit_val);
+ }
+
+ /*
+ * Where should we put temporary files?
+ */
+ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
+ tmpdir = _PATH_TMP;
+ tdlen = strlen(tmpdir);
+ while(tdlen > 0 && tmpdir[tdlen - 1] == '/')
+ tdlen--;
+ tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE));
+ if (tempfile == NULL) {
+ tty_warn(1, "Cannot allocate memory for temp file name.");
+ return(exit_val);
+ }
+ if (tdlen)
+ memcpy(tempfile, tmpdir, tdlen);
+ tempbase = tempfile + tdlen;
+ *tempbase++ = '/';
+
/*
* parse options, determine operational mode, general init
*/
@@ -249,7 +296,17 @@
archive();
break;
case APPND:
+ if (gzip_program != NULL)
+ err(1, "cannot gzip while appending");
append();
+ /*
+ * Check if we tried to append on an empty file and
+ * turned into ARCHIVE mode.
+ */
+ if (act == -ARCHIVE) {
+ act = ARCHIVE;
+ archive();
+ }
break;
case COPY:
copy();
@@ -281,16 +338,18 @@
*/
vflag = vfpart = 1;
if (which_sig == SIGXCPU)
- tty_warn(0, "Cpu time limit reached, cleaning up.");
+ tty_warn(0, "CPU time limit reached, cleaning up.");
else
tty_warn(0, "Signal caught, cleaning up.");
+ /* delete any open temporary file */
+ if (xtmp_name)
+ (void)unlink(xtmp_name);
ar_close();
proc_dir();
if (tflag)
atdir_end();
exit(1);
- /* NOTREACHED */
}
/*
@@ -343,9 +402,16 @@
#endif
/*
+ * Handle posix locale
+ *
+ * set user defines time printing format for -v option
+ */
+ ltmfrmt = getenv("LC_TIME");
+
+ /*
* signal handling to reset stored directory times and modes. Since
* we deal with broken pipes via failed writes we ignore it. We also
- * deal with any file size limit thorugh failed writes. Cpu time
+ * deal with any file size limit thorugh failed writes. CPU time
* limits are caught and a cleanup is forced.
*/
if ((sigemptyset(&s_mask) < 0) || (sigaddset(&s_mask, SIGTERM) < 0) ||
@@ -355,6 +421,7 @@
tty_warn(1, "Unable to set up signal mask");
return(-1);
}
+ memset(&n_hand, 0, sizeof n_hand);
n_hand.sa_mask = s_mask;
n_hand.sa_flags = 0;
n_hand.sa_handler = sig_cleanup;
Home |
Main Index |
Thread Index |
Old Index