Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/pax Ensure we exit with an error if we don't actually do...



details:   https://anonhg.NetBSD.org/src/rev/d09a5e07a78a
branches:  trunk
changeset: 588188:d09a5e07a78a
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sat Feb 11 11:04:57 2006 +0000

description:
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.)

diffstat:

 bin/pax/ar_subs.c |  68 ++++++++++++++++++++++++++++++------------------------
 bin/pax/extern.h  |  12 ++++----
 bin/pax/pax.c     |  21 +++++++++-------
 3 files changed, 56 insertions(+), 45 deletions(-)

diffs (truncated from 377 to 300 lines):

diff -r c2a9887d42d7 -r d09a5e07a78a bin/pax/ar_subs.c
--- a/bin/pax/ar_subs.c Sat Feb 11 10:43:17 2006 +0000
+++ b/bin/pax/ar_subs.c Sat Feb 11 11:04:57 2006 +0000
@@ -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 @@
 #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 @@
  *     (if no pattern is supplied, list entire contents).
  */
 
-void
+int
 list(void)
 {
        ARCHD *arcn;
@@ -207,7 +207,7 @@
         */
        if ((get_arc() < 0) || ((*frmt->options)() < 0) ||
            ((*frmt->st_rd)() < 0))
-               return;
+               return 1;
 
        now = time((time_t *)NULL);
 
@@ -278,6 +278,8 @@
        (void)sigprocmask(SIG_BLOCK, &s_mask, (sigset_t *)NULL);
        ar_close();
        pat_chk();
+
+       return 0;
 }
 
 /*
@@ -286,7 +288,7 @@
  *     pattern(s) (no patterns extracts all members)
  */
 
-void
+int
 extract(void)
 {
        ARCHD *arcn;
@@ -304,7 +306,7 @@
         */
        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 @@
         * 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 @@
        ar_close();
        proc_dir();
        pat_chk();
+
+       return 0;
 }
 
 /*
@@ -527,7 +531,7 @@
  *     previously written archive.
  */
 
-static void
+static int
 wr_archive(ARCHD *arcn, int is_app)
 {
        int res;
@@ -543,13 +547,13 @@
         * 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 @@
         * 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 @@
        if (tflag)
                proc_dir();
        ftree_chk();
+
+       return 0;
 }
 
 /*
@@ -734,7 +740,7 @@
  *     over write existing files that it creates.
  */
 
-void
+int
 append(void)
 {
        ARCHD *arcn;
@@ -751,25 +757,25 @@
         * 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 @@
         * 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 @@
         * we will refuse to write
         */
        if (appnd_start(tlen) < 0)
-               return;
+               return 1;
 
        /*
         * tell the user we are done reading.
@@ -861,7 +867,7 @@
        /*
         * go to the writing phase to add the new members
         */
-       wr_archive(arcn, 1);
+       return wr_archive(arcn, 1);
 }
 
 /*
@@ -869,7 +875,7 @@
  *     write a new archive
  */
 
-void
+int
 archive(void)
 {
 
@@ -879,11 +885,11 @@
         * 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 @@
  *     (except the files are forced to be under the destination directory).
  */
 
-void
+int
 copy(void)
 {
        ARCHD *arcn;
@@ -916,7 +922,7 @@
        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 @@
        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 @@
         * 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 @@
        ar_close();
        proc_dir();
        ftree_chk();
+
+       return 0;
 }
 
 /*
diff -r c2a9887d42d7 -r d09a5e07a78a bin/pax/extern.h
--- a/bin/pax/extern.h  Sat Feb 11 10:43:17 2006 +0000
+++ b/bin/pax/extern.h  Sat Feb 11 11:04:57 2006 +0000
@@ -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 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);



Home | Main Index | Thread Index | Old Index