Ensure we exit with an error if we don't actually do anything.
There are a lot of tty_warn(0,...) and syswarn(0,...) which probably ought to be tty_warn/syswarn(1,...) to force an error exit. However some are used in interactive parts (eg opening a continuation archive) where there is a separate retry loop. So we just pass a failure code out to main() - how quaint! This should now cause the NetBSD build to fail when gzip tries to write to a non-existant directory. (I suspect there are still many errors that don't get reported correctly.)
This commit is contained in:
parent
cdec4ac10c
commit
b419a25464
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ar_subs.c,v 1.48 2006/02/11 10:43:17 dsl Exp $ */
|
||||
/* $NetBSD: ar_subs.c,v 1.49 2006/02/11 11:04:57 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992 Keith Muller.
|
||||
|
@ -42,7 +42,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)ar_subs.c 8.2 (Berkeley) 4/18/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: ar_subs.c,v 1.48 2006/02/11 10:43:17 dsl Exp $");
|
||||
__RCSID("$NetBSD: ar_subs.c,v 1.49 2006/02/11 11:04:57 dsl Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -63,7 +63,7 @@ __RCSID("$NetBSD: ar_subs.c,v 1.48 2006/02/11 10:43:17 dsl Exp $");
|
|||
#include "extern.h"
|
||||
|
||||
static int path_check(ARCHD *, int);
|
||||
static void wr_archive(ARCHD *, int is_app);
|
||||
static int wr_archive(ARCHD *, int is_app);
|
||||
static int get_arc(void);
|
||||
static int next_head(ARCHD *);
|
||||
#if !HAVE_NBTOOL_CONFIG_H
|
||||
|
@ -190,7 +190,7 @@ path_check(ARCHD *arcn, int level)
|
|||
* (if no pattern is supplied, list entire contents).
|
||||
*/
|
||||
|
||||
void
|
||||
int
|
||||
list(void)
|
||||
{
|
||||
ARCHD *arcn;
|
||||
|
@ -207,7 +207,7 @@ list(void)
|
|||
*/
|
||||
if ((get_arc() < 0) || ((*frmt->options)() < 0) ||
|
||||
((*frmt->st_rd)() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
now = time((time_t *)NULL);
|
||||
|
||||
|
@ -278,6 +278,8 @@ list(void)
|
|||
(void)sigprocmask(SIG_BLOCK, &s_mask, (sigset_t *)NULL);
|
||||
ar_close();
|
||||
pat_chk();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -286,7 +288,7 @@ list(void)
|
|||
* pattern(s) (no patterns extracts all members)
|
||||
*/
|
||||
|
||||
void
|
||||
int
|
||||
extract(void)
|
||||
{
|
||||
ARCHD *arcn;
|
||||
|
@ -304,7 +306,7 @@ extract(void)
|
|||
*/
|
||||
if ((get_arc() < 0) || ((*frmt->options)() < 0) ||
|
||||
((*frmt->st_rd)() < 0) || (dir_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
now = time((time_t *)NULL);
|
||||
#if !HAVE_NBTOOL_CONFIG_H
|
||||
|
@ -317,7 +319,7 @@ extract(void)
|
|||
* so we can fix up hard links files later in the archive.
|
||||
*/
|
||||
if (iflag && (name_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* step through each entry on the archive until the format read routine
|
||||
|
@ -519,6 +521,8 @@ extract(void)
|
|||
ar_close();
|
||||
proc_dir();
|
||||
pat_chk();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -527,7 +531,7 @@ extract(void)
|
|||
* previously written archive.
|
||||
*/
|
||||
|
||||
static void
|
||||
static int
|
||||
wr_archive(ARCHD *arcn, int is_app)
|
||||
{
|
||||
int res;
|
||||
|
@ -543,13 +547,13 @@ wr_archive(ARCHD *arcn, int is_app)
|
|||
* that detects them.
|
||||
*/
|
||||
if (((hlk = frmt->hlk) == 1) && (lnk_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* start up the file traversal code and format specific write
|
||||
*/
|
||||
if ((ftree_start() < 0) || ((*frmt->st_wr)() < 0))
|
||||
return;
|
||||
return 1;
|
||||
wrf = frmt->wr;
|
||||
|
||||
now = time((time_t *)NULL);
|
||||
|
@ -559,7 +563,7 @@ wr_archive(ARCHD *arcn, int is_app)
|
|||
* so we can fix up hard links files later in the archive.
|
||||
*/
|
||||
if (iflag && (name_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* if this is not append, and there are no files, we do no write a trailer
|
||||
|
@ -710,6 +714,8 @@ wr_archive(ARCHD *arcn, int is_app)
|
|||
if (tflag)
|
||||
proc_dir();
|
||||
ftree_chk();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -734,7 +740,7 @@ wr_archive(ARCHD *arcn, int is_app)
|
|||
* over write existing files that it creates.
|
||||
*/
|
||||
|
||||
void
|
||||
int
|
||||
append(void)
|
||||
{
|
||||
ARCHD *arcn;
|
||||
|
@ -751,25 +757,25 @@ append(void)
|
|||
* different format than the user specified format.
|
||||
*/
|
||||
if (get_arc() < 0)
|
||||
return;
|
||||
return 1;
|
||||
if ((orgfrmt != NULL) && (orgfrmt != frmt)) {
|
||||
tty_warn(1, "Cannot mix current archive format %s with %s",
|
||||
frmt->name, orgfrmt->name);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* pass the format any options and start up format
|
||||
*/
|
||||
if (((*frmt->options)() < 0) || ((*frmt->st_rd)() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* if we only are adding members that are newer, we need to save the
|
||||
* mod times for all files we see.
|
||||
*/
|
||||
if (uflag && (ftime_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* some archive formats encode hard links by recording the device and
|
||||
|
@ -786,7 +792,7 @@ append(void)
|
|||
* header. See the remap routines for more details.
|
||||
*/
|
||||
if ((udev = frmt->udev) && (dev_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* reading the archive may take a long time. If verbose tell the user
|
||||
|
@ -848,7 +854,7 @@ append(void)
|
|||
* we will refuse to write
|
||||
*/
|
||||
if (appnd_start(tlen) < 0)
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* tell the user we are done reading.
|
||||
|
@ -861,7 +867,7 @@ append(void)
|
|||
/*
|
||||
* go to the writing phase to add the new members
|
||||
*/
|
||||
wr_archive(arcn, 1);
|
||||
return wr_archive(arcn, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -869,7 +875,7 @@ append(void)
|
|||
* write a new archive
|
||||
*/
|
||||
|
||||
void
|
||||
int
|
||||
archive(void)
|
||||
{
|
||||
|
||||
|
@ -879,11 +885,11 @@ archive(void)
|
|||
* options write the archive
|
||||
*/
|
||||
if ((uflag && (ftime_start() < 0)) || (wr_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
if ((*frmt->options)() < 0)
|
||||
return;
|
||||
return 1;
|
||||
|
||||
wr_archive(&archd, 0);
|
||||
return wr_archive(&archd, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -894,7 +900,7 @@ archive(void)
|
|||
* (except the files are forced to be under the destination directory).
|
||||
*/
|
||||
|
||||
void
|
||||
int
|
||||
copy(void)
|
||||
{
|
||||
ARCHD *arcn;
|
||||
|
@ -916,7 +922,7 @@ copy(void)
|
|||
if (dlen >= sizeof(dirbuf) ||
|
||||
(dlen == sizeof(dirbuf) - 1 && dirbuf[dlen - 1] != '/')) {
|
||||
tty_warn(1, "directory name is too long %s", dirptr);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
dest_pt = dirbuf + dlen;
|
||||
if (*(dest_pt-1) != '/') {
|
||||
|
@ -929,11 +935,11 @@ copy(void)
|
|||
if (stat(dirptr, &sb) < 0) {
|
||||
syswarn(1, errno, "Cannot access destination directory %s",
|
||||
dirptr);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
if (!S_ISDIR(sb.st_mode)) {
|
||||
tty_warn(1, "Destination is not a directory %s", dirptr);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -941,14 +947,14 @@ copy(void)
|
|||
* modification time and access mode database
|
||||
*/
|
||||
if ((lnk_start() < 0) || (ftree_start() < 0) || (dir_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* When we are doing interactive rename, we store the mapping of names
|
||||
* so we can fix up hard links files later in the archive.
|
||||
*/
|
||||
if (iflag && (name_start() < 0))
|
||||
return;
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* set up to cp file trees
|
||||
|
@ -1123,6 +1129,8 @@ copy(void)
|
|||
ar_close();
|
||||
proc_dir();
|
||||
ftree_chk();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: extern.h,v 1.49 2005/09/16 16:48:18 christos Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.50 2006/02/11 11:04:57 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992 Keith Muller.
|
||||
|
@ -86,11 +86,11 @@ int updatepath(void);
|
|||
int dochdir(const char *);
|
||||
int fdochdir(int);
|
||||
int domkdir(const char *, mode_t);
|
||||
void list(void);
|
||||
void extract(void);
|
||||
void append(void);
|
||||
void archive(void);
|
||||
void copy(void);
|
||||
int list(void);
|
||||
int extract(void);
|
||||
int append(void);
|
||||
int archive(void);
|
||||
int copy(void);
|
||||
|
||||
/*
|
||||
* buf_subs.c
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pax.c,v 1.39 2006/02/11 10:43:18 dsl Exp $ */
|
||||
/* $NetBSD: pax.c,v 1.40 2006/02/11 11:04:57 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992 Keith Muller.
|
||||
|
@ -44,7 +44,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: pax.c,v 1.39 2006/02/11 10:43:18 dsl Exp $");
|
||||
__RCSID("$NetBSD: pax.c,v 1.40 2006/02/11 11:04:57 dsl Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -242,6 +242,7 @@ main(int argc, char **argv)
|
|||
{
|
||||
const char *tmpdir;
|
||||
size_t tdlen;
|
||||
int rval;
|
||||
|
||||
setprogname(argv[0]);
|
||||
|
||||
|
@ -294,34 +295,36 @@ main(int argc, char **argv)
|
|||
/*
|
||||
* select a primary operation mode
|
||||
*/
|
||||
switch(act) {
|
||||
switch (act) {
|
||||
case EXTRACT:
|
||||
extract();
|
||||
rval = extract();
|
||||
break;
|
||||
case ARCHIVE:
|
||||
archive();
|
||||
rval = archive();
|
||||
break;
|
||||
case APPND:
|
||||
if (gzip_program != NULL)
|
||||
err(1, "cannot gzip while appending");
|
||||
append();
|
||||
rval = append();
|
||||
/*
|
||||
* Check if we tried to append on an empty file and
|
||||
* turned into ARCHIVE mode.
|
||||
*/
|
||||
if (act == -ARCHIVE) {
|
||||
act = ARCHIVE;
|
||||
archive();
|
||||
rval = archive();
|
||||
}
|
||||
break;
|
||||
case COPY:
|
||||
copy();
|
||||
rval = copy();
|
||||
break;
|
||||
default:
|
||||
case LIST:
|
||||
list();
|
||||
rval = list();
|
||||
break;
|
||||
}
|
||||
if (rval != 0)
|
||||
exit_val = 1;
|
||||
return exit_val;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue