mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Merge branch 'ondrej/reproducible-build' into 'master'
Make lib/dns/gen.c compatible with reproducible builds. See merge request isc-projects/bind9!1758
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include "gen-win32.h"
|
||||
@@ -533,7 +535,6 @@ main(int argc, char **argv) {
|
||||
struct cc *cc;
|
||||
struct ttnam *ttn, *ttn2;
|
||||
unsigned int hash;
|
||||
struct tm *tm;
|
||||
time_t now;
|
||||
char year[11];
|
||||
int lasttype;
|
||||
@@ -549,6 +550,9 @@ main(int argc, char **argv) {
|
||||
char *prefix = NULL;
|
||||
char *suffix = NULL;
|
||||
char *file = NULL;
|
||||
char *source_date_epoch;
|
||||
unsigned long long epoch;
|
||||
char *endptr;
|
||||
isc_dir_t dir;
|
||||
|
||||
for (i = 0; i < TYPENAMES; i++)
|
||||
@@ -645,8 +649,46 @@ main(int argc, char **argv) {
|
||||
INSIST(n > 0 && (unsigned)n < sizeof(srcdir));
|
||||
sd(0, "", buf, filetype);
|
||||
|
||||
if (time(&now) != -1) {
|
||||
if ((tm = localtime(&now)) != NULL && tm->tm_year > 104) {
|
||||
source_date_epoch = getenv("SOURCE_DATE_EPOCH");
|
||||
if (source_date_epoch) {
|
||||
errno = 0;
|
||||
epoch = strtoull(source_date_epoch, &endptr, 10);
|
||||
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
|
||||
|| (errno != 0 && epoch == 0)) {
|
||||
fprintf(stderr, "Environment variable "
|
||||
"$SOURCE_DATE_EPOCH: strtoull: %s\n",
|
||||
strerror(errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (endptr == source_date_epoch) {
|
||||
fprintf(stderr, "Environment variable "
|
||||
"$SOURCE_DATE_EPOCH: "
|
||||
"No digits were found: %s\n",
|
||||
endptr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (*endptr != '\0') {
|
||||
fprintf(stderr, "Environment variable "
|
||||
"$SOURCE_DATE_EPOCH: Trailing garbage: %s\n",
|
||||
endptr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (epoch > ULONG_MAX) {
|
||||
fprintf(stderr, "Environment variable "
|
||||
"$SOURCE_DATE_EPOCH: value must be "
|
||||
"smaller than or equal to: %lu but "
|
||||
"was found to be: %llu \n",
|
||||
ULONG_MAX, epoch);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
now = epoch;
|
||||
} else {
|
||||
time(&now);
|
||||
}
|
||||
|
||||
if (now != -1) {
|
||||
struct tm *tm = gmtime(&now);
|
||||
if (tm != NULL && tm->tm_year > 104) {
|
||||
n = snprintf(year, sizeof(year), "-%d",
|
||||
tm->tm_year + 1900);
|
||||
INSIST(n > 0 && (unsigned)n < sizeof(year));
|
||||
|
Reference in New Issue
Block a user