[Rpm-maint] [PATCH 1/2] Use the _buildhost macro as buildhost if defined

Nicolas Vigier boklm at mars-attacks.org
Wed Sep 25 10:20:08 UTC 2013


---
 build/pack.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/build/pack.c b/build/pack.c
index 40bf9dc..3be9a30 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -120,16 +120,23 @@ 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 {
+            (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);
 }
-- 
1.8.1.5



More information about the Rpm-maint mailing list