From nobody Tue Jul 29 12:49:10 2025 X-Original-To: dev-commits-src-all@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 4brwCB6xQBz62xMy; Tue, 29 Jul 2025 12:49:10 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4brwCB4wTNz3lbY; Tue, 29 Jul 2025 12:49:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753793350; 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=D8/zqK77CRaXsNb5RbqE1nhpJEHTnetrlkiNmcnNf4g=; b=cXlmxDwI9/7v+DPCrMFpoN24ZA+0ciDC8ywjUln8cVFySuB/DZugiEm7LdmBLOj1g7Flw/ iANnLhx3+wXeT99xVXLpneW8lPZ1Yxw5WyZR+hmfyhFG0ow5/IJ7fJM5hRI5xAu/81eyLa /qpwOBM9Mh/bt7ADuvwQOX59AvNteUgbT6KRm5weWGg9keHrWl2a8I+uzvrVxHkHyNZGUp +EElPj962Kv68DOhVQvpnEL0WrS71X04aXZcWkoKrweT03qzGqQ8Xfz2H84C0IUjd8rXS7 PE+UdMGAhc3lOFp+A5p/UckHhyffKEXPHRQodPJODEbQdVnd8n/b8i1bkG6MBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753793350; 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=D8/zqK77CRaXsNb5RbqE1nhpJEHTnetrlkiNmcnNf4g=; b=KTIqOc5WIpaQTJKpe1PaRWu05/4BopTtUF3NN/wB39BmsAfN8vAvrqETAE/d3kAxV+nMMX ITRTrL6Z0jh2Nz9qFHqHeacNlBRVhwZcOOhaYA2PBA4z7lAaFSHu/2izsrUcvP9LvVyAan qvY5q5PrgUHddCmG3SAxXjYMjJoRuJzEzeyqOFvtGzNujXMw8QuQAbIH6MKJEwpKwA4MVp XtBQ/R1UfCIK8p0ajhUB7k6sUO9TtZx48miQNjS+x6dLhZuM2v+EkvOH1mwfJ/BN7P3NFO 0bbQ1p4tznBvgHNZkp4eYIDKTJnkSQeUkukTAFmLIGUAVV3kXTtk+EtdfQB2yw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753793350; a=rsa-sha256; cv=none; b=KnJpk5xZE25OSWXDBRBEhNZ7Jt0W8EUmpUQGPxWeTzrP6IB2+6ulK3S1PlL7yE1yKFBP27 q1jqrORE1upq1OqaiXRk4+WJ6YzAsDjdrYP1045YU3EN1uCZ1jsCNHIwU2ITvWmUm2omt5 Xmu41f1RHakN925DxajWOstx9ON0m44+gavLqVaFgLBgGCCcIJrsrKE7w+JZrv7eu2lFYS vPNv9tGFgR6CXtJMK13mddRqgUtRdmZnotTMIdESrlfXxnJeaYQP4b30hj3ASni87BdoTz MvGlxbkyjHs+QQ5v+nq02C3Ha1hZ4ysOYVxbwTYV90cQFw9dRrEHMd9LOCmusQ== 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 4brwCB4XGBzXZd; Tue, 29 Jul 2025 12:49:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56TCnAxZ033567; Tue, 29 Jul 2025 12:49:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56TCnAur033564; Tue, 29 Jul 2025 12:49:10 GMT (envelope-from git) Date: Tue, 29 Jul 2025 12:49:10 GMT Message-Id: <202507291249.56TCnAur033564@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f6ed43d346b1 - stable/14 - mkimg: Make output reproducible using a specific timestamp List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: f6ed43d346b1a79f62e33e3a3fe001d3fc5bcbde Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f6ed43d346b1a79f62e33e3a3fe001d3fc5bcbde commit f6ed43d346b1a79f62e33e3a3fe001d3fc5bcbde Author: Mark Johnston AuthorDate: 2025-07-07 20:27:24 +0000 Commit: Mark Johnston CommitDate: 2025-07-29 12:08:32 +0000 mkimg: Make output reproducible using a specific timestamp In commit 95ac5b0e27e9 ("mkimg: Add a reproducible mode"), I added a -R flag to mkimg, indicating that output should be reproducible. There is one place in the VHD image backend that uses time(3) to populate an image metadata field; this field is visible to tools which know how to process VHD images. Rather than picking an arbitrary value for that timestamp, it seems better to behave like makefs(8) and let the invoker pick a suitable timestamp. So, remove -R and instead add a -t option which lets the timestamp be specified directly. Then, modify the VHD backend to use that timestamp. Fixes: 95ac5b0e27e9 ("mkimg: Add a reproducible mode") Reviewed by: bnovkov MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D51077 (cherry picked from commit 393fefa3d9c78948d911e5de0182a9b858b23475) --- usr.bin/mkimg/mkimg.1 | 8 ++++---- usr.bin/mkimg/mkimg.c | 24 ++++++++++++++++-------- usr.bin/mkimg/mkimg.h | 4 ++-- usr.bin/mkimg/uuid.c | 7 ++++--- usr.bin/mkimg/vhd.c | 2 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1 index f6b151d2d5c7..ae48904eb16c 100644 --- a/usr.bin/mkimg/mkimg.1 +++ b/usr.bin/mkimg/mkimg.1 @@ -41,7 +41,7 @@ .Op Fl f Ar format .Op Fl o Ar outfile .Op Fl a Ar active -.Op Fl R +.Op Fl t Ar timestamp .Op Fl v .Op Fl y .Op Fl s Ar scheme Op Fl p Ar partition ... @@ -139,9 +139,9 @@ option is a shorthand to specify the minimum and maximum capacity at the same time. .Pp The -.Fl R -option enables reproducible mode: any timestamps or random identifiers will -be fixed so as to ensure consistent output. +.Fl t +option causes any timestamps embedded in the output file to be set to the +given time, specified in seconds since the epoch. .Pp The .Fl v diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c index 58bf90fd5ad4..80c79777575e 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -62,7 +62,8 @@ static struct option longopts[] = { static uint64_t min_capacity = 0; static uint64_t max_capacity = 0; -bool reproducible = false; +/* Fixed timestamp for reproducible builds. */ +time_t timestamp = (time_t)-1; struct partlisthead partlist = TAILQ_HEAD_INITIALIZER(partlist); u_int nparts = 0; @@ -564,7 +565,7 @@ main(int argc, char *argv[]) bcfd = -1; outfd = 1; /* Write to stdout by default */ - while ((c = getopt_long(argc, argv, "a:b:c:C:f:o:p:s:vyH:P:RS:T:", + while ((c = getopt_long(argc, argv, "a:b:c:C:f:o:p:s:t:vyH:P:S:T:", longopts, NULL)) != -1) { switch (c) { case 'a': /* ACTIVE PARTITION, if supported */ @@ -609,9 +610,6 @@ main(int argc, char *argv[]) if (error) errc(EX_DATAERR, error, "partition"); break; - case 'R': - reproducible = true; - break; case 's': /* SCHEME */ if (scheme_selected() != NULL) usage("multiple schemes given"); @@ -619,6 +617,19 @@ main(int argc, char *argv[]) if (error) errc(EX_DATAERR, error, "scheme"); break; + case 't': { + char *ep; + long long val; + + errno = 0; + val = strtoll(optarg, &ep, 0); + if (ep == optarg || *ep != '\0') + errno = EINVAL; + if (errno != 0) + errc(EX_DATAERR, errno, "timestamp"); + timestamp = (time_t)val; + break; + } case 'y': unit_testing++; break; @@ -681,9 +692,6 @@ main(int argc, char *argv[]) if (max_capacity != 0 && min_capacity > max_capacity) usage("minimum capacity cannot be larger than the maximum one"); - if (reproducible) - srandom(42); - if (secsz > blksz) { if (blksz != 0) errx(EX_DATAERR, "the physical block size cannot " diff --git a/usr.bin/mkimg/mkimg.h b/usr.bin/mkimg/mkimg.h index 608de458e83c..aa0ec2a8d944 100644 --- a/usr.bin/mkimg/mkimg.h +++ b/usr.bin/mkimg/mkimg.h @@ -29,9 +29,9 @@ #include #include -#include +#include -extern bool reproducible; /* Generate reproducible output. */ +extern time_t timestamp; struct part { TAILQ_ENTRY(part) link; diff --git a/usr.bin/mkimg/uuid.c b/usr.bin/mkimg/uuid.c index f3415a8c1111..885a6c36b522 100644 --- a/usr.bin/mkimg/uuid.c +++ b/usr.bin/mkimg/uuid.c @@ -57,9 +57,10 @@ osdep_uuidgen(mkimg_uuid_t *uuid) u_int i; uint16_t seq; - if (reproducible) - memset(&tv, 0, sizeof(tv)); - else if (gettimeofday(&tv, NULL) == -1) + if (timestamp != (time_t)-1) { + tv.tv_sec = timestamp; + tv.tv_usec = 0; + } else if (gettimeofday(&tv, NULL) == -1) abort(); time += (uint64_t)tv.tv_sec * 10000000LL; diff --git a/usr.bin/mkimg/vhd.c b/usr.bin/mkimg/vhd.c index 1e1f1e7f3c3e..c0fe45ab416e 100644 --- a/usr.bin/mkimg/vhd.c +++ b/usr.bin/mkimg/vhd.c @@ -188,7 +188,7 @@ vhd_timestamp(void) time_t t; if (!unit_testing) { - t = time(NULL); + t = timestamp != (time_t)-1 ? timestamp : time(NULL); return (t - 0x386d4380); }