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