|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 "sema.h" |
|
32 #include "buffer.h" |
|
33 #include "../config.h" |
|
34 |
|
35 /* The output semaphore. */ |
|
36 sbs_semaphore talon_sem; |
|
37 |
|
38 #define TALON_ATTEMPT_STRMAX 32 |
|
39 #define RECIPETAG_STRMAX 2048 |
|
40 #define STATUS_STRMAX 100 |
|
41 |
|
42 #define TALONDELIMITER '|' |
|
43 #define VARNAMEMAX 100 |
|
44 #define VARVALMAX 1024 |
|
45 |
|
46 |
|
47 #include "log.h" |
|
48 |
|
49 #ifdef HAS_MSVCRT |
|
50 /* Make all output handling binary */ |
|
51 unsigned int _CRT_fmode = _O_BINARY; |
|
52 #endif |
|
53 |
|
54 double getseconds(void) |
|
55 { |
|
56 struct timeval tp; |
|
57 gettimeofday(&tp, NULL); |
|
58 |
|
59 return (double)tp.tv_sec + ((double)tp.tv_usec)/1000000.0L; |
|
60 } |
|
61 |
|
62 void talon_setenv(char name[], char val[]) |
|
63 { |
|
64 #if defined(HAS_GETENVIRONMENTVARIABLE) |
|
65 SetEnvironmentVariableA(name,val); |
|
66 #elif defined(HAS_GETENV) |
|
67 setenv(name,val, 1); |
|
68 #else |
|
69 # error "Need a function for setting environment variables" |
|
70 #endif |
|
71 } |
|
72 |
|
73 |
|
74 #define TALON_MAXENV 4096 |
|
75 char * talon_getenv(char name[]) |
|
76 { |
|
77 #if defined(HAS_SETENV) |
|
78 char *val = getenv(name); |
|
79 char *dest = NULL; |
|
80 |
|
81 if (val) |
|
82 { |
|
83 dest = malloc(strlen(val) + 1); |
|
84 if (dest) |
|
85 { |
|
86 strcpy(dest,val); |
|
87 } |
|
88 } |
|
89 return dest; |
|
90 #elif defined(HAS_SETENVIRONMENTVARIABLE) |
|
91 char *val = malloc(TALON_MAXENV); |
|
92 if (0 != GetEnvironmentVariableA(name,val,TALON_MAXENV-1)) |
|
93 return val; |
|
94 else |
|
95 return NULL; |
|
96 #else |
|
97 # error "Need a function for setting environment variables" |
|
98 #endif |
|
99 } |
|
100 |
|
101 |
|
102 |
|
103 int main(int argc, char *argv[]) |
|
104 { |
|
105 /* find the argument to -c then strip the talon related front section */ |
|
106 |
|
107 char *recipe = NULL; |
|
108 int talon_returncode = 0; |
|
109 |
|
110 /* Now take settings from the environment (having potentially modified it) */ |
|
111 if (talon_getenv("TALON_DEBUG")) |
|
112 loglevel=LOGDEBUG; |
|
113 |
|
114 |
|
115 int enverrors = 0; |
|
116 |
|
117 char *buildid = talon_getenv("TALON_BUILDID"); |
|
118 if (!buildid) |
|
119 { |
|
120 error("error: %s", "TALON_BUILDID not set in environment\n"); |
|
121 enverrors++; |
|
122 } |
|
123 |
|
124 talon_sem.name = buildid; |
|
125 talon_sem.timeout = 999999990; |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 int x; |
|
131 debug("debug: %s", "WAITING ON SEMAPHORE\n"); |
|
132 x = sema_wait(&talon_sem); |
|
133 if (x == 0) |
|
134 { |
|
135 debug("debug: %s", "SEMAPHORE OBTAINED\n"); |
|
136 getchar(); |
|
137 sema_release(&talon_sem); |
|
138 debug("debug: %s", "SEMAPHORE RELEASED\n"); |
|
139 } |
|
140 } |