From 22588250baa1bfa5c00f57d39329d0c144fc8112 Mon Sep 17 00:00:00 2001
From: Florian Festi <ffesti@redhat.com>
Date: Thu, 2 Jun 2016 15:54:01 +0200
Subject: [PATCH] Add support for _buildhost macro for setting the build host
manually.
This is useful for reproducible builds. See rhbz#1309367.
---
build/pack.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/build/pack.c b/build/pack.c
index f9fb3a0..82c1262 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -179,16 +179,25 @@ static const char * buildHost(void)
static char hostname[1024];
static int oneshot = 0;
struct hostent *hbn;
+ char *bhMacro;
if (! oneshot) {
- (void) gethostname(hostname, sizeof(hostname));
- hbn = gethostbyname(hostname);
- if (hbn)
- strcpy(hostname, hbn->h_name);
- else
- rpmlog(RPMLOG_WARNING,
- _("Could not canonicalize hostname: %s\n"), hostname);
- oneshot = 1;
+ bhMacro = rpmExpand("%{?_buildhost}", NULL);
+ if (strcmp(bhMacro, "") != 0 && strlen(bhMacro) < 1024) {
+ strcpy(hostname, bhMacro);
+ } else {
+ if (strcmp(bhMacro, "") != 0)
+ rpmlog(RPMLOG_WARNING, _("The _buildhost macro is too long\n"));
+ (void) gethostname(hostname, sizeof(hostname));
+ hbn = gethostbyname(hostname);
+ if (hbn)
+ strcpy(hostname, hbn->h_name);
+ else
+ rpmlog(RPMLOG_WARNING,
+ _("Could not canonicalize hostname: %s\n"), hostname);
+ }
+ free(bhMacro);
+ oneshot = 1;
}
return(hostname);
}
--
2.5.5