sbsv2/raptor/util/talon/talon.c
branchfix
changeset 282 99ac65572b14
parent 255 9a33b42b14b0
child 283 a5284ec02d61
equal deleted inserted replaced
281:6125450a72c5 282:99ac65572b14
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
       
    19 #ifdef HAS_WINSOCK2
       
    20 #include <winsock2.h>
       
    21 #include <ws2tcpip.h>
       
    22 #define WIN32_LEAN_AND_MEAN
       
    23 #endif
    19 
    24 
    20 
    25 
    21 #include <stdlib.h>
    26 #include <stdlib.h>
    22 #include <unistd.h>
    27 #include <unistd.h>
    23 #include <string.h>
    28 #include <string.h>
    46 
    51 
    47 #define TALONDELIMITER '|'
    52 #define TALONDELIMITER '|'
    48 #define VARNAMEMAX 100
    53 #define VARNAMEMAX 100
    49 #define VARVALMAX 1024
    54 #define VARVALMAX 1024
    50 
    55 
       
    56 #define HOSTNAME_MAX 100
       
    57 
    51 
    58 
    52 #include "log.h"
    59 #include "log.h"
    53 
    60 
    54 #ifdef HAS_MSVCRT
    61 #ifdef HAS_MSVCRT
    55 /* Make all output handling binary */
    62 /* Make all output handling binary */
    56 unsigned int _CRT_fmode = _O_BINARY;
    63 unsigned int _CRT_fmode = _O_BINARY;
    57 #endif
    64 #endif
       
    65 
    58 
    66 
    59 double getseconds(void)
    67 double getseconds(void)
    60 {
    68 {
    61 	struct timeval tp;
    69 	struct timeval tp;
    62 	gettimeofday(&tp, NULL);
    70 	gettimeofday(&tp, NULL);
   231 	/* find the argument to -c then strip the talon related front section */
   239 	/* find the argument to -c then strip the talon related front section */
   232 
   240 
   233 	char *recipe = NULL;
   241 	char *recipe = NULL;
   234 	int talon_returncode = 0;
   242 	int talon_returncode = 0;
   235 
   243 
       
   244 #ifdef HAS_WINSOCK2
       
   245 	WSADATA wsaData;
       
   246 
       
   247 	int wsaresult;
       
   248 
       
   249 	wsaresult = WSAStartup(MAKEWORD(2,2), &wsaData);
       
   250 
       
   251 	/* We ignore the result as we are only doing this to use gethostname
       
   252 	   and if that fails then leaving the host atrtibute blank is perfectly
       
   253 	   acceptable.
       
   254 	*/
       
   255 
       
   256 #endif
       
   257 
   236 #ifdef HAS_GETCOMMANDLINE
   258 #ifdef HAS_GETCOMMANDLINE
   237 	char *commandline= GetCommandLine();
   259 	char *commandline= GetCommandLine();
   238 	/*
   260 	/*
   239 	 * The command line should be either,
   261 	 * The command line should be either,
   240 	 * talon -c "some shell commands"
   262 	 * talon -c "some shell commands"
   318 	}
   340 	}
   319 
   341 
   320 	/* remove any leading white space on the recipe */
   342 	/* remove any leading white space on the recipe */
   321 	while (isspace(*recipe))
   343 	while (isspace(*recipe))
   322 		recipe++;
   344 		recipe++;
       
   345 
       
   346 
       
   347 	/* Make sure that the agent's hostname can be put into the host attribute */
       
   348 	char hostname[HOSTNAME_MAX];
       
   349 
       
   350 	if (0 != gethostname(hostname, HOSTNAME_MAX-1))
       
   351 	{
       
   352 		hostname[0] = '\0';
       
   353 	}
       
   354 
       
   355 	talon_setenv("HOSTNAME", hostname);
       
   356 
   323 
   357 
   324 	/* turn debugging on? */
   358 	/* turn debugging on? */
   325 	char *debugstr=talon_getenv("TALON_DEBUG");
   359 	char *debugstr=talon_getenv("TALON_DEBUG");
   326 
   360 
   327 	if (debugstr)
   361 	if (debugstr)