fix: use gethostname() to set host attribute as this works on a cluster whereas reading the COMPUTERNAME env var doesn't. fix
authortimothy.murphy@nokia.com
Sun, 28 Feb 2010 22:37:15 +0000
branchfix
changeset 282 99ac65572b14
parent 281 6125450a72c5
child 283 a5284ec02d61
fix: use gethostname() to set host attribute as this works on a cluster whereas reading the COMPUTERNAME env var doesn't.
sbsv2/raptor/lib/flm/taggedrules.mk
sbsv2/raptor/util/config.h
sbsv2/raptor/util/gccprogram.mk
sbsv2/raptor/util/talon/Makefile
sbsv2/raptor/util/talon/talon.c
sbsv2/raptor/win32/bin/talon.exe
--- a/sbsv2/raptor/lib/flm/taggedrules.mk	Sun Feb 28 23:17:56 2010 +0200
+++ b/sbsv2/raptor/lib/flm/taggedrules.mk	Sun Feb 28 22:37:15 2010 +0000
@@ -100,11 +100,7 @@
 
 else
 
-  ifneq ($(filter win,$(HOSTPLATFORM)),)
-    TALON_HOSTNAME_VAR:=$$COMPUTERNAME
-  else
-    TALON_HOSTNAME_VAR:=$$HOSTNAME
-  endif
+TALON_HOSTNAME_VAR:=$$HOSTNAME
 
 TALON_RECIPEATTRIBUTES:=\
  name='$$RECIPE'\
--- a/sbsv2/raptor/util/config.h	Sun Feb 28 23:17:56 2010 +0200
+++ b/sbsv2/raptor/util/config.h	Sun Feb 28 22:37:15 2010 +0000
@@ -21,6 +21,7 @@
 #define HAS_GETCOMMANDLINE 1
 #define HAS_MILLISECONDSLEEP 1
 #define HAS_MSVCRT 1
+#define HAS_WINSOCK2 1
 #else
 #define HAS_POLL 1
 #define HAS_SETENV 1
--- a/sbsv2/raptor/util/gccprogram.mk	Sun Feb 28 23:17:56 2010 +0200
+++ b/sbsv2/raptor/util/gccprogram.mk	Sun Feb 28 22:37:15 2010 +0000
@@ -62,7 +62,7 @@
 $(foreach SOURCEFILE,$(SOURCES),$(c2obj))
 
 $(BINDIR)/$(TARGET)$(PROGRAMEXT): $$(OBJECTS)
-	gcc $(LDFLAGS) $$^ -o $$@
+	gcc  $$^ $(LDFLAGS)  -o $$@
 	
 $$(shell mkdir -p $(OUTPUTPATH)/$(TARGET))
 
--- a/sbsv2/raptor/util/talon/Makefile	Sun Feb 28 23:17:56 2010 +0200
+++ b/sbsv2/raptor/util/talon/Makefile	Sun Feb 28 22:37:15 2010 +0000
@@ -29,6 +29,7 @@
 else
 LDFLAGS:=$(subst \,/,$(SBS_MINGW:\=/)\lib\libiberty.a)
 endif
+LDFLAGS:=$(LDFLAGS) -Wl,-lws2_32
 else
 CHOMP_C:=
 PROCESS_C:=process.c
--- a/sbsv2/raptor/util/talon/talon.c	Sun Feb 28 23:17:56 2010 +0200
+++ b/sbsv2/raptor/util/talon/talon.c	Sun Feb 28 22:37:15 2010 +0000
@@ -16,6 +16,11 @@
 */
 
 
+#ifdef HAS_WINSOCK2
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#define WIN32_LEAN_AND_MEAN
+#endif
 
 
 #include <stdlib.h>
@@ -48,6 +53,8 @@
 #define VARNAMEMAX 100
 #define VARVALMAX 1024
 
+#define HOSTNAME_MAX 100
+
 
 #include "log.h"
 
@@ -56,6 +63,7 @@
 unsigned int _CRT_fmode = _O_BINARY;
 #endif
 
+
 double getseconds(void)
 {
 	struct timeval tp;
@@ -233,6 +241,20 @@
 	char *recipe = NULL;
 	int talon_returncode = 0;
 
+#ifdef HAS_WINSOCK2
+	WSADATA wsaData;
+
+	int wsaresult;
+
+	wsaresult = WSAStartup(MAKEWORD(2,2), &wsaData);
+
+	/* We ignore the result as we are only doing this to use gethostname
+	   and if that fails then leaving the host atrtibute blank is perfectly
+	   acceptable.
+	*/
+
+#endif
+
 #ifdef HAS_GETCOMMANDLINE
 	char *commandline= GetCommandLine();
 	/*
@@ -321,6 +343,18 @@
 	while (isspace(*recipe))
 		recipe++;
 
+
+	/* Make sure that the agent's hostname can be put into the host attribute */
+	char hostname[HOSTNAME_MAX];
+
+	if (0 != gethostname(hostname, HOSTNAME_MAX-1))
+	{
+		hostname[0] = '\0';
+	}
+
+	talon_setenv("HOSTNAME", hostname);
+
+
 	/* turn debugging on? */
 	char *debugstr=talon_getenv("TALON_DEBUG");
 
Binary file sbsv2/raptor/win32/bin/talon.exe has changed