author | Richard Taylor <richard.i.taylor@nokia.com> |
Thu, 25 Feb 2010 16:02:22 +0000 | |
branch | fix |
changeset 370 | c86748d54051 |
parent 255 | 9a33b42b14b0 |
child 282 | 99ac65572b14 |
permissions | -rw-r--r-- |
3 | 1 |
/* |
240
fbc6a8ad3957
SF Bug 1861 - update log schema, fix some copyright notices
timothy.murphy@nokia.com
parents:
237
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 | 3 |
* All rights reserved. |
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
||
21 |
#include <stdlib.h> |
|
22 |
#include <unistd.h> |
|
23 |
#include <string.h> |
|
24 |
#include <stdio.h> |
|
25 |
||
26 |
#include <sys/types.h> |
|
27 |
#include <sys/stat.h> |
|
28 |
#include <fcntl.h> |
|
29 |
#include <stdarg.h> |
|
30 |
||
31 |
#include "talon_process.h" |
|
32 |
#include "sema.h" |
|
33 |
#include "buffer.h" |
|
34 |
#include "../config.h" |
|
35 |
||
252
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
251
diff
changeset
|
36 |
#ifdef HAS_GETCOMMANDLINE |
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
251
diff
changeset
|
37 |
#include "chomp.h" |
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
251
diff
changeset
|
38 |
#endif |
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
251
diff
changeset
|
39 |
|
3 | 40 |
/* The output semaphore. */ |
41 |
sbs_semaphore talon_sem; |
|
42 |
||
43 |
#define TALON_ATTEMPT_STRMAX 32 |
|
44 |
#define RECIPETAG_STRMAX 2048 |
|
237
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
45 |
#define STATUS_STRMAX 120 |
3 | 46 |
|
47 |
#define TALONDELIMITER '|' |
|
48 |
#define VARNAMEMAX 100 |
|
49 |
#define VARVALMAX 1024 |
|
50 |
||
51 |
||
52 |
#include "log.h" |
|
53 |
||
54 |
#ifdef HAS_MSVCRT |
|
55 |
/* Make all output handling binary */ |
|
56 |
unsigned int _CRT_fmode = _O_BINARY; |
|
57 |
#endif |
|
58 |
||
59 |
double getseconds(void) |
|
60 |
{ |
|
61 |
struct timeval tp; |
|
62 |
gettimeofday(&tp, NULL); |
|
63 |
||
64 |
return (double)tp.tv_sec + ((double)tp.tv_usec)/1000000.0L; |
|
65 |
} |
|
66 |
||
67 |
void talon_setenv(char name[], char val[]) |
|
68 |
{ |
|
69 |
#if defined(HAS_GETENVIRONMENTVARIABLE) |
|
70 |
SetEnvironmentVariableA(name,val); |
|
71 |
#elif defined(HAS_GETENV) |
|
72 |
setenv(name,val, 1); |
|
73 |
#else |
|
74 |
# error "Need a function for setting environment variables" |
|
75 |
#endif |
|
76 |
} |
|
77 |
||
78 |
||
79 |
#define TALON_MAXENV 4096 |
|
80 |
char * talon_getenv(char name[]) |
|
81 |
{ |
|
82 |
#if defined(HAS_SETENV) |
|
83 |
char *val = getenv(name); |
|
84 |
char *dest = NULL; |
|
85 |
||
86 |
if (val) |
|
87 |
{ |
|
88 |
dest = malloc(strlen(val) + 1); |
|
89 |
if (dest) |
|
90 |
{ |
|
91 |
strcpy(dest,val); |
|
92 |
} |
|
93 |
} |
|
94 |
return dest; |
|
95 |
#elif defined(HAS_SETENVIRONMENTVARIABLE) |
|
96 |
char *val = malloc(TALON_MAXENV); |
|
97 |
if (0 != GetEnvironmentVariableA(name,val,TALON_MAXENV-1)) |
|
98 |
return val; |
|
99 |
else |
|
100 |
return NULL; |
|
101 |
#else |
|
102 |
# error "Need a function for setting environment variables" |
|
103 |
#endif |
|
104 |
} |
|
105 |
||
106 |
void prependattributes(buffer *b, char *attributes) |
|
107 |
{ |
|
108 |
char recipetag[RECIPETAG_STRMAX]; |
|
109 |
char *rt; |
|
110 |
char envvarname[VARNAMEMAX]; |
|
111 |
char *att; |
|
112 |
||
113 |
||
114 |
strcpy(recipetag, "<recipe "); |
|
115 |
rt = recipetag + 8; |
|
116 |
||
117 |
att = attributes; |
|
118 |
while (*att != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1]) |
|
119 |
{ |
|
120 |
if ( *att == '$' ) |
|
121 |
{ |
|
122 |
int e; |
|
123 |
char *v; |
|
124 |
/* insert the value of an environent variable */ |
|
125 |
att++; |
|
126 |
e = 0; |
|
127 |
do { |
|
128 |
envvarname[e++] = *att; |
|
129 |
att++; |
|
130 |
} while ( e < (VARNAMEMAX-1) && (isalnum(*att) || *att == '_')); |
|
131 |
envvarname[e] = '\0'; |
|
132 |
/* DEBUG(("envvarname: %s\n", envvarname)); */ |
|
133 |
v = talon_getenv(envvarname); |
|
134 |
if (v) |
|
135 |
{ |
|
136 |
/* DEBUG((" value: %s\n", v)); */ |
|
137 |
char *oldv=v; |
|
138 |
while (*v != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1]) |
|
139 |
{ |
|
140 |
*rt = *v; |
|
141 |
rt++; v++; |
|
142 |
} |
|
143 |
free(oldv); |
|
144 |
} |
|
145 |
} else { |
|
146 |
*rt = *att; |
|
147 |
rt++; att++; |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
char *finish = ">\n<![CDATA[\n"; |
|
152 |
||
153 |
while (*finish != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1]) |
|
154 |
{ |
|
155 |
*rt = *finish; |
|
156 |
*rt++; finish++; |
|
157 |
} |
|
158 |
||
159 |
*rt = '\0'; |
|
160 |
||
161 |
buffer_prepend(b, recipetag, strlen(recipetag)); |
|
162 |
} |
|
163 |
||
164 |
/* read a recipe string from a temporary file. |
|
165 |
* |
|
166 |
* We only expect to do this for very long command lines on |
|
167 |
* Windows. So allocate the maximum size for CreateProcess on |
|
168 |
* Win32 (32768 bytes) and error if the file is longer than that. |
|
169 |
* |
|
170 |
*/ |
|
171 |
char *read_recipe_from_file(const char *filename) |
|
172 |
{ |
|
173 |
FILE *fp = fopen(filename, "r"); |
|
174 |
||
175 |
if (!fp) |
|
176 |
{ |
|
177 |
error("talon: error: could not read '%s'\n", filename); |
|
178 |
return NULL; |
|
179 |
} |
|
180 |
||
181 |
int max_length = 32768; |
|
182 |
char *recipe = (char*)malloc(max_length); |
|
183 |
||
184 |
if (!recipe) |
|
185 |
{ |
|
186 |
error("talon: error: could not allocate memory to read '%s'\n", filename); |
|
187 |
return NULL; |
|
188 |
} |
|
189 |
int position = 0; |
|
190 |
||
191 |
/* read the file one character at a time */ |
|
192 |
int c; |
|
193 |
while ((c = getc(fp)) != EOF) |
|
194 |
{ |
|
195 |
switch (c) |
|
196 |
{ |
|
197 |
case '\r': |
|
198 |
case '\n': |
|
199 |
/* ignore newlines */ |
|
200 |
break; |
|
201 |
||
202 |
case '"': |
|
203 |
/* double quotes have to be escaped so they aren't lost later */ |
|
204 |
if (position < max_length) |
|
205 |
recipe[position++] = '\\'; |
|
206 |
if (position < max_length) |
|
207 |
recipe[position++] = c; |
|
208 |
break; |
|
209 |
||
210 |
default: |
|
211 |
if (position < max_length) |
|
212 |
recipe[position++] = c; |
|
213 |
break; |
|
214 |
} |
|
215 |
} |
|
216 |
fclose(fp); |
|
217 |
||
218 |
/* add a terminating \0 */ |
|
219 |
if (position < max_length) |
|
220 |
recipe[position] = '\0'; |
|
221 |
else |
|
222 |
{ |
|
223 |
error("talon: error: command longer than 32768 in '%s'\n", filename); |
|
224 |
return NULL; |
|
225 |
} |
|
226 |
return recipe; |
|
227 |
} |
|
228 |
||
229 |
int main(int argc, char *argv[]) |
|
230 |
{ |
|
231 |
/* find the argument to -c then strip the talon related front section */ |
|
232 |
||
233 |
char *recipe = NULL; |
|
234 |
int talon_returncode = 0; |
|
235 |
||
236 |
#ifdef HAS_GETCOMMANDLINE |
|
237 |
char *commandline= GetCommandLine(); |
|
238 |
/* |
|
239 |
* The command line should be either, |
|
240 |
* talon -c "some shell commands" |
|
241 |
* or |
|
242 |
* talon shell_script_file |
|
243 |
* |
|
244 |
* talon could be an absolute path and may have a .exe extension. |
|
245 |
*/ |
|
251
64208ed747d4
SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
237
diff
changeset
|
246 |
|
64208ed747d4
SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
237
diff
changeset
|
247 |
|
64208ed747d4
SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
237
diff
changeset
|
248 |
recipe = chompCommand(commandline); |
3 | 249 |
if (recipe) |
250 |
{ |
|
251 |
/* there was a -c so extract the quoted commands */ |
|
252 |
||
253 |
int recipelen = strlen(recipe); |
|
254 |
if (recipelen > 0 && recipe[recipelen - 1] == '"') |
|
255 |
recipe[recipelen - 1] = '\0'; /* remove trailing quote */ |
|
256 |
} |
|
257 |
else |
|
258 |
{ |
|
259 |
/* there was no -c so extract the argument as a filename */ |
|
260 |
||
261 |
recipe = strstr(commandline, "talon"); |
|
262 |
if (recipe) |
|
263 |
{ |
|
264 |
/* find the first space */ |
|
265 |
while (!isspace(*recipe) && *recipe != '\0') |
|
266 |
recipe++; |
|
267 |
/* skip past the spaces */ |
|
268 |
while (isspace(*recipe)) |
|
269 |
recipe++; |
|
270 |
||
271 |
recipe = read_recipe_from_file(recipe); |
|
272 |
||
273 |
if (!recipe) |
|
274 |
{ |
|
275 |
error("talon: error: bad script file in shell call '%s'\n", commandline); |
|
276 |
return 1; |
|
277 |
} |
|
278 |
} |
|
279 |
else |
|
280 |
{ |
|
281 |
error("talon: error: no 'talon' in shell call '%s'\n", commandline); |
|
282 |
return 1; |
|
283 |
} |
|
284 |
} |
|
285 |
#else |
|
286 |
/* |
|
287 |
* The command line should be either, |
|
288 |
* talon -c "some shell commands" |
|
289 |
* or |
|
290 |
* talon shell_script_file |
|
291 |
* |
|
292 |
* talon could be an absolute path and may have a .exe extension. |
|
293 |
*/ |
|
294 |
switch (argc) |
|
295 |
{ |
|
296 |
case 2: |
|
297 |
recipe = read_recipe_from_file(argv[1]); |
|
298 |
break; |
|
299 |
case 3: |
|
300 |
if (strcmp("-c", argv[1]) != 0) |
|
301 |
{ |
|
302 |
error("talon: error: %s\n", "usage is 'talon -c command' or 'talon script_filename'"); |
|
303 |
return 1; |
|
304 |
} |
|
305 |
recipe = argv[2]; |
|
306 |
break; |
|
307 |
default: |
|
308 |
error("talon: error: %s\n", "usage is 'talon -c command' or 'talon script_filename'"); |
|
309 |
return 1; |
|
310 |
} |
|
311 |
#endif |
|
312 |
||
313 |
/* did we get a recipe at all? */ |
|
314 |
if (!recipe) |
|
315 |
{ |
|
316 |
error("talon: error: %s", "no recipe supplied to the shell.\n"); |
|
317 |
return 1; |
|
318 |
} |
|
319 |
||
320 |
/* remove any leading white space on the recipe */ |
|
321 |
while (isspace(*recipe)) |
|
322 |
recipe++; |
|
323 |
||
324 |
/* turn debugging on? */ |
|
325 |
char *debugstr=talon_getenv("TALON_DEBUG"); |
|
326 |
||
327 |
if (debugstr) |
|
328 |
{ |
|
329 |
loglevel=LOGDEBUG; |
|
330 |
free(debugstr); debugstr=NULL; |
|
331 |
} |
|
332 |
||
333 |
DEBUG(("talon: recipe: %s\n", recipe)); |
|
334 |
||
335 |
||
336 |
char varname[VARNAMEMAX]; |
|
337 |
char varval[VARVALMAX]; |
|
338 |
int dotagging = 0; |
|
339 |
int force_descramble_off = 0; |
|
340 |
||
341 |
char *rp = recipe; |
|
342 |
if (*rp == TALONDELIMITER) { |
|
343 |
dotagging = 1; |
|
344 |
||
345 |
/* there are some talon-specific settings |
|
346 |
* in the command which must be stripped */ |
|
347 |
rp++; |
|
348 |
char *out = varname; |
|
349 |
char *stopout = varname + VARNAMEMAX - 1; |
|
350 |
DEBUG(("talon: parameters found\n")); |
|
351 |
while (*rp != '\0') |
|
352 |
{ |
|
353 |
||
354 |
switch (*rp) { |
|
355 |
case '=': |
|
356 |
*out = '\0'; |
|
357 |
DEBUG(("talon: varname: %s\n",varname)); |
|
358 |
out = varval; |
|
359 |
stopout = varval + VARVALMAX - 1; |
|
360 |
break; |
|
361 |
case ';': |
|
362 |
*out = '\0'; |
|
363 |
DEBUG(("talon: varval: %s\n",varval)); |
|
364 |
talon_setenv(varname, varval); |
|
365 |
out = varname; |
|
366 |
stopout = varname + VARNAMEMAX - 1; |
|
367 |
break; |
|
368 |
default: |
|
369 |
*out = *rp; |
|
370 |
if (out < stopout) |
|
371 |
out++; |
|
372 |
break; |
|
373 |
} |
|
374 |
||
375 |
if (*rp == TALONDELIMITER) |
|
376 |
{ |
|
377 |
rp++; |
|
378 |
break; |
|
379 |
} |
|
380 |
||
381 |
rp++; |
|
382 |
} |
|
383 |
} else { |
|
384 |
/* This is probably a $(shell) statement |
|
385 |
* in make so no descrambling needed and |
|
386 |
* tags are definitely not wanted as they |
|
387 |
* would corrupt the expected output*/ |
|
388 |
force_descramble_off = 1; |
|
389 |
} |
|
390 |
||
391 |
||
392 |
/* Now take settings from the environment (having potentially modified it) */ |
|
393 |
if (talon_getenv("TALON_DEBUG")) |
|
394 |
loglevel=LOGDEBUG; |
|
395 |
||
396 |
||
397 |
int enverrors = 0; |
|
398 |
||
399 |
char *shell = talon_getenv("TALON_SHELL"); |
|
400 |
if (!shell) |
|
401 |
{ |
|
402 |
error("error: %s", "TALON_SHELL not set in environment\n"); |
|
403 |
enverrors++; |
|
404 |
} |
|
405 |
||
406 |
int timeout = -1; |
|
407 |
char *timeout_str = talon_getenv("TALON_TIMEOUT"); |
|
408 |
if (timeout_str) |
|
409 |
{ |
|
410 |
timeout = atoi(timeout_str); |
|
411 |
free(timeout_str); timeout_str = NULL; |
|
412 |
} |
|
413 |
||
414 |
char *buildid = talon_getenv("TALON_BUILDID"); |
|
415 |
if (!buildid) |
|
416 |
{ |
|
417 |
error("error: %s", "TALON_BUILDID not set in environment\n"); |
|
418 |
enverrors++; |
|
419 |
} |
|
420 |
||
421 |
char *attributes = talon_getenv("TALON_RECIPEATTRIBUTES"); |
|
422 |
if (!attributes) |
|
423 |
{ |
|
424 |
error("error: %s", "TALON_RECIPEATTRIBUTES not set in environment\n"); |
|
425 |
enverrors++; |
|
426 |
} |
|
427 |
||
428 |
||
429 |
int max_retries = 0; |
|
430 |
char *retries_str = talon_getenv("TALON_RETRIES"); |
|
431 |
if (retries_str) |
|
432 |
{ |
|
433 |
max_retries = atoi(retries_str); |
|
434 |
free(retries_str); retries_str = NULL; |
|
435 |
} |
|
436 |
||
437 |
||
438 |
int descramble = 0; |
|
439 |
if (! force_descramble_off ) |
|
440 |
{ |
|
441 |
char *descramblestr = talon_getenv("TALON_DESCRAMBLE"); |
|
442 |
if (descramblestr) |
|
443 |
{ |
|
444 |
if (*descramblestr == '0') |
|
445 |
descramble = 0; |
|
446 |
else |
|
447 |
descramble = 1; |
|
448 |
||
449 |
free(descramblestr); descramblestr = NULL; |
|
450 |
} |
|
451 |
} |
|
452 |
||
453 |
||
454 |
||
455 |
/* Talon can look in a flags variable to alter it's behaviour */ |
|
456 |
int force_success = 0; |
|
457 |
char *flags_str = talon_getenv("TALON_FLAGS"); |
|
458 |
if (flags_str) |
|
459 |
{ |
|
460 |
int c; |
|
461 |
for (c=0; flags_str[c] !=0; c++) |
|
462 |
flags_str[c] = tolower(flags_str[c]); |
|
463 |
||
464 |
if (strstr(flags_str, "forcesuccess")) |
|
465 |
force_success = 1; |
|
466 |
||
467 |
/* don't put <recipe> or <CDATA<[[ tags around the output. e.g. if it's XML already*/ |
|
468 |
if (strstr(flags_str, "rawoutput")) |
|
469 |
{ |
|
470 |
dotagging = 0; |
|
471 |
} |
|
472 |
||
473 |
free(flags_str); flags_str = NULL; |
|
474 |
} |
|
475 |
||
476 |
/* Talon subprocesses need to have the "correct" shell variable set. */ |
|
477 |
talon_setenv("SHELL", shell); |
|
478 |
||
479 |
/* we have allowed some errors to build up so that the user |
|
480 |
* can see all of them before we stop and force the user |
|
481 |
* to fix them |
|
482 |
*/ |
|
483 |
if (enverrors) |
|
484 |
{ |
|
485 |
return 1; |
|
486 |
} |
|
487 |
||
488 |
||
489 |
/* Run the recipe repeatedly until the retry count expires or |
|
490 |
* it succeeds. |
|
491 |
*/ |
|
492 |
int attempt = 0, retries = max_retries; |
|
493 |
proc *p = NULL; |
|
494 |
||
495 |
char *args[5]; |
|
496 |
||
497 |
char *qrp=rp; |
|
498 |
||
499 |
#ifdef HAS_GETCOMMANDLINE |
|
500 |
/* re-quote the argument to -c since this helps windows deal with it */ |
|
501 |
int qrpsize = strlen(rp) + 3; |
|
502 |
qrp = malloc(qrpsize); |
|
503 |
qrp[0] = '"'; |
|
504 |
strcpy(&qrp[1], rp); |
|
505 |
qrp[qrpsize-2] = '"'; |
|
506 |
qrp[qrpsize-1] = '\0'; |
|
507 |
#endif |
|
508 |
||
509 |
int index = 0; |
|
510 |
args[index++] = shell; |
|
511 |
||
512 |
if (dotagging) /* don't do bash -x for non-tagged commands e.g. $(shell output) */ |
|
513 |
args[index++] = "-x"; |
|
514 |
||
515 |
args[index++] = "-c"; |
|
516 |
args[index++] = qrp; |
|
517 |
args[index++] = NULL; |
|
518 |
||
519 |
/* get the semaphore ready */ |
|
520 |
talon_sem.name = buildid; |
|
521 |
talon_sem.timeout = timeout; |
|
522 |
do |
|
523 |
{ |
|
524 |
char talon_attempt[TALON_ATTEMPT_STRMAX]; |
|
525 |
double start_time = getseconds(); |
|
526 |
||
527 |
attempt++; |
|
528 |
||
529 |
snprintf(talon_attempt, TALON_ATTEMPT_STRMAX-1, "%d", attempt); |
|
530 |
talon_attempt[TALON_ATTEMPT_STRMAX - 1] = '\0'; |
|
531 |
||
532 |
talon_setenv("TALON_ATTEMPT", talon_attempt); |
|
533 |
||
534 |
p = process_run(shell, args, timeout); |
|
535 |
||
536 |
double end_time = getseconds(); |
|
537 |
||
538 |
if (p) |
|
539 |
{ |
|
540 |
char status[STATUS_STRMAX]; |
|
541 |
char timestat[STATUS_STRMAX]; |
|
542 |
||
543 |
talon_returncode = p->returncode; |
|
544 |
||
545 |
if (dotagging) |
|
546 |
{ |
|
237
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
547 |
char *flagsstr = force_success == 0 ? "" : " flags='FORCESUCCESS'"; |
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
548 |
char *reasonstr = "" ; |
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
549 |
|
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
550 |
if (p->causeofdeath == PROC_TIMEOUTDEATH) |
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
551 |
reasonstr = " reason='timeout'"; |
3 | 552 |
|
553 |
if (p->returncode != 0) |
|
554 |
{ |
|
555 |
char *exitstr = retries > 0 ? "retry" : "failed"; |
|
237
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
556 |
snprintf(status, STATUS_STRMAX - 1, "\n<status exit='%s' code='%d' attempt='%d'%s%s />", exitstr, p->returncode, attempt, flagsstr, reasonstr ); |
3 | 557 |
} else { |
237
dd11681bd6f3
SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents:
3
diff
changeset
|
558 |
snprintf(status, STATUS_STRMAX - 1, "\n<status exit='ok' attempt='%d'%s%s />", attempt, flagsstr, reasonstr ); |
3 | 559 |
} |
560 |
status[STATUS_STRMAX-1] = '\0'; |
|
561 |
||
562 |
snprintf(timestat, STATUS_STRMAX - 1, "<time start='%.5f' elapsed='%.3f' />",start_time, end_time-start_time ); |
|
563 |
timestat[STATUS_STRMAX-1] = '\0'; |
|
564 |
||
565 |
prependattributes(p->output, attributes); |
|
566 |
||
567 |
if (dotagging) { |
|
568 |
} |
|
569 |
buffer_append(p->output, "\n]]>", 4); |
|
570 |
buffer_append(p->output, timestat, strlen(timestat)); |
|
571 |
buffer_append(p->output, status, strlen(status)); |
|
572 |
buffer_append(p->output, "\n</recipe>\n", 11); |
|
573 |
} |
|
574 |
||
575 |
unsigned int iterator = 0; |
|
576 |
byteblock *bb; |
|
577 |
||
578 |
if (descramble) |
|
579 |
sema_wait(&talon_sem); |
|
580 |
while ((bb = buffer_getbytes(p->output, &iterator))) |
|
581 |
{ |
|
582 |
write(STDOUT_FILENO, &bb->byte0, bb->fill); |
|
583 |
} |
|
584 |
if (descramble) |
|
585 |
sema_release(&talon_sem); |
|
586 |
||
587 |
||
588 |
if (p->returncode == 0 || force_success) |
|
589 |
{ |
|
590 |
process_free(&p); |
|
591 |
break; |
|
592 |
} |
|
593 |
||
594 |
process_free(&p); |
|
595 |
} else { |
|
596 |
error("error: failed to run shell: %s: check the SHELL environment variable.\n", args[0]); |
|
597 |
return 1; |
|
598 |
} |
|
599 |
||
600 |
retries--; |
|
601 |
} |
|
602 |
while (retries >= 0); |
|
603 |
||
604 |
if (buildid) free(buildid); buildid = NULL; |
|
605 |
if (attributes) free(attributes); attributes = NULL; |
|
606 |
if (shell) free(shell); shell = NULL; |
|
607 |
||
608 |
if (force_success) |
|
609 |
return 0; |
|
610 |
else |
|
611 |
return talon_returncode; |
|
612 |
} |