diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index 0c086b8adf..67bfb45193 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -453,12 +453,24 @@ int make_filesystem( if (sector_size > 0) { if (strv_extend(&env, "MKE2FS_DEVICE_SECTSIZE") < 0) - return log_oom(); + return log_oom(); if (strv_extendf(&env, "%"PRIu64, sector_size) < 0) return log_oom(); } + /* e2fsprogs supports $SOURCE_DATE_EPOCH since v1.47.1. For older versions, we need to set + * $E2FSPROGS_FAKE_TIME. See the following: + * https://github.com/tytso/e2fsprogs/commit/b6e2913061577ad981464e435026d71a48fd5caf + * Note, $E2FSPROGS_FAKE_TIME and $SOURCE_DATE_EPOCH are mostly equivalent, except for the + * 0 value handling, where $E2FSPROGS_FAKE_TIME=0 is ignored and the current time is used, + * but $SOURCE_DATE_EPOCH=0 sets 1970-01-01 as the timestamp. */ + if (!secure_getenv("E2FSPROGS_FAKE_TIME")) { /* honor $E2FSPROGS_FAKE_TIME if already set */ + const char *e = secure_getenv("SOURCE_DATE_EPOCH"); + if (e && strv_extend_strv(&env, STRV_MAKE("E2FSPROGS_FAKE_TIME", e), /* filter_duplicates= */ false) < 0) + return log_oom(); + } + } else if (streq(fstype, "btrfs")) { argv = strv_new(mkfs, "-L", label, diff --git a/test/units/TEST-58-REPART.sh b/test/units/TEST-58-REPART.sh index bc0ee9f0c6..23548d9cea 100755 --- a/test/units/TEST-58-REPART.sh +++ b/test/units/TEST-58-REPART.sh @@ -1896,7 +1896,7 @@ testcase_luks2_integrity() { } testcase_ext_reproducibility() { - local defs imgs + local defs imgs ts # Online mode mounts the filesystem which updates inode timestamps non-deterministically if [[ "$OFFLINE" != "yes" ]]; then @@ -1916,21 +1916,28 @@ Format=ext4 EOF # Build the image twice with the same seed and verify they are identical - systemd-repart --offline="$OFFLINE" \ - --definitions="$defs" \ - --empty=create \ - --size=50M \ - --seed="$seed" \ - --dry-run=no \ - "$imgs/test1.img" + ts=$(date +%s) + env SOURCE_DATE_EPOCH="$ts" \ + systemd-repart \ + --offline="$OFFLINE" \ + --definitions="$defs" \ + --empty=create \ + --size=50M \ + --seed="$seed" \ + --dry-run=no \ + "$imgs/test1.img" - systemd-repart --offline="$OFFLINE" \ - --definitions="$defs" \ - --empty=create \ - --size=50M \ - --seed="$seed" \ - --dry-run=no \ - "$imgs/test2.img" + sleep 2 + + env SOURCE_DATE_EPOCH="$ts" \ + systemd-repart \ + --offline="$OFFLINE" \ + --definitions="$defs" \ + --empty=create \ + --size=50M \ + --seed="$seed" \ + --dry-run=no \ + "$imgs/test2.img" cmp "$imgs/test1.img" "$imgs/test2.img" }