sbsv2/raptor/util/talon/talon.c
branchfix
changeset 282 99ac65572b14
parent 255 9a33b42b14b0
child 283 a5284ec02d61
--- 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");