Print this page
make: unifdef for TEAMWARE_MAKE_CMN (defined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/pmake.cc
+++ new/usr/src/cmd/make/bin/pmake.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#ifdef TEAMWARE_MAKE_CMN
27 26
28 27 /*
29 28 * Included files
30 29 */
31 30 #include <arpa/inet.h>
32 31 #include <mk/defs.h>
33 32 #include <mksh/misc.h>
34 33 #include <netdb.h>
35 34 #include <netinet/in.h>
36 35 #include <sys/socket.h>
37 36 #include <sys/stat.h>
38 37 #include <sys/types.h>
39 38 #include <sys/utsname.h>
40 39 #include <rpc/rpc.h> /* host2netname(), netname2host() */
41 40
42 41 /*
43 42 * Defined macros
44 43 */
45 44
46 45 /*
47 46 * typedefs & structs
48 47 */
49 48
50 49 /*
51 50 * Static variables
52 51 */
53 52
54 53 /*
55 54 * File table of contents
56 55 */
57 56 static int get_max(wchar_t **ms_address, wchar_t *hostname);
58 57 static Boolean pskip_comment(wchar_t **cp_address);
59 58 static void pskip_till_next_word(wchar_t **cp);
60 59 static Boolean pskip_white_space(wchar_t **cp_address);
61 60
62 61
63 62 /*
64 63 * read_make_machines(Name make_machines_name)
65 64 *
66 65 * For backwards compatibility w/ PMake 1.x, when DMake 2.x is
67 66 * being run in parallel mode, DMake should parse the PMake startup
68 67 * file $(HOME)/.make.machines to get the PMake max jobs.
69 68 *
70 69 * Return value:
71 70 * int of PMake max jobs
72 71 *
73 72 * Parameters:
74 73 * make_machines_name Name of .make.machines file
75 74 *
76 75 */
77 76 int
78 77 read_make_machines(Name make_machines_name)
79 78 {
80 79 wchar_t c;
81 80 Boolean default_make_machines;
82 81 struct hostent *hp;
83 82 wchar_t local_host[MAX_HOSTNAMELEN + 1];
84 83 char local_host_mb[MAX_HOSTNAMELEN + 1] = "";
85 84 int local_host_wslen;
86 85 wchar_t full_host[MAXNETNAMELEN + 1];
87 86 int full_host_wslen = 0;
88 87 char *homedir;
89 88 Name MAKE_MACHINES;
90 89 struct stat make_machines_buf;
91 90 FILE *make_machines_file;
92 91 wchar_t *make_machines_list = NULL;
93 92 char *make_machines_list_mb = NULL;
94 93 wchar_t make_machines_path[MAXPATHLEN];
95 94 char mb_make_machines_path[MAXPATHLEN];
96 95 wchar_t *mp;
97 96 wchar_t *ms;
98 97 int pmake_max_jobs = 0;
99 98 struct utsname uts_info;
100 99
101 100
102 101 MBSTOWCS(wcs_buffer, NOCATGETS("MAKE_MACHINES"));
103 102 MAKE_MACHINES = GETNAME(wcs_buffer, FIND_LENGTH);
104 103 /* Did the user specify a .make.machines file on the command line? */
105 104 default_make_machines = false;
106 105 if (make_machines_name == NULL) {
107 106 /* Try reading the default .make.machines file, in $(HOME). */
108 107 homedir = getenv(NOCATGETS("HOME"));
109 108 if ((homedir != NULL) && (strlen(homedir) < (sizeof(mb_make_machines_path) - 16))) {
110 109 sprintf(mb_make_machines_path,
111 110 NOCATGETS("%s/.make.machines"), homedir);
112 111 MBSTOWCS(make_machines_path, mb_make_machines_path);
113 112 make_machines_name = GETNAME(make_machines_path, FIND_LENGTH);
114 113 default_make_machines = true;
115 114 }
116 115 if (make_machines_name == NULL) {
117 116 /*
118 117 * No $(HOME)/.make.machines file.
119 118 * Return 0 for PMake max jobs.
120 119 */
121 120 return(0);
122 121 }
123 122 }
124 123 /*
125 124 make_machines_list_mb = getenv(MAKE_MACHINES->string_mb);
126 125 */
127 126 /* Open the .make.machines file. */
128 127 if ((make_machines_file = fopen(make_machines_name->string_mb, "r")) == NULL) {
129 128 if (!default_make_machines) {
130 129 /* Error opening .make.machines file. */
131 130 fatal(catgets(catd, 1, 314, "Open of %s failed: %s"),
132 131 make_machines_name->string_mb,
133 132 errmsg(errno));
134 133 } else {
135 134 /*
136 135 * No $(HOME)/.make.machines file.
137 136 * Return 0 for PMake max jobs.
138 137 */
139 138 return(0);
140 139 }
141 140 /* Stat the .make.machines file to get the size of the file. */
142 141 } else if (fstat(fileno(make_machines_file), &make_machines_buf) < 0) {
143 142 /* Error stat'ing .make.machines file. */
144 143 fatal(catgets(catd, 1, 315, "Stat of %s failed: %s"),
145 144 make_machines_name->string_mb,
146 145 errmsg(errno));
147 146 } else {
148 147 /* Allocate memory for "MAKE_MACHINES=<contents of .m.m>" */
149 148 make_machines_list_mb =
150 149 (char *) getmem((int) (strlen(MAKE_MACHINES->string_mb) +
151 150 2 +
152 151 make_machines_buf.st_size));
153 152 sprintf(make_machines_list_mb,
154 153 "%s=",
155 154 MAKE_MACHINES->string_mb);
156 155 /* Read in the .make.machines file. */
157 156 if (fread(make_machines_list_mb + strlen(MAKE_MACHINES->string_mb) + 1,
158 157 sizeof(char),
159 158 (int) make_machines_buf.st_size,
160 159 make_machines_file) != make_machines_buf.st_size) {
161 160 /*
162 161 * Error reading .make.machines file.
163 162 * Return 0 for PMake max jobs.
164 163 */
165 164 warning(catgets(catd, 1, 316, "Unable to read %s"),
166 165 make_machines_name->string_mb);
167 166 (void) fclose(make_machines_file);
168 167 retmem_mb((caddr_t) make_machines_list_mb);
169 168 return(0);
170 169 } else {
171 170 (void) fclose(make_machines_file);
172 171 /* putenv "MAKE_MACHINES=<contents of .m.m>" */
173 172 *(make_machines_list_mb +
174 173 strlen(MAKE_MACHINES->string_mb) +
175 174 1 +
176 175 make_machines_buf.st_size) = (int) nul_char;
177 176 if (putenv(make_machines_list_mb) != 0) {
178 177 warning(catgets(catd, 1, 317, "Couldn't put contents of %s in environment"),
179 178 make_machines_name->string_mb);
180 179 } else {
181 180 make_machines_list_mb += strlen(MAKE_MACHINES->string_mb) + 1;
182 181 make_machines_list = ALLOC_WC(strlen(make_machines_list_mb) + 1);
183 182 (void) mbstowcs(make_machines_list,
184 183 make_machines_list_mb,
185 184 (strlen(make_machines_list_mb) + 1));
186 185 }
187 186 }
188 187 }
189 188
190 189 uname(&uts_info);
191 190 strcpy(local_host_mb, &uts_info.nodename[0]);
192 191 MBSTOWCS(local_host, local_host_mb);
193 192 local_host_wslen = wslen(local_host);
194 193
195 194 // There is no getdomainname() function on Solaris.
196 195 // And netname2host() function does not work on Linux.
197 196 // So we have to use different APIs.
198 197 if (host2netname(mbs_buffer, NULL, NULL) &&
199 198 netname2host(mbs_buffer, mbs_buffer2, MAXNETNAMELEN+1)) {
200 199 MBSTOWCS(full_host, mbs_buffer2);
201 200 full_host_wslen = wslen(full_host);
202 201 }
203 202
204 203 for (ms = make_machines_list;
205 204 (ms) && (*ms );
206 205 ) {
207 206 /*
208 207 * Skip white space and comments till you reach
209 208 * a machine name.
210 209 */
211 210 pskip_till_next_word(&ms);
212 211
213 212 /*
214 213 * If we haven't reached the end of file, process the
215 214 * machine name.
216 215 */
217 216 if (*ms) {
218 217 /*
219 218 * If invalid machine name decrement counter
220 219 * and skip line.
221 220 */
222 221 mp = ms;
223 222 SKIPWORD(ms);
224 223 c = *ms;
225 224 *ms++ = '\0'; /* Append null to machine name. */
226 225 /*
227 226 * If this was the beginning of a comment
228 227 * (we overwrote a # sign) and it's not
229 228 * end of line yet, shift the # sign.
230 229 */
231 230 if ((c == '#') && (*ms != '\n') && (*ms)) {
232 231 *ms = '#';
233 232 }
234 233 WCSTOMBS(mbs_buffer, mp);
235 234 /*
236 235 * Print "Ignoring unknown host" if:
237 236 * 1) hostname is longer than MAX_HOSTNAMELEN, or
238 237 * 2) hostname is unknown
239 238 */
240 239 if ((wslen(mp) > MAX_HOSTNAMELEN) ||
241 240 ((hp = gethostbyname(mbs_buffer)) == NULL)) {
242 241 warning(catgets(catd, 1, 318, "Ignoring unknown host %s"),
243 242 mbs_buffer);
244 243 SKIPTOEND(ms);
245 244 /* Increment ptr if not end of file. */
246 245 if (*ms) {
247 246 ms++;
248 247 }
249 248 } else {
250 249 /* Compare current hostname with local_host. */
251 250 if (wslen(mp) == local_host_wslen &&
252 251 IS_WEQUALN(mp, local_host, local_host_wslen)) {
253 252 /*
254 253 * Bingo, local_host is in .make.machines.
255 254 * Continue reading.
256 255 */
257 256 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
258 257 /* Compare current hostname with full_host. */
259 258 } else if (wslen(mp) == full_host_wslen &&
260 259 IS_WEQUALN(mp, full_host, full_host_wslen)) {
261 260 /*
262 261 * Bingo, full_host is in .make.machines.
263 262 * Continue reading.
264 263 */
265 264 pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
266 265 } else {
267 266 if (c != '\n') {
268 267 SKIPTOEND(ms);
269 268 if (*ms) {
270 269 ms++;
271 270 }
272 271 }
273 272 continue;
274 273 }
275 274 /* If we get here, local_host is in .make.machines. */
276 275 if (c != '\n') {
277 276 /* Now look for keyword 'max'. */
278 277 MBSTOWCS(wcs_buffer, NOCATGETS("max"));
279 278 SKIPSPACE(ms);
280 279 while ((*ms != '\n') && (*ms)) {
281 280 if (*ms == '#') {
282 281 pskip_comment(&ms);
283 282 } else if (IS_WEQUALN(ms, wcs_buffer, 3)) {
284 283 /* Skip "max". */
285 284 ms += 3;
286 285 pmake_max_jobs = get_max(&ms, mp);
287 286 SKIPSPACE(ms);
288 287 } else {
289 288 warning(catgets(catd, 1, 322, "unknown option for host %s"), mbs_buffer);
290 289 SKIPTOEND(ms);
291 290 break;
292 291 }
293 292 }
294 293 }
295 294 break; /* out of outermost for() loop. */
296 295 }
297 296 }
298 297 }
299 298 retmem(make_machines_list);
300 299 return(pmake_max_jobs);
301 300 }
302 301
303 302 /*
304 303 * pskip_till_next_word(cp)
305 304 *
306 305 * Parameters:
307 306 * cp the address of the string pointer.
308 307 *
309 308 * On return:
310 309 * cp points to beginning of machine name.
311 310 *
312 311 */
313 312 static void
314 313 pskip_till_next_word(wchar_t **cp)
315 314 {
316 315 /*
317 316 * Keep recursing until all combinations of white spaces
318 317 * and comments have been skipped.
319 318 */
320 319 if (pskip_white_space(cp) || pskip_comment(cp)) {
321 320 pskip_till_next_word(cp);
322 321 }
323 322 }
324 323
325 324 /*
326 325 * pskip_white_space(cp_address)
327 326 *
328 327 * Advances the string pointer so that it points to the first
329 328 * non white character (space/tab/linefeed).
330 329 *
331 330 * Parameters:
332 331 * cp_address the address of the string pointer.
333 332 *
334 333 * Return Value:
335 334 * True if the pointer was changed.
336 335 *
337 336 */
338 337 static Boolean
339 338 pskip_white_space(wchar_t **cp_address)
340 339 {
341 340 wchar_t *cp = *cp_address;
342 341
343 342 while (*cp && iswspace(*cp)) {
344 343 cp++;
345 344 }
346 345 /* Have we skipped any characters? */
347 346 if (cp != *cp_address) {
348 347 *cp_address = cp;
349 348 return(true);
350 349 } else {
351 350 return(false);
352 351 }
353 352 }
354 353
355 354 /*
356 355 * pskip_comment(cp_address)
357 356 *
358 357 * If cp_address is pointing to '#' (the beginning of a comment),
359 358 * increment the pointer till you reach end of line.
360 359 *
361 360 * Parameters:
362 361 * cp_address the address of the string pointer.
363 362 *
364 363 * Return Value:
365 364 * True if the pointer was changed.
366 365 *
367 366 */
368 367 static Boolean
369 368 pskip_comment(wchar_t **cp_address)
370 369 {
371 370 wchar_t *cp = *cp_address;
372 371
373 372 /* Is this the beginning of a comment? Skip till end of line. */
374 373 if (*cp == '#') {
375 374 SKIPTOEND(cp);
376 375 }
377 376 /* Have we skipped a comment line? */
378 377 if (cp != *cp_address) {
379 378 *cp_address = cp;
380 379 return(true);
381 380 } else {
382 381 return(false);
383 382 }
384 383 }
385 384
386 385 static int
387 386 get_max(wchar_t **ms_address, wchar_t *hostname)
388 387 {
389 388 wchar_t *ms = *ms_address;
390 389 int limit = PMAKE_DEF_MAX_JOBS; /* Default setting. */
391 390
392 391 WCSTOMBS(mbs_buffer, hostname);
393 392 /* Look for `='. */
394 393 SKIPSPACE(ms);
395 394 if ((!*ms) || (*ms == '\n') || (*ms != '=')) {
396 395 SKIPTOEND(ms);
397 396 warning(catgets(catd, 1, 319, "expected `=' after max, ignoring rest of line for host %s"),
398 397 mbs_buffer);
399 398 *ms_address = ms;
400 399 return((int) limit);
401 400 } else {
402 401 ms++;
403 402 SKIPSPACE(ms);
404 403 if ((*ms != '\n') && (*ms != '\0')) {
405 404 /* We've found, hopefully, a valid "max" value. */
406 405 limit = (int) wcstol(ms, &ms, 10);
407 406 if (limit < 1) {
408 407 limit = PMAKE_DEF_MAX_JOBS;
409 408 warning(catgets(catd, 1, 320, "max value cannot be less than or equal to zero for host %s"), mbs_buffer);
↓ open down ↓ |
373 lines elided |
↑ open up ↑ |
410 409 }
411 410 } else {
412 411 /* No "max" value after "max=". */
413 412 warning(catgets(catd, 1, 321, "no max value specified for host %s"), mbs_buffer);
414 413 }
415 414 *ms_address = ms;
416 415 return(limit);
417 416 }
418 417 }
419 418
420 -#endif
421 419
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX