Add support for _buildhost macro for setting the build host manually.

This is useful for reproducible builds. See rhbz#1309367.
This commit is contained in:
Florian Festi 2016-06-02 15:54:01 +02:00
parent 7a7c31f551
commit 22588250ba
1 changed files with 17 additions and 8 deletions

View File

@ -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);
}