From nobody Thu Jan 27 22:10:49 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 50661197D86F; Thu, 27 Jan 2022 22:10:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JlFCZ19q2z3H2J; Thu, 27 Jan 2022 22:10:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643321450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lau9D8ob7FAeZ1gPMJ7n8jd34vTLrv0Xd3LwMLztB1I=; b=rvPcPV1oT4uJ8d5B+FaoNVFNresxJLaYdpP4ECwju0WFkCHTxcqMW6GS2pK8N6o/9lEA9W xfVyWekZQ+WNULd6Hg969HxnKB5+WPfSJefWiXc9UeVMGGLFCmSvVaGv1J2K4AZe2WlRA1 TpO/ZGsjRBdfih2Q+c26Uy9iVunU9vllZpObzC3Xt4Pqai4I14IG0wAy4Y/MhRqejJ9IEm 5Eg4AQ+aZ40LUjuJ5uaTzEM4JSd24K89qHD47tY+aclZV7kfQtpmc6uursojTEfxot3KqZ qKarsI2+wVfYeSb30esBvRhD1vHuNcUILiXwWru41Mio1aHOuXZAJEgj430kyQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0242C1E273; Thu, 27 Jan 2022 22:10:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20RMAn6x067175; Thu, 27 Jan 2022 22:10:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20RMAndi067174; Thu, 27 Jan 2022 22:10:49 GMT (envelope-from git) Date: Thu, 27 Jan 2022 22:10:49 GMT Message-Id: <202201272210.20RMAndi067174@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 41e6398f9bc1 - main - ar: Avoid overwriting the stdout file stream pointer List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 41e6398f9bc1bba4ed872118e742096d692fdfec Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643321450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lau9D8ob7FAeZ1gPMJ7n8jd34vTLrv0Xd3LwMLztB1I=; b=gcEwITNKkXCFOWlUP2T32qPFTQuMjO2eYZMfwraNE37JOGG7j8YEZcn0pQdEirGt9DJZgw 8/hItXEhh3hzYUFEYHdMj0I2hlz2ZhROIteGm60k8Gj1zjbjYxQN+YXMKubSM6ngVKTv5y jYWl33Shouzh2QibPnu47z5l2wLYLFpna29Ce/qPWnfK9R9k6gZGcA6MBDz+s61hAhCvTv +umM3zyn/f8OIO6OKYOoWV8/vlDu5+wxYXrwyUcjfWrVsPdJ+DUY7li1EPNM4BYFnesvuJ OiItNZiNvnlcf62uRoObYQPNVqlJCaWImXGHApTFS88NMJqoFVH0NEAg3sTMVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643321450; a=rsa-sha256; cv=none; b=dbpLCjIIsX9vZs7Cmz8M+xHW1Gd/3alt7q6R4gSprttq4RyQJ3ngrkvBScB1KAdqanhGeM cbZ3mBRCOvanv8uX2bbLvjG7yQ7AWF5f/UFpRmUZ7XouDXtJFp1rh5tPb1SanXorJHcDLx ElWj3AvuPr/sGPIyVEn6+y8jc9lGBYAYdLgEV46S7yjlRyoqI/NkWF/WIKvEY7zDhIeEhq hrvyP5Bj+A+twkiOsjACjr6jXeOdAEnGGlh40N0OIu/3BsVhtwLFl9EYmqCyENBnnTKZgn V8nmMlpFvm3rHCxZifD11dVxc8F/xihaLmrMmUDQWDyKrk9rtiIw4ZHRz1+vew== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=41e6398f9bc1bba4ed872118e742096d692fdfec commit 41e6398f9bc1bba4ed872118e742096d692fdfec Author: Mark Johnston AuthorDate: 2022-01-27 22:10:17 +0000 Commit: Mark Johnston CommitDate: 2022-01-27 22:10:17 +0000 ar: Avoid overwriting the stdout file stream pointer This doesn't work with musl, which defines stdout as FILE * const. Instead, explicitly pass the desired output stream to ar_read_archive(). No functional change intended. Reviewed by: emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34064 --- usr.bin/ar/acpyacc.y | 14 ++++++-------- usr.bin/ar/ar.c | 2 +- usr.bin/ar/ar.h | 2 +- usr.bin/ar/read.c | 18 +++++++++--------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/usr.bin/ar/acpyacc.y b/usr.bin/ar/acpyacc.y index 34156e1d2d58..1ce7197ef222 100644 --- a/usr.bin/ar/acpyacc.y +++ b/usr.bin/ar/acpyacc.y @@ -406,7 +406,7 @@ arscp_extract(struct list *list) if (!arscp_target_exist()) return; arscp_mlist2argv(list); - ar_read_archive(bsdar, 'x'); + ar_read_archive(bsdar, 'x', stdout); arscp_free_argv(); arscp_free_mlist(list); } @@ -422,7 +422,7 @@ arscp_list(void) bsdar->argv = NULL; /* Always verbose. */ bsdar->options |= AR_V; - ar_read_archive(bsdar, 't'); + ar_read_archive(bsdar, 't', stdout); bsdar->options &= ~AR_V; } @@ -433,10 +433,9 @@ arscp_dir(char *archive, struct list *list, char *rlt) FILE *out; /* If rlt != NULL, redirect output to it */ - out = NULL; + out = stdout; if (rlt) { - out = stdout; - if ((stdout = fopen(rlt, "w")) == NULL) + if ((out = fopen(rlt, "w")) == NULL) bsdar_errc(bsdar, errno, "fopen %s failed", rlt); } @@ -449,13 +448,12 @@ arscp_dir(char *archive, struct list *list, char *rlt) } if (verbose) bsdar->options |= AR_V; - ar_read_archive(bsdar, 't'); + ar_read_archive(bsdar, 't', out); bsdar->options &= ~AR_V; if (rlt) { - if (fclose(stdout) == EOF) + if (fclose(out) == EOF) bsdar_errc(bsdar, errno, "fclose %s failed", rlt); - stdout = out; free(rlt); } free(archive); diff --git a/usr.bin/ar/ar.c b/usr.bin/ar/ar.c index fb57fbe21e7f..17dd2a88d25b 100644 --- a/usr.bin/ar/ar.c +++ b/usr.bin/ar/ar.c @@ -330,7 +330,7 @@ main(int argc, char **argv) exitcode = ar_write_archive(bsdar, bsdar->mode); break; case 'p': case 't': case 'x': - exitcode = ar_read_archive(bsdar, bsdar->mode); + exitcode = ar_read_archive(bsdar, bsdar->mode, stdout); break; default: bsdar_usage(); diff --git a/usr.bin/ar/ar.h b/usr.bin/ar/ar.h index bcccf93a6016..66a7888c3e1c 100644 --- a/usr.bin/ar/ar.h +++ b/usr.bin/ar/ar.h @@ -115,7 +115,7 @@ struct bsdar { }; void ar_mode_script(struct bsdar *ar); -int ar_read_archive(struct bsdar *ar, int mode); +int ar_read_archive(struct bsdar *ar, int mode, FILE *out); int ar_write_archive(struct bsdar *ar, int mode); void bsdar_errc(struct bsdar *, int _code, const char *fmt, ...) __dead2; void bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...); diff --git a/usr.bin/ar/read.c b/usr.bin/ar/read.c index 81e0bfce1b7e..84b94a1f4d77 100644 --- a/usr.bin/ar/read.c +++ b/usr.bin/ar/read.c @@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$"); * Handle read modes: 'x', 't' and 'p'. */ int -ar_read_archive(struct bsdar *bsdar, int mode) +ar_read_archive(struct bsdar *bsdar, int mode, FILE *out) { struct archive *a; struct archive_entry *entry; @@ -123,18 +123,18 @@ ar_read_archive(struct bsdar *bsdar, int mode) size = archive_entry_size(entry); mtime = archive_entry_mtime(entry); (void)strmode(md, buf); - (void)fprintf(stdout, "%s %6d/%-6d %8ju ", + (void)fprintf(out, "%s %6d/%-6d %8ju ", buf + 1, uid, gid, (uintmax_t)size); tp = localtime(&mtime); (void)strftime(buf, sizeof(buf), "%b %e %H:%M %Y", tp); - (void)fprintf(stdout, "%s %s", buf, name); + (void)fprintf(out, "%s %s", buf, name); } else - (void)fprintf(stdout, "%s", name); + (void)fprintf(out, "%s", name); r = archive_read_data_skip(a); if (r == ARCHIVE_WARN || r == ARCHIVE_RETRY || r == ARCHIVE_FATAL) { - (void)fprintf(stdout, "\n"); + (void)fprintf(out, "\n"); bsdar_warnc(bsdar, archive_errno(a), "%s", archive_error_string(a)); } @@ -142,14 +142,14 @@ ar_read_archive(struct bsdar *bsdar, int mode) if (r == ARCHIVE_FATAL) break; - (void)fprintf(stdout, "\n"); + (void)fprintf(out, "\n"); } else { /* mode == 'x' || mode = 'p' */ if (mode == 'p') { if (bsdar->options & AR_V) { - (void)fprintf(stdout, "\n<%s>\n\n", + (void)fprintf(out, "\n<%s>\n\n", name); - fflush(stdout); + fflush(out); } r = archive_read_data_into_fd(a, 1); } else { @@ -172,7 +172,7 @@ ar_read_archive(struct bsdar *bsdar, int mode) } if (bsdar->options & AR_V) - (void)fprintf(stdout, "x - %s\n", name); + (void)fprintf(out, "x - %s\n", name); /* Disallow absolute paths. */ if (name[0] == '/') { bsdar_warnc(bsdar, 0,