Index: head/usr.bin/tar/bsdtar.h =================================================================== --- head/usr.bin/tar/bsdtar.h (revision 179212) +++ head/usr.bin/tar/bsdtar.h (revision 179213) @@ -1,131 +1,131 @@ /*- * Copyright (c) 2003-2007 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include "bsdtar_platform.h" #include #define DEFAULT_BYTES_PER_BLOCK (20*512) /* * The internal state for the "bsdtar" program. * * Keeping all of the state in a structure like this simplifies memory * leak testing (at exit, anything left on the heap is suspect). A * pointer to this structure is passed to most bsdtar internal * functions. */ struct bsdtar { /* Options */ const char *filename; /* -f filename */ const char *create_format; /* -F format */ char *pending_chdir; /* -C dir */ const char *names_from_file; /* -T file */ time_t newer_ctime_sec; /* --newer/--newer-than */ long newer_ctime_nsec; /* --newer/--newer-than */ time_t newer_mtime_sec; /* --newer-mtime */ long newer_mtime_nsec; /* --newer-mtime-than */ int bytes_per_block; /* -b block_size */ int verbose; /* -v */ int extract_flags; /* Flags for extract operation */ int strip_components; /* Remove this many leading dirs */ char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ char symlink_mode; /* H or L, per BSD conventions */ char create_compression; /* j, y, or z */ const char *compress_program; char option_absolute_paths; /* -P */ char option_chroot; /* --chroot */ char option_dont_traverse_mounts; /* --one-file-system */ char option_fast_read; /* --fast-read */ char option_honor_nodump; /* --nodump */ char option_interactive; /* -w */ char option_no_owner; /* -o */ char option_no_subdirs; /* -n */ char option_null; /* --null */ char option_stdout; /* -O */ char option_totals; /* --totals */ char option_unlink_first; /* -U */ char option_warn_links; /* --check-links */ char day_first; /* show day before month in -tv output */ /* If >= 0, then close this when done. */ int fd; /* Miscellaneous state information */ struct archive *archive; const char *progname; int argc; char **argv; size_t gs_width; /* For 'list_item' in read.c */ size_t u_width; /* for 'list_item' in read.c */ uid_t user_uid; /* UID running this program */ int return_value; /* Value returned by main() */ char warned_lead_slash; /* Already displayed warning */ char next_line_is_dir; /* Used for -C parsing in -cT */ /* * Data for various subsystems. Full definitions are located in * the file where they are used. */ struct archive_dir *archive_dir; /* for write.c */ struct name_cache *gname_cache; /* for write.c */ struct links_cache *links_cache; /* for write.c */ struct matching *matching; /* for matching.c */ struct security *security; /* for read.c */ struct name_cache *uname_cache; /* for write.c */ - struct siginfo *siginfo; /* for siginfo.c */ + struct siginfo_data *siginfo; /* for siginfo.c */ }; void bsdtar_errc(struct bsdtar *, int _eval, int _code, const char *fmt, ...); void bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...); void cleanup_exclusions(struct bsdtar *); void do_chdir(struct bsdtar *); int edit_pathname(struct bsdtar *, struct archive_entry *); int exclude(struct bsdtar *, const char *pattern); int exclude_from_file(struct bsdtar *, const char *pathname); int excluded(struct bsdtar *, const char *pathname); int include(struct bsdtar *, const char *pattern); int include_from_file(struct bsdtar *, const char *pathname); int pathcmp(const char *a, const char *b); int process_lines(struct bsdtar *bsdtar, const char *pathname, int (*process)(struct bsdtar *, const char *)); void safe_fprintf(FILE *, const char *fmt, ...); void set_chdir(struct bsdtar *, const char *newdir); void siginfo_init(struct bsdtar *); void siginfo_setinfo(struct bsdtar *, const char * oper, const char * path, int64_t size); void siginfo_printinfo(struct bsdtar *, off_t progress); void siginfo_done(struct bsdtar *); void tar_mode_c(struct bsdtar *bsdtar); void tar_mode_r(struct bsdtar *bsdtar); void tar_mode_t(struct bsdtar *bsdtar); void tar_mode_u(struct bsdtar *bsdtar); void tar_mode_x(struct bsdtar *bsdtar); int unmatched_inclusions(struct bsdtar *bsdtar); void usage(struct bsdtar *); int yes(const char *fmt, ...); Index: head/usr.bin/tar/siginfo.c =================================================================== --- head/usr.bin/tar/siginfo.c (revision 179212) +++ head/usr.bin/tar/siginfo.c (revision 179213) @@ -1,147 +1,147 @@ /*- * Copyright 2008 Colin Percival * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "bsdtar_platform.h" __FBSDID("$FreeBSD$"); #include #include #include #include #include #include "bsdtar.h" /* Is there a pending SIGINFO or SIGUSR1? */ static volatile sig_atomic_t siginfo_received = 0; -struct siginfo { +struct siginfo_data { /* What sort of operation are we doing? */ char * oper; /* What path are we handling? */ char * path; /* How large is the archive entry? */ int64_t size; /* Old signal handlers. */ #ifdef SIGINFO void (*siginfo_old)(int); #endif void (*sigusr1_old)(int); }; static void siginfo_handler(int sig); /* Handler for SIGINFO / SIGUSR1. */ static void siginfo_handler(int sig) { (void)sig; /* UNUSED */ /* Record that SIGINFO or SIGUSR1 has been received. */ siginfo_received = 1; } void siginfo_init(struct bsdtar *bsdtar) { /* Allocate space for internal structure. */ - if ((bsdtar->siginfo = malloc(sizeof(struct siginfo))) == NULL) + if ((bsdtar->siginfo = malloc(sizeof(struct siginfo_data))) == NULL) bsdtar_errc(bsdtar, 1, errno, "malloc failed"); /* Set the strings to NULL so that free() is safe. */ bsdtar->siginfo->path = bsdtar->siginfo->oper = NULL; #ifdef SIGINFO /* We want to catch SIGINFO, if it exists. */ bsdtar->siginfo->siginfo_old = signal(SIGINFO, siginfo_handler); #endif /* ... and treat SIGUSR1 the same way as SIGINFO. */ bsdtar->siginfo->sigusr1_old = signal(SIGUSR1, siginfo_handler); } void siginfo_setinfo(struct bsdtar *bsdtar, const char * oper, const char * path, int64_t size) { /* Free old operation and path strings. */ free(bsdtar->siginfo->oper); free(bsdtar->siginfo->path); /* Duplicate strings and store entry size. */ if ((bsdtar->siginfo->oper = strdup(oper)) == NULL) bsdtar_errc(bsdtar, 1, errno, "Cannot strdup"); if ((bsdtar->siginfo->path = strdup(path)) == NULL) bsdtar_errc(bsdtar, 1, errno, "Cannot strdup"); bsdtar->siginfo->size = size; } void siginfo_printinfo(struct bsdtar *bsdtar, off_t progress) { /* If there's a signal to handle and we know what we're doing... */ if ((siginfo_received == 1) && (bsdtar->siginfo->path != NULL) && (bsdtar->siginfo->oper != NULL)) { if (bsdtar->verbose) fprintf(stderr, "\n"); if (bsdtar->siginfo->size > 0) { safe_fprintf(stderr, "%s %s (%ju / %" PRId64 ")", bsdtar->siginfo->oper, bsdtar->siginfo->path, (uintmax_t)progress, bsdtar->siginfo->size); } else { safe_fprintf(stderr, "%s %s", bsdtar->siginfo->oper, bsdtar->siginfo->path); } if (!bsdtar->verbose) fprintf(stderr, "\n"); siginfo_received = 0; } } void siginfo_done(struct bsdtar *bsdtar) { #ifdef SIGINFO /* Restore old SIGINFO handler. */ signal(SIGINFO, bsdtar->siginfo->siginfo_old); #endif /* And the old SIGUSR1 handler, too. */ signal(SIGUSR1, bsdtar->siginfo->sigusr1_old); /* Free strings. */ free(bsdtar->siginfo->path); free(bsdtar->siginfo->oper); /* Free internal data structure. */ free(bsdtar->siginfo); }