Date: Sun, 17 Jul 2011 21:42:22 +0000 (UTC) From: Martin Matuska <mm@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r224154 - in head/usr.bin/cpio: . test Message-ID: <201107172142.p6HLgMX6091558@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mm Date: Sun Jul 17 21:42:22 2011 New Revision: 224154 URL: http://svn.freebsd.org/changeset/base/224154 Log: Update bsdcpio to 2.8.4 Use common code from lib/libarchive/libarchive_fe Approved by: kientzle MFC after: 2 weeks Added: head/usr.bin/cpio/test/test_cmdline.c (contents, props changed) head/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.bin.uu (contents, props changed) head/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.crc.uu (contents, props changed) head/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.newc.uu (contents, props changed) head/usr.bin/cpio/test/test_gcpio_compat_ref_nosym.ustar.uu (contents, props changed) head/usr.bin/cpio/test/test_option_B_upper.c (contents, props changed) head/usr.bin/cpio/test/test_option_C_upper.c (contents, props changed) head/usr.bin/cpio/test/test_option_J_upper.c (contents, props changed) head/usr.bin/cpio/test/test_option_L_upper.c (contents, props changed) head/usr.bin/cpio/test/test_option_Z_upper.c (contents, props changed) head/usr.bin/cpio/test/test_option_l.c (contents, props changed) head/usr.bin/cpio/test/test_option_lzma.c (contents, props changed) Deleted: head/usr.bin/cpio/err.c head/usr.bin/cpio/err.h head/usr.bin/cpio/line_reader.c head/usr.bin/cpio/line_reader.h head/usr.bin/cpio/matching.c head/usr.bin/cpio/matching.h head/usr.bin/cpio/pathmatch.c head/usr.bin/cpio/pathmatch.h head/usr.bin/cpio/test/test_option_B.c head/usr.bin/cpio/test/test_option_L.c head/usr.bin/cpio/test/test_option_ell.c Modified: head/usr.bin/cpio/Makefile head/usr.bin/cpio/cmdline.c head/usr.bin/cpio/config_freebsd.h head/usr.bin/cpio/cpio.c head/usr.bin/cpio/cpio.h head/usr.bin/cpio/test/Makefile head/usr.bin/cpio/test/main.c head/usr.bin/cpio/test/test.h head/usr.bin/cpio/test/test_0.c head/usr.bin/cpio/test/test_basic.c head/usr.bin/cpio/test/test_format_newc.c head/usr.bin/cpio/test/test_gcpio_compat.c head/usr.bin/cpio/test/test_option_a.c head/usr.bin/cpio/test/test_option_c.c head/usr.bin/cpio/test/test_option_d.c head/usr.bin/cpio/test/test_option_f.c head/usr.bin/cpio/test/test_option_help.c head/usr.bin/cpio/test/test_option_m.c head/usr.bin/cpio/test/test_option_t.c head/usr.bin/cpio/test/test_option_u.c head/usr.bin/cpio/test/test_option_version.c head/usr.bin/cpio/test/test_option_y.c head/usr.bin/cpio/test/test_option_z.c head/usr.bin/cpio/test/test_owner_parse.c head/usr.bin/cpio/test/test_passthrough_dotdot.c head/usr.bin/cpio/test/test_passthrough_reverse.c head/usr.bin/cpio/test/test_pathmatch.c Modified: head/usr.bin/cpio/Makefile ============================================================================== --- head/usr.bin/cpio/Makefile Sun Jul 17 21:33:15 2011 (r224153) +++ head/usr.bin/cpio/Makefile Sun Jul 17 21:42:22 2011 (r224154) @@ -3,17 +3,24 @@ .include <bsd.own.mk> PROG= bsdcpio -BSDCPIO_VERSION_STRING=2.8.3 -SRCS= cpio.c cmdline.c err.c line_reader.c matching.c pathmatch.c +BSDCPIO_VERSION_STRING=2.8.4 + +SRCS= cpio.c cmdline.c + +.PATH: ${.CURDIR}/../../lib/libarchive/libarchive_fe +SRCS+= err.c line_reader.c matching.c pathmatch.c + CFLAGS+= -DBSDCPIO_VERSION_STRING=\"${BSDCPIO_VERSION_STRING}\" CFLAGS+= -DPLATFORM_CONFIG_H=\"config_freebsd.h\" +CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../../lib/libarchive/libarchive_fe + .ifdef RELEASE_CRUNCH # FreeBSD's installer uses cpio in crunched binaries that are # statically linked, cannot use -lcrypto, and are size sensitive. CFLAGS+= -DSMALLER .endif -DPADD= ${LIBARCHIVE} ${LIBZ} ${LIBBZ2} ${LIBMD} ${LIBLZMA} -LDADD= -larchive -lz -lbz2 -lmd -llzma +DPADD= ${LIBARCHIVE} ${LIBZ} ${LIBBZ2} ${LIBMD} ${LIBLZMA} ${LIBBSDXML} +LDADD= -larchive -lz -lbz2 -lmd -llzma -lbsdxml .if ${MK_OPENSSL} != "no" DPADD+= ${LIBCRYPTO} LDADD+= -lcrypto Modified: head/usr.bin/cpio/cmdline.c ============================================================================== --- head/usr.bin/cpio/cmdline.c Sun Jul 17 21:33:15 2011 (r224153) +++ head/usr.bin/cpio/cmdline.c Sun Jul 17 21:42:22 2011 (r224154) @@ -175,7 +175,7 @@ cpio_getopt(struct cpio *cpio) /* Otherwise, pick up the next word. */ opt_word = *cpio->argv; if (opt_word == NULL) { - warnc(0, + lafe_warnc(0, "Option -%c requires an argument", opt); return ('?'); @@ -226,13 +226,13 @@ cpio_getopt(struct cpio *cpio) /* Fail if there wasn't a unique match. */ if (match == NULL) { - warnc(0, + lafe_warnc(0, "Option %s%s is not supported", long_prefix, opt_word); return ('?'); } if (match2 != NULL) { - warnc(0, + lafe_warnc(0, "Ambiguous option %s%s (matches --%s and --%s)", long_prefix, opt_word, match->name, match2->name); return ('?'); @@ -244,7 +244,7 @@ cpio_getopt(struct cpio *cpio) if (cpio->optarg == NULL) { cpio->optarg = *cpio->argv; if (cpio->optarg == NULL) { - warnc(0, + lafe_warnc(0, "Option %s%s requires an argument", long_prefix, match->name); return ('?'); @@ -255,7 +255,7 @@ cpio_getopt(struct cpio *cpio) } else { /* Argument forbidden: fail if there is one. */ if (cpio->optarg != NULL) { - warnc(0, + lafe_warnc(0, "Option %s%s does not allow an argument", long_prefix, match->name); return ('?'); Modified: head/usr.bin/cpio/config_freebsd.h ============================================================================== --- head/usr.bin/cpio/config_freebsd.h Sun Jul 17 21:33:15 2011 (r224153) +++ head/usr.bin/cpio/config_freebsd.h Sun Jul 17 21:42:22 2011 (r224154) @@ -53,4 +53,5 @@ #define HAVE_UNSIGNED_LONG_LONG 1 #define HAVE_UTIME_H 1 #define HAVE_UTIMES 1 +#define HAVE_WCSCMP 1 Modified: head/usr.bin/cpio/cpio.c ============================================================================== --- head/usr.bin/cpio/cpio.c Sun Jul 17 21:33:15 2011 (r224153) +++ head/usr.bin/cpio/cpio.c Sun Jul 17 21:42:22 2011 (r224154) @@ -136,19 +136,19 @@ main(int argc, char *argv[]) cpio->buff = buff; cpio->buff_size = sizeof(buff); - /* Need progname before calling warnc. */ + /* Need lafe_progname before calling lafe_warnc. */ if (*argv == NULL) - progname = "bsdcpio"; + lafe_progname = "bsdcpio"; else { #if defined(_WIN32) && !defined(__CYGWIN__) - progname = strrchr(*argv, '\\'); + lafe_progname = strrchr(*argv, '\\'); #else - progname = strrchr(*argv, '/'); + lafe_progname = strrchr(*argv, '/'); #endif - if (progname != NULL) - progname++; + if (lafe_progname != NULL) + lafe_progname++; else - progname = *argv; + lafe_progname = *argv; } cpio->uid_override = -1; @@ -189,7 +189,7 @@ main(int argc, char *argv[]) case 'C': /* NetBSD/OpenBSD */ cpio->bytes_per_block = atoi(cpio->optarg); if (cpio->bytes_per_block <= 0) - errc(1, 0, "Invalid blocksize %s", cpio->optarg); + lafe_errc(1, 0, "Invalid blocksize %s", cpio->optarg); break; case 'c': /* POSIX 1997 */ cpio->format = "odc"; @@ -198,14 +198,14 @@ main(int argc, char *argv[]) cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR; break; case 'E': /* NetBSD/OpenBSD */ - include_from_file(&cpio->matching, + lafe_include_from_file(&cpio->matching, cpio->optarg, cpio->option_null); break; case 'F': /* NetBSD/OpenBSD/GNU cpio */ cpio->filename = cpio->optarg; break; case 'f': /* POSIX 1997 */ - exclude(&cpio->matching, cpio->optarg); + lafe_exclude(&cpio->matching, cpio->optarg); break; case 'H': /* GNU cpio (also --format) */ cpio->format = cpio->optarg; @@ -218,7 +218,7 @@ main(int argc, char *argv[]) break; case 'i': /* POSIX 1997 */ if (cpio->mode != '\0') - errc(1, 0, + lafe_errc(1, 0, "Cannot use both -i and -%c", cpio->mode); cpio->mode = opt; break; @@ -255,13 +255,13 @@ main(int argc, char *argv[]) break; case 'o': /* POSIX 1997 */ if (cpio->mode != '\0') - errc(1, 0, + lafe_errc(1, 0, "Cannot use both -o and -%c", cpio->mode); cpio->mode = opt; break; case 'p': /* POSIX 1997 */ if (cpio->mode != '\0') - errc(1, 0, + lafe_errc(1, 0, "Cannot use both -p and -%c", cpio->mode); cpio->mode = opt; cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; @@ -277,7 +277,7 @@ main(int argc, char *argv[]) * also; use that to set [ug]name_override. */ errmsg = owner_parse(cpio->optarg, &uid, &gid); if (errmsg) { - warnc(-1, "%s", errmsg); + lafe_warnc(-1, "%s", errmsg); usage(); } if (uid != -1) { @@ -335,16 +335,16 @@ main(int argc, char *argv[]) cpio->mode = 'i'; /* -t requires -i */ if (cpio->option_list && cpio->mode != 'i') - errc(1, 0, "Option -t requires -i"); + lafe_errc(1, 0, "Option -t requires -i"); /* -n requires -it */ if (cpio->option_numeric_uid_gid && !cpio->option_list) - errc(1, 0, "Option -n requires -it"); + lafe_errc(1, 0, "Option -n requires -it"); /* Can only specify format when writing */ if (cpio->format != NULL && cpio->mode != 'o') - errc(1, 0, "Option --format requires -o"); + lafe_errc(1, 0, "Option --format requires -o"); /* -l requires -p */ if (cpio->option_link && cpio->mode != 'p') - errc(1, 0, "Option -l requires -p"); + lafe_errc(1, 0, "Option -l requires -p"); /* TODO: Flag other nonsensical combinations. */ switch (cpio->mode) { @@ -358,7 +358,7 @@ main(int argc, char *argv[]) break; case 'i': while (*cpio->argv != NULL) { - include(&cpio->matching, *cpio->argv); + lafe_include(&cpio->matching, *cpio->argv); --cpio->argc; ++cpio->argv; } @@ -369,12 +369,12 @@ main(int argc, char *argv[]) break; case 'p': if (*cpio->argv == NULL || **cpio->argv == '\0') - errc(1, 0, + lafe_errc(1, 0, "-p mode requires a target directory"); mode_pass(cpio, *cpio->argv); break; default: - errc(1, 0, + lafe_errc(1, 0, "Must specify at least one of -i, -o, or -p"); } @@ -388,7 +388,7 @@ usage(void) { const char *p; - p = progname; + p = lafe_progname; fprintf(stderr, "Brief Usage:\n"); fprintf(stderr, " List: %s -it < archive\n", p); @@ -426,7 +426,7 @@ long_help(void) const char *prog; const char *p; - prog = progname; + prog = lafe_progname; fflush(stderr); @@ -459,16 +459,16 @@ static void mode_out(struct cpio *cpio) { struct archive_entry *entry, *spare; - struct line_reader *lr; + struct lafe_line_reader *lr; const char *p; int r; if (cpio->option_append) - errc(1, 0, "Append mode not yet supported."); + lafe_errc(1, 0, "Append mode not yet supported."); cpio->archive_read_disk = archive_read_disk_new(); if (cpio->archive_read_disk == NULL) - errc(1, 0, "Failed to allocate archive object"); + lafe_errc(1, 0, "Failed to allocate archive object"); if (cpio->option_follow_links) archive_read_disk_set_symlink_logical(cpio->archive_read_disk); else @@ -477,7 +477,7 @@ mode_out(struct cpio *cpio) cpio->archive = archive_write_new(); if (cpio->archive == NULL) - errc(1, 0, "Failed to allocate archive object"); + lafe_errc(1, 0, "Failed to allocate archive object"); switch (cpio->compress) { case 'J': r = archive_write_set_compression_xz(cpio->archive); @@ -499,10 +499,10 @@ mode_out(struct cpio *cpio) break; } if (r < ARCHIVE_WARN) - errc(1, 0, "Requested compression not available"); + lafe_errc(1, 0, "Requested compression not available"); r = archive_write_set_format_by_name(cpio->archive, cpio->format); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(cpio->archive)); + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); archive_write_set_bytes_per_block(cpio->archive, cpio->bytes_per_block); cpio->linkresolver = archive_entry_linkresolver_new(); archive_entry_linkresolver_set_strategy(cpio->linkresolver, @@ -513,11 +513,11 @@ mode_out(struct cpio *cpio) */ r = archive_write_open_file(cpio->archive, cpio->filename); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(cpio->archive)); - lr = line_reader("-", cpio->option_null); - while ((p = line_reader_next(lr)) != NULL) + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); + lr = lafe_line_reader("-", cpio->option_null); + while ((p = lafe_line_reader_next(lr)) != NULL) file_to_archive(cpio, p); - line_reader_free(lr); + lafe_line_reader_free(lr); /* * The hardlink detection may have queued up a couple of entries @@ -534,7 +534,7 @@ mode_out(struct cpio *cpio) r = archive_write_close(cpio->archive); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(cpio->archive)); + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); if (!cpio->quiet) { int64_t blocks = @@ -566,15 +566,15 @@ file_to_archive(struct cpio *cpio, const */ entry = archive_entry_new(); if (entry == NULL) - errc(1, 0, "Couldn't allocate entry"); + lafe_errc(1, 0, "Couldn't allocate entry"); archive_entry_copy_sourcepath(entry, srcpath); r = archive_read_disk_entry_from_file(cpio->archive_read_disk, entry, -1, NULL); if (r < ARCHIVE_FAILED) - errc(1, 0, "%s", + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive_read_disk)); if (r < ARCHIVE_OK) - warnc(0, "%s", + lafe_warnc(0, "%s", archive_error_string(cpio->archive_read_disk)); if (r <= ARCHIVE_FAILED) { cpio->return_value = 1; @@ -607,7 +607,7 @@ file_to_archive(struct cpio *cpio, const free(cpio->pass_destpath); cpio->pass_destpath = malloc(cpio->pass_destpath_alloc); if (cpio->pass_destpath == NULL) - errc(1, ENOMEM, + lafe_errc(1, ENOMEM, "Can't allocate path buffer"); } strcpy(cpio->pass_destpath, cpio->destdir); @@ -673,7 +673,7 @@ entry_to_archive(struct cpio *cpio, stru /* Save the original entry in case we need it later. */ t = archive_entry_clone(entry); if (t == NULL) - errc(1, ENOMEM, "Can't create link"); + lafe_errc(1, ENOMEM, "Can't create link"); /* Note: link(2) doesn't create parent directories, * so we use archive_write_header() instead as a * convenience. */ @@ -683,7 +683,7 @@ entry_to_archive(struct cpio *cpio, stru r = archive_write_header(cpio->archive, t); archive_entry_free(t); if (r != ARCHIVE_OK) - warnc(archive_errno(cpio->archive), + lafe_warnc(archive_errno(cpio->archive), "%s", archive_error_string(cpio->archive)); if (r == ARCHIVE_FATAL) exit(1); @@ -691,7 +691,7 @@ entry_to_archive(struct cpio *cpio, stru if (r != ARCHIVE_OK && archive_errno(cpio->archive) == EXDEV) { /* Cross-device link: Just fall through and use * the original entry to copy the file over. */ - warnc(0, "Copying file instead"); + lafe_warnc(0, "Copying file instead"); } else #endif return (0); @@ -705,7 +705,7 @@ entry_to_archive(struct cpio *cpio, stru if (archive_entry_size(entry) > 0) { fd = open(srcpath, O_RDONLY | O_BINARY); if (fd < 0) { - warnc(errno, + lafe_warnc(errno, "%s: could not open file", srcpath); goto cleanup; } @@ -717,7 +717,7 @@ entry_to_archive(struct cpio *cpio, stru r = archive_write_header(cpio->archive, entry); if (r != ARCHIVE_OK) - warnc(archive_errno(cpio->archive), + lafe_warnc(archive_errno(cpio->archive), "%s: %s", srcpath, archive_error_string(cpio->archive)); @@ -731,10 +731,10 @@ entry_to_archive(struct cpio *cpio, stru r = archive_write_data(cpio->archive, cpio->buff, bytes_read); if (r < 0) - errc(1, archive_errno(cpio->archive), + lafe_errc(1, archive_errno(cpio->archive), "%s", archive_error_string(cpio->archive)); if (r < bytes_read) { - warnc(0, + lafe_warnc(0, "Truncated write; file may have grown while being archived."); } bytes_read = read(fd, cpio->buff, cpio->buff_size); @@ -763,7 +763,7 @@ restore_time(struct cpio *cpio, struct a (void)name; /* UNUSED */ if (!warned) - warnc(0, "Can't restore access times on this platform"); + lafe_warnc(0, "Can't restore access times on this platform"); warned = 1; return (fd); #else @@ -801,7 +801,7 @@ restore_time(struct cpio *cpio, struct a if ((AE_IFLNK != archive_entry_filetype(entry)) && utimes(name, times) != 0) #endif - warnc(errno, "Can't update time for %s", name); + lafe_warnc(errno, "Can't update time for %s", name); #endif return (fd); } @@ -818,28 +818,28 @@ mode_in(struct cpio *cpio) ext = archive_write_disk_new(); if (ext == NULL) - errc(1, 0, "Couldn't allocate restore object"); + lafe_errc(1, 0, "Couldn't allocate restore object"); r = archive_write_disk_set_options(ext, cpio->extract_flags); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(ext)); + lafe_errc(1, 0, "%s", archive_error_string(ext)); a = archive_read_new(); if (a == NULL) - errc(1, 0, "Couldn't allocate archive object"); + lafe_errc(1, 0, "Couldn't allocate archive object"); archive_read_support_compression_all(a); archive_read_support_format_all(a); if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) - errc(1, archive_errno(a), + lafe_errc(1, archive_errno(a), "%s", archive_error_string(a)); for (;;) { r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { - errc(1, archive_errno(a), + lafe_errc(1, archive_errno(a), "%s", archive_error_string(a)); } - if (excluded(cpio->matching, archive_entry_pathname(entry))) + if (lafe_excluded(cpio->matching, archive_entry_pathname(entry))) continue; if (cpio->option_rename) { destpath = cpio_rename(archive_entry_pathname(entry)); @@ -867,10 +867,10 @@ mode_in(struct cpio *cpio) } r = archive_read_close(a); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(a)); + lafe_errc(1, 0, "%s", archive_error_string(a)); r = archive_write_close(ext); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(ext)); + lafe_errc(1, 0, "%s", archive_error_string(ext)); if (!cpio->quiet) { int64_t blocks = (archive_position_uncompressed(a) + 511) / 512; @@ -899,13 +899,13 @@ extract_data(struct archive *ar, struct if (r == ARCHIVE_EOF) return (ARCHIVE_OK); if (r != ARCHIVE_OK) { - warnc(archive_errno(ar), + lafe_warnc(archive_errno(ar), "%s", archive_error_string(ar)); exit(1); } r = archive_write_data_block(aw, block, size, offset); if (r != ARCHIVE_OK) { - warnc(archive_errno(aw), + lafe_warnc(archive_errno(aw), "%s", archive_error_string(aw)); return (r); } @@ -921,22 +921,22 @@ mode_list(struct cpio *cpio) a = archive_read_new(); if (a == NULL) - errc(1, 0, "Couldn't allocate archive object"); + lafe_errc(1, 0, "Couldn't allocate archive object"); archive_read_support_compression_all(a); archive_read_support_format_all(a); if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) - errc(1, archive_errno(a), + lafe_errc(1, archive_errno(a), "%s", archive_error_string(a)); for (;;) { r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { - errc(1, archive_errno(a), + lafe_errc(1, archive_errno(a), "%s", archive_error_string(a)); } - if (excluded(cpio->matching, archive_entry_pathname(entry))) + if (lafe_excluded(cpio->matching, archive_entry_pathname(entry))) continue; if (cpio->verbose) list_item_verbose(cpio, entry); @@ -945,7 +945,7 @@ mode_list(struct cpio *cpio) } r = archive_read_close(a); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(a)); + lafe_errc(1, 0, "%s", archive_error_string(a)); if (!cpio->quiet) { int64_t blocks = (archive_position_uncompressed(a) + 511) / 512; @@ -1040,7 +1040,7 @@ list_item_verbose(struct cpio *cpio, str static void mode_pass(struct cpio *cpio, const char *destdir) { - struct line_reader *lr; + struct lafe_line_reader *lr; const char *p; int r; @@ -1052,31 +1052,31 @@ mode_pass(struct cpio *cpio, const char cpio->archive = archive_write_disk_new(); if (cpio->archive == NULL) - errc(1, 0, "Failed to allocate archive object"); + lafe_errc(1, 0, "Failed to allocate archive object"); r = archive_write_disk_set_options(cpio->archive, cpio->extract_flags); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(cpio->archive)); + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); cpio->linkresolver = archive_entry_linkresolver_new(); archive_write_disk_set_standard_lookup(cpio->archive); cpio->archive_read_disk = archive_read_disk_new(); if (cpio->archive_read_disk == NULL) - errc(1, 0, "Failed to allocate archive object"); + lafe_errc(1, 0, "Failed to allocate archive object"); if (cpio->option_follow_links) archive_read_disk_set_symlink_logical(cpio->archive_read_disk); else archive_read_disk_set_symlink_physical(cpio->archive_read_disk); archive_read_disk_set_standard_lookup(cpio->archive_read_disk); - lr = line_reader("-", cpio->option_null); - while ((p = line_reader_next(lr)) != NULL) + lr = lafe_line_reader("-", cpio->option_null); + while ((p = lafe_line_reader_next(lr)) != NULL) file_to_archive(cpio, p); - line_reader_free(lr); + lafe_line_reader_free(lr); archive_entry_linkresolver_free(cpio->linkresolver); r = archive_write_close(cpio->archive); if (r != ARCHIVE_OK) - errc(1, 0, "%s", archive_error_string(cpio->archive)); + lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); if (!cpio->quiet) { int64_t blocks = @@ -1160,7 +1160,7 @@ lookup_name(struct cpio *cpio, struct na if (*name_cache_variable == NULL) { *name_cache_variable = malloc(sizeof(struct name_cache)); if (*name_cache_variable == NULL) - errc(1, ENOMEM, "No more memory"); + lafe_errc(1, ENOMEM, "No more memory"); memset(*name_cache_variable, 0, sizeof(struct name_cache)); (*name_cache_variable)->size = name_cache_size; } @@ -1217,7 +1217,7 @@ lookup_uname_helper(struct cpio *cpio, c if (pwent == NULL) { *name = NULL; if (errno != 0 && errno != ENOENT) - warnc(errno, "getpwuid(%d) failed", id); + lafe_warnc(errno, "getpwuid(%d) failed", id); return (errno); } @@ -1244,7 +1244,7 @@ lookup_gname_helper(struct cpio *cpio, c if (grent == NULL) { *name = NULL; if (errno != 0) - warnc(errno, "getgrgid(%d) failed", id); + lafe_warnc(errno, "getgrgid(%d) failed", id); return (errno); } Modified: head/usr.bin/cpio/cpio.h ============================================================================== --- head/usr.bin/cpio/cpio.h Sun Jul 17 21:33:15 2011 (r224153) +++ head/usr.bin/cpio/cpio.h Sun Jul 17 21:42:22 2011 (r224154) @@ -88,7 +88,7 @@ struct cpio { struct name_cache *gname_cache; /* Work data. */ - struct matching *matching; + struct lafe_matching *matching; char *buff; size_t buff_size; }; Modified: head/usr.bin/cpio/test/Makefile ============================================================================== --- head/usr.bin/cpio/test/Makefile Sun Jul 17 21:33:15 2011 (r224153) +++ head/usr.bin/cpio/test/Makefile Sun Jul 17 21:42:22 2011 (r224154) @@ -2,24 +2,30 @@ # Where to find the cpio sources (for the internal unit tests) CPIO_SRCDIR=${.CURDIR}/.. -.PATH: ${CPIO_SRCDIR} -# Some cpio sources are pulled in for white-box tests -CPIO_SRCS= cmdline.c err.c pathmatch.c +.PATH: ${CPIO_SRCDIR} +CPIO_SRCS= cmdline.c + +.PATH: ${.CURDIR}/../../../lib/libarchive/libarchive_fe +TAR_SRCS= err.c pathmatch.c TESTS= \ test_0.c \ test_basic.c \ test_format_newc.c \ test_gcpio_compat.c \ + test_option_B_upper.c \ + test_option_C_upper.c \ + test_option_J_upper.c \ + test_option_L_upper.c \ + test_option_Z_upper.c \ test_option_a.c \ - test_option_B.c \ test_option_c.c \ test_option_d.c \ test_option_f.c \ test_option_help.c \ - test_option_L.c \ - test_option_ell.c \ + test_option_l.c \ + test_option_lzma.c \ test_option_m.c \ test_option_t.c \ test_option_u.c \ @@ -34,6 +40,7 @@ TESTS= \ # Build the test program SRCS= list.h \ ${CPIO_SRCS} \ + ${TAR_SRCS} \ ${TESTS} \ main.c @@ -46,9 +53,11 @@ DPADD=${LIBARCHIVE} ${LIBBZ2} ${LIBZ} ${ CFLAGS+= -DPLATFORM_CONFIG_H=\"config_freebsd.h\" CFLAGS+= -I.. LDADD= -larchive -lz -lbz2 -llzma -CFLAGS+= -static -g -O2 -Wall +#CFLAGS+= -static -g -O2 -Wall +CFLAGS+= -g -O2 -Wall CFLAGS+= -I${.OBJDIR} CFLAGS+= -I${CPIO_SRCDIR} +CFLAGS+= -I${.CURDIR}/../../../lib/libarchive/libarchive_fe # Uncomment to link against dmalloc #LDADD+= -L/usr/local/lib -ldmalloc Modified: head/usr.bin/cpio/test/main.c ============================================================================== --- head/usr.bin/cpio/test/main.c Sun Jul 17 21:33:15 2011 (r224153) +++ head/usr.bin/cpio/test/main.c Sun Jul 17 21:42:22 2011 (r224154) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2009 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,12 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* - * Various utility routines useful for test programs. - * Each test program is linked against this file. - */ #include "test.h" - #include <errno.h> #include <locale.h> #include <stdarg.h> @@ -38,149 +33,318 @@ * This same file is used pretty much verbatim for all test harnesses. * * The next few lines are the only differences. + * TODO: Move this into a separate configuration header, have all test + * suites share one copy of this file. */ -#define PROGRAM "bsdcpio" /* Name of program being tested. */ +__FBSDID("$FreeBSD$"); +#define KNOWNREF "test_option_f.cpio.uu" #define ENVBASE "BSDCPIO" /* Prefix for environment variables. */ +#define PROGRAM "bsdcpio" /* Name of program being tested. */ +#undef LIBRARY /* Not testing a library. */ #undef EXTRA_DUMP /* How to dump extra data */ /* How to generate extra version info. */ #define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "") -#define KNOWNREF "test_option_f.cpio.uu" -__FBSDID("$FreeBSD$"); /* - * "list.h" is simply created by "grep DEFINE_TEST"; it has - * a line like - * DEFINE_TEST(test_function) - * for each test. - * Include it here with a suitable DEFINE_TEST to declare all of the - * test functions. + * + * Windows support routines + * + * Note: Configuration is a tricky issue. Using HAVE_* feature macros + * in the test harness is dangerous because they cover up + * configuration errors. The classic example of this is omitting a + * configure check. If libarchive and libarchive_test both look for + * the same feature macro, such errors are hard to detect. Platform + * macros (e.g., _WIN32 or __GNUC__) are a little better, but can + * easily lead to very messy code. It's best to limit yourself + * to only the most generic programming techniques in the test harness + * and thus avoid conditionals altogether. Where that's not possible, + * try to minimize conditionals by grouping platform-specific tests in + * one place (e.g., test_acl_freebsd) or by adding new assert() + * functions (e.g., assertMakeHardlink()) to cover up platform + * differences. Platform-specific coding in libarchive_test is often + * a symptom that some capability is missing from libarchive itself. */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); -#include "list.h" +#if defined(_WIN32) && !defined(__CYGWIN__) +#include <io.h> +#include <windows.h> +#ifndef F_OK +#define F_OK (0) +#endif +#ifndef S_ISDIR +#define S_ISDIR(m) ((m) & _S_IFDIR) +#endif +#ifndef S_ISREG +#define S_ISREG(m) ((m) & _S_IFREG) +#endif +#if !defined(__BORLANDC__) +#define access _access +#define chdir _chdir +#endif +#ifndef fileno +#define fileno _fileno +#endif +/*#define fstat _fstat64*/ +#if !defined(__BORLANDC__) +#define getcwd _getcwd +#endif +#define lstat stat +/*#define lstat _stat64*/ +/*#define stat _stat64*/ +#define rmdir _rmdir +#if !defined(__BORLANDC__) +#define strdup _strdup +#define umask _umask +#endif +#define int64_t __int64 +#endif + +#if defined(HAVE__CrtSetReportMode) +# include <crtdbg.h> +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) +void *GetFunctionKernel32(const char *name) +{ + static HINSTANCE lib; + static int set; + if (!set) { + set = 1; + lib = LoadLibrary("kernel32.dll"); + } + if (lib == NULL) { + fprintf(stderr, "Can't load kernel32.dll?!\n"); + exit(1); + } + return (void *)GetProcAddress(lib, name); +} + +static int +my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateSymbolicLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, flags); +} + +static int +my_CreateHardLinkA(const char *linkname, const char *target) +{ + static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); + static int set; + if (!set) { + set = 1; + f = GetFunctionKernel32("CreateHardLinkA"); + } + return f == NULL ? 0 : (*f)(linkname, target, NULL); +} + +int +my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) +{ + HANDLE h; + int r; -/* Interix doesn't define these in a standard header. */ -#if __INTERIX__ -extern char *optarg; -extern int optind; + memset(bhfi, 0, sizeof(*bhfi)); + h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) + return (0); + r = GetFileInformationByHandle(h, bhfi); + CloseHandle(h); + return (r); +} #endif +#if defined(HAVE__CrtSetReportMode) +static void +invalid_parameter_handler(const wchar_t * expression, + const wchar_t * function, const wchar_t * file, + unsigned int line, uintptr_t pReserved) +{ + /* nop */ +} +#endif + +/* + * + * OPTIONS FLAGS + * + */ + /* Enable core dump on failure. */ static int dump_on_failure = 0; -/* Default is to remove temp dirs for successful tests. */ +/* Default is to remove temp dirs and log data for successful tests. */ static int keep_temp_files = 0; -/* Default is to print some basic information about each test. */ -static int quiet_flag = 0; -/* Default is to summarize repeated failures. */ -static int verbose = 0; -/* Cumulative count of component failures. */ +/* Default is to just report pass/fail for each test. */ +static int verbosity = 0; +#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ +#define VERBOSITY_PASSFAIL 0 /* Default */ +#define VERBOSITY_LIGHT_REPORT 1 /* -v */ +#define VERBOSITY_FULL 2 /* -vv */ +/* A few places generate even more output for verbosity > VERBOSITY_FULL, + * mostly for debugging the test harness itself. */ +/* Cumulative count of assertion failures. */ static int failures = 0; -/* Cumulative count of skipped component tests. */ +/* Cumulative count of reported skips. */ static int skips = 0; -/* Cumulative count of assertions. */ +/* Cumulative count of assertions checked. */ static int assertions = 0; /* Directory where uuencoded reference files can be found. */ static const char *refdir; /* - * My own implementation of the standard assert() macro emits the - * message in the same format as GCC (file:line: message). - * It also includes some additional useful information. - * This makes it a lot easier to skim through test failures in - * Emacs. ;-) - * - * It also supports a few special features specifically to simplify - * test harnesses: - * failure(fmt, args) -- Stores a text string that gets - * printed if the following assertion fails, good for - * explaining subtle tests. - */ -static char msg[4096]; - -/* - * For each test source file, we remember how many times each - * failure was reported. + * Report log information selectively to console and/or disk log. */ -static const char *failed_filename = NULL; -static struct line { - int line; - int count; -} failed_lines[1000]; - -/* - * Count this failure; return the number of previous failures. - */ -static int -previous_failures(const char *filename, int line) +static int log_console = 0; +static FILE *logfile; +static void +vlogprintf(const char *fmt, va_list ap) { - unsigned int i; - int count; +#ifdef va_copy + va_list lfap; + va_copy(lfap, ap); +#endif + if (log_console) + vfprintf(stdout, fmt, ap); + if (logfile != NULL) +#ifdef va_copy + vfprintf(logfile, fmt, lfap); + va_end(lfap); +#else + vfprintf(logfile, fmt, ap); +#endif +} - if (failed_filename == NULL || strcmp(failed_filename, filename) != 0) - memset(failed_lines, 0, sizeof(failed_lines)); - failed_filename = filename; +static void +logprintf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vlogprintf(fmt, ap); + va_end(ap); +} - for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { - if (failed_lines[i].line == line) { - count = failed_lines[i].count; - failed_lines[i].count++; - return (count); - } - if (failed_lines[i].line == 0) { - failed_lines[i].line = line; - failed_lines[i].count = 1; - return (0); - } - } - return (0); +/* Set up a message to display only if next assertion fails. */ +static char msgbuff[4096]; +static const char *msg, *nextmsg; +void +failure(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vsprintf(msgbuff, fmt, ap); + va_end(ap); + nextmsg = msgbuff; } /* * Copy arguments into file-local variables. + * This was added to permit vararg assert() functions without needing + * variadic wrapper macros. Turns out that the vararg capability is almost + * never used, so almost all of the vararg assertions can be simplified + * by removing the vararg capability and reworking the wrapper macro to + * pass __FILE__, __LINE__ directly into the function instead of using + * this hook. I suspect this machinery is used so rarely that we + * would be better off just removing it entirely. That would simplify + * the code here noticably. */ static const char *test_filename; static int test_line; static void *test_extra; -void test_setup(const char *filename, int line) +void assertion_setup(const char *filename, int line) { test_filename = filename; test_line = line; } +/* Called at the beginning of each assert() function. */ +static void +assertion_count(const char *file, int line) +{ + (void)file; /* UNUSED */ + (void)line; /* UNUSED */ + ++assertions; + /* Proper handling of "failure()" message. */ + msg = nextmsg; + nextmsg = NULL; + /* Uncomment to print file:line after every assertion. + * Verbose, but occasionally useful in tracking down crashes. */ + /* printf("Checked %s:%d\n", file, line); */ +} + /* - * Inform user that we're skipping a test. + * For each test source file, we remember how many times each + * assertion was reported. Cleared before each new test, + * used by test_summarize(). */ *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107172142.p6HLgMX6091558>