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.23-1.39 (requested by rafal in tic...
details: https://anonhg.NetBSD.org/src/rev/6e39268cafe9
branches: netbsd-1-6
changeset: 531258:6e39268cafe9
user: jmc <jmc%NetBSD.org@localhost>
date: Wed Apr 07 06:57:05 2004 +0000
description:
Pullup rev 1.23-1.39 (requested by rafal in ticket #1021)
Pullup pax to current version on trunk. Includes many fixes.
diffstat:
bin/pax/ar_io.c | 440 +++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 309 insertions(+), 131 deletions(-)
diffs (truncated from 826 to 300 lines):
diff -r d1eb3cf897f6 -r 6e39268cafe9 bin/pax/ar_io.c
--- a/bin/pax/ar_io.c Wed Apr 07 04:37:01 2004 +0000
+++ b/bin/pax/ar_io.c Wed Apr 07 06:57:05 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ar_io.c,v 1.22 2002/01/31 19:27:53 tv Exp $ */
+/* $NetBSD: ar_io.c,v 1.22.2.1 2004/04/07 06:57:05 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,12 +33,16 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
-#if defined(__RCSID) && !defined(lint)
+#if !defined(lint)
#if 0
static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94";
#else
-__RCSID("$NetBSD: ar_io.c,v 1.22 2002/01/31 19:27:53 tv Exp $");
+__RCSID("$NetBSD: ar_io.c,v 1.22.2.1 2004/04/07 06:57:05 jmc Exp $");
#endif
#endif /* not lint */
@@ -52,6 +52,7 @@
#include <sys/ioctl.h>
#include <sys/mtio.h>
#include <sys/param.h>
+#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <fcntl.h>
@@ -60,7 +61,12 @@
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
+#ifdef SUPPORT_RMT
+#define __RMTLIB_PRIVATE
+#include <rmt.h>
+#endif /* SUPPORT_RMT */
#include "pax.h"
+#include "options.h"
#include "extern.h"
/*
@@ -86,17 +92,26 @@
static int can_unlnk = 0; /* do we unlink null archives? */
const char *arcname; /* printable name of archive */
const char *gzip_program; /* name of gzip program */
+static pid_t zpid = -1; /* pid of child process */
time_t starttime; /* time the run started */
-int minusCfd = -1; /* active -C directory */
-int curdirfd = -1; /* original current directory */
int force_one_volume; /* 1 if we ignore volume changes */
static int get_phys(void);
extern sigset_t s_mask;
-static void ar_start_gzip(int);
+static void ar_start_gzip(int, const char *, int);
static const char *timefmt(char *, size_t, off_t, time_t);
static const char *sizefmt(char *, size_t, off_t);
+#ifdef SUPPORT_RMT
+#ifdef SYS_NO_RESTART
+static int rmtread_with_restart(int, void *, int);
+static int rmtwrite_with_restart(int, void *, int);
+#else
+#define rmtread_with_restart(a, b, c) rmtread((a), (b), (c))
+#define rmtwrite_with_restart(a, b, c) rmtwrite((a), (b), (c))
+#endif
+#endif /* SUPPORT_RMT */
+
/*
* ar_open()
* Opens the next archive volume. Determines the type of the device and
@@ -111,12 +126,6 @@
{
struct mtget mb;
- /*
- * change back to the current directory (for now).
- */
- if (curdirfd != -1)
- fchdir(curdirfd);
-
if (arfd != -1)
(void)close(arfd);
arfd = -1;
@@ -124,6 +133,19 @@
artyp = ISREG;
flcnt = 0;
+#ifdef SUPPORT_RMT
+ if (name && strchr(name, ':') != NULL && !forcelocal) {
+ artyp = ISRMT;
+ if ((arfd = rmtopen(name, O_RDWR, DMOD)) == -1) {
+ syswarn(0, errno, "Failed open on %s", name);
+ return -1;
+ }
+ blksz = rdblksz = 8192;
+ lstrval = 1;
+ return 0;
+ }
+#endif /* SUPPORT_RMT */
+
/*
* open based on overall operation mode
*/
@@ -135,8 +157,8 @@
arcname = STDN;
} else if ((arfd = open(name, EXT_MODE, DMOD)) < 0)
syswarn(0, errno, "Failed open to read on %s", name);
- if (zflag)
- ar_start_gzip(arfd);
+ if (arfd != -1 && gzip_program != NULL)
+ ar_start_gzip(arfd, gzip_program, 0);
break;
case ARCHIVE:
if (name == NULL) {
@@ -146,12 +168,10 @@
syswarn(0, errno, "Failed open to write on %s", name);
else
can_unlnk = 1;
- if (zflag)
- ar_start_gzip(arfd);
+ if (arfd != -1 && gzip_program != NULL)
+ ar_start_gzip(arfd, gzip_program, 1);
break;
case APPND:
- if (zflag)
- err(1, "can not gzip while appending");
if (name == NULL) {
arfd = STDOUT_FILENO;
arcname = STDO;
@@ -170,6 +190,9 @@
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
*/
@@ -199,6 +222,22 @@
artyp = ISREG;
/*
+ * Special handling for empty files.
+ */
+ if (artyp == ISREG && arsb.st_size == 0) {
+ switch (act) {
+ case LIST:
+ case EXTRACT:
+ return -1;
+ case APPND:
+ act = -ARCHIVE;
+ return -1;
+ case ARCHIVE:
+ break;
+ }
+ }
+
+ /*
* make sure we beyond any doubt that we only can unlink regular files
* we created
*/
@@ -206,12 +245,6 @@
can_unlnk = 0;
/*
- * change directory if necessary
- */
- if (minusCfd != -1)
- fchdir(minusCfd);
-
- /*
* if we are writing, we are done
*/
if (act == ARCHIVE) {
@@ -224,7 +257,7 @@
* set default blksz on read. APPNDs writes rdblksz on the last volume
* On all new archive volumes, we shift to wrblksz (if the user
* specified one, otherwize we will continue to use rdblksz). We
- * must to set blocksize based on what kind of device the archive is
+ * must set blocksize based on what kind of device the archive is
* stored.
*/
switch(artyp) {
@@ -304,7 +337,7 @@
break;
default:
/*
- * should never happen, worse case, slow...
+ * should never happen, worst case, slow...
*/
blksz = rdblksz = BLKMULT;
break;
@@ -320,17 +353,13 @@
void
ar_close(void)
{
- FILE *outf;
+ int status;
if (arfd < 0) {
did_io = io_ok = flcnt = 0;
return;
}
- if (act == LIST)
- outf = stdout;
- else
- outf = stderr;
/*
* Close archive file. This may take a LONG while on tapes (we may be
@@ -340,11 +369,11 @@
*/
if (vflag && (artyp == ISTAPE)) {
if (vfpart)
- (void)putc('\n', outf);
- (void)fprintf(outf,
+ (void)putc('\n', listf);
+ (void)fprintf(listf,
"%s: Waiting for tape drive close to complete...",
argv0);
- (void)fflush(outf);
+ (void)fflush(listf);
}
/*
@@ -357,12 +386,28 @@
can_unlnk = 0;
}
- (void)close(arfd);
+ /*
+ * for a quick extract/list, pax frequently exits before the child
+ * process is done
+ */
+ if ((act == LIST || act == EXTRACT) && nflag && zpid > 0)
+ kill(zpid, SIGINT);
+
+#ifdef SUPPORT_RMT
+ if (artyp == ISRMT)
+ (void)rmtclose(arfd);
+ else
+#endif /* SUPPORT_RMT */
+ (void)close(arfd);
+
+ /* Do not exit before child to ensure data integrity */
+ if (zpid > 0)
+ waitpid(zpid, &status, 0);
if (vflag && (artyp == ISTAPE)) {
- (void)fputs("done.\n", outf);
+ (void)fputs("done.\n", listf);
vfpart = 0;
- (void)fflush(outf);
+ (void)fflush(listf);
}
arfd = -1;
@@ -388,13 +433,30 @@
* Print out a summary of I/O for this archive volume.
*/
if (vfpart) {
- (void)putc('\n', outf);
+ (void)putc('\n', listf);
vfpart = 0;
}
+ /*
+ * If we have not determined the format yet, we just say how many bytes
+ * we have skipped over looking for a header to id. there is no way we
+ * could have written anything yet.
+ */
+ if (frmt == NULL) {
+ (void)fprintf(listf, "%s: unknown format, " OFFT_F
+ " bytes skipped.\n", argv0, rdcnt);
+ (void)fflush(listf);
+ flcnt = 0;
+ return;
Home |
Main Index |
Thread Index |
Old Index