[Midnightbsd-cvs] src [9572] trunk/usr.bin/ar: sync with 10 stable.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Mon Sep 18 22:07:07 EDT 2017
Revision: 9572
http://svnweb.midnightbsd.org/src/?rev=9572
Author: laffer1
Date: 2017-09-18 22:07:06 -0400 (Mon, 18 Sep 2017)
Log Message:
-----------
sync with 10 stable.
Modified Paths:
--------------
trunk/usr.bin/ar/ar.1
trunk/usr.bin/ar/ar.c
trunk/usr.bin/ar/read.c
trunk/usr.bin/ar/write.c
Modified: trunk/usr.bin/ar/ar.1
===================================================================
--- trunk/usr.bin/ar/ar.1 2017-09-19 02:05:09 UTC (rev 9571)
+++ trunk/usr.bin/ar/ar.1 2017-09-19 02:07:06 UTC (rev 9572)
@@ -23,7 +23,7 @@
.\"
.\" $MidnightBSD$
.\"
-.Dd December 22, 2011
+.Dd July 25, 2016
.Dt AR 1
.Os
.Sh NAME
@@ -66,6 +66,7 @@
.Op Fl D
.Op Fl f
.Op Fl s | Fl S
+.Op Fl U
.Op Fl v
.Op Fl z
.Ar archive
@@ -82,6 +83,7 @@
.Op Fl j
.Op Fl s | Fl S
.Op Fl u
+.Op Fl U
.Op Fl v
.Op Fl z
.Ar archive
@@ -112,6 +114,7 @@
.Fl M
.Nm ranlib
.Op Fl D
+.Op Fl U
.Ar archive ...
.Sh DESCRIPTION
The
@@ -202,11 +205,22 @@
.Fl r
or
.Fl q
-option, insert 0's instead of the real mtime, uid and gid values
+option,
+with the
+.Fl s
+option without other options, or when invoked as
+.Nm ranlib ,
+insert 0's instead of the real mtime, uid and gid values
and 0644 instead of file mode from the members named by arguments
.Ar .
This ensures that checksums on the resulting archives are reproducible
when member contents are identical.
+This option is enabled by default.
+If multiple
+.Fl D
+and
+.Fl U
+options are specified on the command line, the final one takes precedence.
.It Fl f
Synonymous with option
.Fl T .
@@ -316,6 +330,19 @@
.Ar
will be extracted only if they are newer than the corresponding
files in the file system.
+.It Fl U
+When used in combination with the
+.Fl r
+or
+.Fl q
+option, insert the real mtime, uid and gid, and file mode values
+from the members named by arguments
+.Ar .
+If multiple
+.Fl D
+and
+.Fl U
+options are specified on the command line, the final one takes precedence.
.It Fl v
Provide verbose output.
When used with the
Modified: trunk/usr.bin/ar/ar.c
===================================================================
--- trunk/usr.bin/ar/ar.c 2017-09-19 02:05:09 UTC (rev 9571)
+++ trunk/usr.bin/ar/ar.c 2017-09-19 02:07:06 UTC (rev 9572)
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/usr.bin/ar/ar.c,v 1.2 2012/07/20 02:01:37 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
#include <sys/queue.h>
#include <sys/types.h>
@@ -100,10 +100,12 @@
struct bsdar *bsdar, bsdar_storage;
char *p;
size_t len;
- int i, opt;
+ int i, opt, Dflag, Uflag;
bsdar = &bsdar_storage;
memset(bsdar, 0, sizeof(*bsdar));
+ Dflag = 0;
+ Uflag = 0;
if ((bsdar->progname = getprogname()) == NULL)
bsdar->progname = "ar";
@@ -113,7 +115,7 @@
len = strlen(bsdar->progname);
if (len >= strlen("ranlib") &&
strcmp(bsdar->progname + len - strlen("ranlib"), "ranlib") == 0) {
- while ((opt = getopt_long(argc, argv, "tDV", longopts,
+ while ((opt = getopt_long(argc, argv, "tDUV", longopts,
NULL)) != -1) {
switch(opt) {
case 't':
@@ -120,8 +122,13 @@
/* Ignored. */
break;
case 'D':
- bsdar->options |= AR_D;
+ Dflag = 1;
+ Uflag = 0;
break;
+ case 'U':
+ Uflag = 1;
+ Dflag = 0;
+ break;
case 'V':
ranlib_version();
break;
@@ -137,8 +144,11 @@
if (*argv == NULL)
ranlib_usage();
+ /* Enable determinstic mode unless -U is set. */
+ if (Uflag == 0)
+ bsdar->options |= AR_D;
bsdar->options |= AR_S;
- for (;(bsdar->filename = *argv++) != NULL;)
+ while ((bsdar->filename = *argv++) != NULL)
ar_mode_s(bsdar);
exit(EX_OK);
@@ -157,7 +167,7 @@
}
}
- while ((opt = getopt_long(argc, argv, "abCcdDfijlMmopqrSsTtuVvxz",
+ while ((opt = getopt_long(argc, argv, "abCcdDfijlMmopqrSsTtUuVvxz",
longopts, NULL)) != -1) {
switch(opt) {
case 'a':
@@ -177,7 +187,8 @@
set_mode(bsdar, opt);
break;
case 'D':
- bsdar->options |= AR_D;
+ Dflag = 1;
+ Uflag = 0;
break;
case 'f':
case 'T':
@@ -216,6 +227,10 @@
case 't':
set_mode(bsdar, opt);
break;
+ case 'U':
+ Uflag = 1;
+ Dflag = 0;
+ break;
case 'u':
bsdar->options |= AR_U;
break;
@@ -267,6 +282,11 @@
argv++;
}
+ /* Set determinstic mode for -D, and by default without -U. */
+ if (Dflag || (Uflag == 0 && (bsdar->mode == 'q' || bsdar->mode == 'r' ||
+ (bsdar->mode == '\0' && bsdar->options & AR_S))))
+ bsdar->options |= AR_D;
+
if (bsdar->options & AR_A)
only_mode(bsdar, "-a", "mqr");
if (bsdar->options & AR_B)
@@ -275,8 +295,10 @@
only_mode(bsdar, "-c", "qr");
if (bsdar->options & AR_CC)
only_mode(bsdar, "-C", "x");
- if (bsdar->options & AR_D)
+ if (Dflag)
only_mode(bsdar, "-D", "qr");
+ if (Uflag)
+ only_mode(bsdar, "-U", "qr");
if (bsdar->options & AR_O)
only_mode(bsdar, "-o", "x");
if (bsdar->options & AR_SS)
@@ -364,9 +386,9 @@
(void)fprintf(stderr, "\tar -m [-Tjsvz] archive file ...\n");
(void)fprintf(stderr, "\tar -m [-Tabijsvz] position archive file ...\n");
(void)fprintf(stderr, "\tar -p [-Tv] archive [file ...]\n");
- (void)fprintf(stderr, "\tar -q [-TcDjsvz] archive file ...\n");
- (void)fprintf(stderr, "\tar -r [-TcDjsuvz] archive file ...\n");
- (void)fprintf(stderr, "\tar -r [-TabcDijsuvz] position archive file ...\n");
+ (void)fprintf(stderr, "\tar -q [-TcDjsUvz] archive file ...\n");
+ (void)fprintf(stderr, "\tar -r [-TcDjsUuvz] archive file ...\n");
+ (void)fprintf(stderr, "\tar -r [-TabcDijsUuvz] position archive file ...\n");
(void)fprintf(stderr, "\tar -s [-jz] archive\n");
(void)fprintf(stderr, "\tar -t [-Tv] archive [file ...]\n");
(void)fprintf(stderr, "\tar -x [-CTouv] archive [file ...]\n");
@@ -378,7 +400,7 @@
ranlib_usage(void)
{
- (void)fprintf(stderr, "usage: ranlib [-t] archive ...\n");
+ (void)fprintf(stderr, "usage: ranlib [-DtU] archive ...\n");
(void)fprintf(stderr, "\tranlib -V\n");
exit(EX_USAGE);
}
Modified: trunk/usr.bin/ar/read.c
===================================================================
--- trunk/usr.bin/ar/read.c 2017-09-19 02:05:09 UTC (rev 9571)
+++ trunk/usr.bin/ar/read.c 2017-09-19 02:07:06 UTC (rev 9572)
@@ -102,7 +102,8 @@
continue;
}
- name = archive_entry_pathname(entry);
+ if ((name = archive_entry_pathname(entry)) == NULL)
+ break;
/* Skip pseudo members. */
if (strcmp(name, "/") == 0 || strcmp(name, "//") == 0)
@@ -186,7 +187,15 @@
if (bsdar->options & AR_V)
(void)fprintf(stdout, "x - %s\n", name);
- flags = 0;
+ /* Disallow absolute paths. */
+ if (name[0] == '/') {
+ bsdar_warnc(bsdar, 0,
+ "Absolute path '%s'", name);
+ continue;
+ }
+ /* Basic path security flags. */
+ flags = ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
+ ARCHIVE_EXTRACT_SECURE_NODOTDOT;
if (bsdar->options & AR_O)
flags |= ARCHIVE_EXTRACT_TIME;
Modified: trunk/usr.bin/ar/write.c
===================================================================
--- trunk/usr.bin/ar/write.c 2017-09-19 02:05:09 UTC (rev 9571)
+++ trunk/usr.bin/ar/write.c 2017-09-19 02:07:06 UTC (rev 9572)
@@ -41,6 +41,7 @@
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
+#include <unistd.h>
#include "ar.h"
@@ -61,6 +62,7 @@
static void free_obj(struct bsdar *bsdar, struct ar_obj *obj);
static void insert_obj(struct bsdar *bsdar, struct ar_obj *obj,
struct ar_obj *pos);
+static void prefault_buffer(const char *buf, size_t s);
static void read_objs(struct bsdar *bsdar, const char *archive,
int checkargv);
static void write_archive(struct bsdar *bsdar, char mode);
@@ -551,11 +553,35 @@
}
/*
+ * Fault in the buffer prior to writing as a workaround for poor performance
+ * due to interaction with kernel fs deadlock avoidance code. See the comment
+ * above vn_io_fault_doio() in sys/kern/vfs_vnops.c for details of the issue.
+ */
+static void
+prefault_buffer(const char *buf, size_t s)
+{
+ volatile const char *p;
+ size_t page_size;
+
+ if (s == 0)
+ return;
+ page_size = sysconf(_SC_PAGESIZE);
+ for (p = buf; p < buf + s; p += page_size)
+ *p;
+ /*
+ * Ensure we touch the last page as well, in case the buffer is not
+ * page-aligned.
+ */
+ *(volatile const char *)(buf + s - 1);
+}
+
+/*
* Wrapper for archive_write_data().
*/
static void
write_data(struct bsdar *bsdar, struct archive *a, const void *buf, size_t s)
{
+ prefault_buffer(buf, s);
if (archive_write_data(a, buf, s) != (ssize_t)s)
bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s",
archive_error_string(a));
More information about the Midnightbsd-cvs
mailing list