source: trunk/src/kmk/job.c@ 2591

Last change on this file since 2591 was 2591, checked in by bird, 13 years ago

kmk: Merged in changes from GNU make 3.82. Previous GNU make base version was gnumake-2008-10-28-CVS.

  • Property svn:eol-style set to native
File size: 104.2 KB
Line 
1/* Job execution and handling for GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
42010 Free Software Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 3 of the License, or (at your option) any later
10version.
11
12GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along with
17this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include "make.h"
20
21#include <assert.h>
22
23#include "job.h"
24#include "debug.h"
25#include "filedef.h"
26#include "commands.h"
27#include "variable.h"
28#include "debug.h"
29#ifdef CONFIG_WITH_KMK_BUILTIN
30# include "kmkbuiltin.h"
31#endif
32#ifdef KMK
33# include "kbuild.h"
34#endif
35
36
37#include <string.h>
38
39/* Default shell to use. */
40#ifdef WINDOWS32
41#include <windows.h>
42
43char *default_shell = "sh.exe";
44int no_default_sh_exe = 1;
45int batch_mode_shell = 1;
46HANDLE main_thread;
47
48#elif defined (_AMIGA)
49
50char default_shell[] = "";
51extern int MyExecute (char **);
52int batch_mode_shell = 0;
53
54#elif defined (__MSDOS__)
55
56/* The default shell is a pointer so we can change it if Makefile
57 says so. It is without an explicit path so we get a chance
58 to search the $PATH for it (since MSDOS doesn't have standard
59 directories we could trust). */
60char *default_shell = "command.com";
61int batch_mode_shell = 0;
62
63#elif defined (__EMX__)
64
65char *default_shell = "sh.exe"; /* bird changed this from "/bin/sh" as that doesn't make sense on OS/2. */
66int batch_mode_shell = 0;
67
68#elif defined (VMS)
69
70# include <descrip.h>
71char default_shell[] = "";
72int batch_mode_shell = 0;
73
74#elif defined (__riscos__)
75
76char default_shell[] = "";
77int batch_mode_shell = 0;
78
79#else
80
81char default_shell[] = "/bin/sh";
82int batch_mode_shell = 0;
83
84#endif
85
86#ifdef __MSDOS__
87# include <process.h>
88static int execute_by_shell;
89static int dos_pid = 123;
90int dos_status;
91int dos_command_running;
92#endif /* __MSDOS__ */
93
94#ifdef _AMIGA
95# include <proto/dos.h>
96static int amiga_pid = 123;
97static int amiga_status;
98static char amiga_bname[32];
99static int amiga_batch_file;
100#endif /* Amiga. */
101
102#ifdef VMS
103# ifndef __GNUC__
104# include <processes.h>
105# endif
106# include <starlet.h>
107# include <lib$routines.h>
108static void vmsWaitForChildren (int *);
109#endif
110
111#ifdef WINDOWS32
112# include <windows.h>
113# include <io.h>
114# include <process.h>
115# include "sub_proc.h"
116# include "w32err.h"
117# include "pathstuff.h"
118#endif /* WINDOWS32 */
119
120#ifdef __EMX__
121# include <process.h>
122#endif
123
124#if defined (HAVE_SYS_WAIT_H) || defined (HAVE_UNION_WAIT)
125# include <sys/wait.h>
126#endif
127
128#ifdef HAVE_WAITPID
129# define WAIT_NOHANG(status) waitpid (-1, (status), WNOHANG)
130#else /* Don't have waitpid. */
131# ifdef HAVE_WAIT3
132# ifndef wait3
133extern int wait3 ();
134# endif
135# define WAIT_NOHANG(status) wait3 ((status), WNOHANG, (struct rusage *) 0)
136# endif /* Have wait3. */
137#endif /* Have waitpid. */
138
139#if !defined (wait) && !defined (POSIX)
140int wait ();
141#endif
142
143#ifndef HAVE_UNION_WAIT
144
145# define WAIT_T int
146
147# ifndef WTERMSIG
148# define WTERMSIG(x) ((x) & 0x7f)
149# endif
150# ifndef WCOREDUMP
151# define WCOREDUMP(x) ((x) & 0x80)
152# endif
153# ifndef WEXITSTATUS
154# define WEXITSTATUS(x) (((x) >> 8) & 0xff)
155# endif
156# ifndef WIFSIGNALED
157# define WIFSIGNALED(x) (WTERMSIG (x) != 0)
158# endif
159# ifndef WIFEXITED
160# define WIFEXITED(x) (WTERMSIG (x) == 0)
161# endif
162
163#else /* Have `union wait'. */
164
165# define WAIT_T union wait
166# ifndef WTERMSIG
167# define WTERMSIG(x) ((x).w_termsig)
168# endif
169# ifndef WCOREDUMP
170# define WCOREDUMP(x) ((x).w_coredump)
171# endif
172# ifndef WEXITSTATUS
173# define WEXITSTATUS(x) ((x).w_retcode)
174# endif
175# ifndef WIFSIGNALED
176# define WIFSIGNALED(x) (WTERMSIG(x) != 0)
177# endif
178# ifndef WIFEXITED
179# define WIFEXITED(x) (WTERMSIG(x) == 0)
180# endif
181
182#endif /* Don't have `union wait'. */
183
184#if !defined(HAVE_UNISTD_H) && !defined(WINDOWS32)
185# ifndef _MSC_VER /* bird */
186int dup2 ();
187int execve ();
188void _exit ();
189# endif /* bird */
190# ifndef VMS
191int geteuid ();
192int getegid ();
193int setgid ();
194int getgid ();
195# endif
196#endif
197
198/* Different systems have different requirements for pid_t.
199 Plus we have to support gettext string translation... Argh. */
200static const char *
201pid2str (pid_t pid)
202{
203 static char pidstring[100];
204#if defined(WINDOWS32) && (__GNUC__ > 3 || _MSC_VER > 1300)
205 /* %Id is only needed for 64-builds, which were not supported by
206 older versions of Windows compilers. */
207 sprintf (pidstring, "%Id", pid);
208#else
209 sprintf (pidstring, "%lu", (unsigned long) pid);
210#endif
211 return pidstring;
212}
213
214int getloadavg (double loadavg[], int nelem);
215int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote,
216 int *id_ptr, int *used_stdin);
217int start_remote_job_p (int);
218int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr,
219 int block);
220
221RETSIGTYPE child_handler (int);
222static void free_child (struct child *);
223static void start_job_command (struct child *child);
224static int load_too_high (void);
225static int job_next_command (struct child *);
226static int start_waiting_job (struct child *);
227#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
228static void print_job_time (struct child *);
229#endif
230
231
232/* Chain of all live (or recently deceased) children. */
233
234struct child *children = 0;
235
236/* Number of children currently running. */
237
238unsigned int job_slots_used = 0;
239
240/* Nonzero if the `good' standard input is in use. */
241
242static int good_stdin_used = 0;
243
244/* Chain of children waiting to run until the load average goes down. */
245
246static struct child *waiting_jobs = 0;
247
248/* Non-zero if we use a *real* shell (always so on Unix). */
249
250int unixy_shell = 1;
251
252/* Number of jobs started in the current second. */
253
254unsigned long job_counter = 0;
255
256/* Number of jobserver tokens this instance is currently using. */
257
258unsigned int jobserver_tokens = 0;
259
260
261#ifdef WINDOWS32
262/*
263 * The macro which references this function is defined in make.h.
264 */
265int
266w32_kill(pid_t pid, int sig)
267{
268 return ((process_kill((HANDLE)pid, sig) == TRUE) ? 0 : -1);
269}
270
271/* This function creates a temporary file name with an extension specified
272 * by the unixy arg.
273 * Return an xmalloc'ed string of a newly created temp file and its
274 * file descriptor, or die. */
275static char *
276create_batch_file (char const *base, int unixy, int *fd)
277{
278 const char *const ext = unixy ? "sh" : "bat";
279 const char *error_string = NULL;
280 char temp_path[MAXPATHLEN]; /* need to know its length */
281 unsigned path_size = GetTempPath(sizeof temp_path, temp_path);
282 int path_is_dot = 0;
283 unsigned uniq = 1;
284 const unsigned sizemax = strlen (base) + strlen (ext) + 10;
285
286 if (path_size == 0)
287 {
288 path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
289 path_is_dot = 1;
290 }
291
292 while (path_size > 0 &&
293 path_size + sizemax < sizeof temp_path &&
294 uniq < 0x10000)
295 {
296 unsigned size = sprintf (temp_path + path_size,
297 "%s%s-%x.%s",
298 temp_path[path_size - 1] == '\\' ? "" : "\\",
299 base, uniq, ext);
300 HANDLE h = CreateFile (temp_path, /* file name */
301 GENERIC_READ | GENERIC_WRITE, /* desired access */
302 0, /* no share mode */
303 NULL, /* default security attributes */
304 CREATE_NEW, /* creation disposition */
305 FILE_ATTRIBUTE_NORMAL | /* flags and attributes */
306 FILE_ATTRIBUTE_TEMPORARY, /* we'll delete it */
307 NULL); /* no template file */
308
309 if (h == INVALID_HANDLE_VALUE)
310 {
311 const DWORD er = GetLastError();
312
313 if (er == ERROR_FILE_EXISTS || er == ERROR_ALREADY_EXISTS)
314 ++uniq;
315
316 /* the temporary path is not guaranteed to exist */
317 else if (path_is_dot == 0)
318 {
319 path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
320 path_is_dot = 1;
321 }
322
323 else
324 {
325 error_string = map_windows32_error_to_string (er);
326 break;
327 }
328 }
329 else
330 {
331 const unsigned final_size = path_size + size + 1;
332 char *const path = xmalloc (final_size);
333 memcpy (path, temp_path, final_size);
334 *fd = _open_osfhandle ((intptr_t)h, 0);
335 if (unixy)
336 {
337 char *p;
338 int ch;
339 for (p = path; (ch = *p) != 0; ++p)
340 if (ch == '\\')
341 *p = '/';
342 }
343 return path; /* good return */
344 }
345 }
346
347 *fd = -1;
348 if (error_string == NULL)
349 error_string = _("Cannot create a temporary file\n");
350 fatal (NILF, error_string);
351
352 /* not reached */
353 return NULL;
354}
355#endif /* WINDOWS32 */
356
357#ifdef __EMX__
358/* returns whether path is assumed to be a unix like shell. */
359int
360_is_unixy_shell (const char *path)
361{
362 /* list of non unix shells */
363 const char *known_os2shells[] = {
364 "cmd.exe",
365 "cmd",
366 "4os2.exe",
367 "4os2",
368 "4dos.exe",
369 "4dos",
370 "command.com",
371 "command",
372 NULL
373 };
374
375 /* find the rightmost '/' or '\\' */
376 const char *name = strrchr (path, '/');
377 const char *p = strrchr (path, '\\');
378 unsigned i;
379
380 if (name && p) /* take the max */
381 name = (name > p) ? name : p;
382 else if (p) /* name must be 0 */
383 name = p;
384 else if (!name) /* name and p must be 0 */
385 name = path;
386
387 if (*name == '/' || *name == '\\') name++;
388
389 i = 0;
390 while (known_os2shells[i] != NULL) {
391 if (strcasecmp (name, known_os2shells[i]) == 0)
392 return 0; /* not a unix shell */
393 i++;
394 }
395
396 /* in doubt assume a unix like shell */
397 return 1;
398}
399#endif /* __EMX__ */
400
401/* determines whether path looks to be a Bourne-like shell. */
402int
403is_bourne_compatible_shell (const char *path)
404{
405 /* list of known unix (Bourne-like) shells */
406 const char *unix_shells[] = {
407 "sh",
408 "bash",
409 "ksh",
410 "rksh",
411 "zsh",
412 "ash",
413 "dash",
414 NULL
415 };
416 unsigned i, len;
417
418 /* find the rightmost '/' or '\\' */
419 const char *name = strrchr (path, '/');
420 char *p = strrchr (path, '\\');
421
422 if (name && p) /* take the max */
423 name = (name > p) ? name : p;
424 else if (p) /* name must be 0 */
425 name = p;
426 else if (!name) /* name and p must be 0 */
427 name = path;
428
429 if (*name == '/' || *name == '\\') name++;
430
431 /* this should be able to deal with extensions on Windows-like systems */
432 for (i = 0; unix_shells[i] != NULL; i++) {
433 len = strlen(unix_shells[i]);
434#if defined(WINDOWS32) || defined(__MSDOS__)
435 if ((strncasecmp (name, unix_shells[i], len) == 0) &&
436 (strlen(name) >= len && (name[len] == '\0' || name[len] == '.')))
437#else
438 if ((strncmp (name, unix_shells[i], len) == 0) &&
439 (strlen(name) >= len && name[len] == '\0'))
440#endif
441 return 1; /* a known unix-style shell */
442 }
443
444 /* if not on the list, assume it's not a Bourne-like shell */
445 return 0;
446}
447
448
449
450/* Write an error message describing the exit status given in
451 EXIT_CODE, EXIT_SIG, and COREDUMP, for the target TARGET_NAME.
452 Append "(ignored)" if IGNORED is nonzero. */
453
454static void
455child_error (const char *target_name,
456 int exit_code, int exit_sig, int coredump, int ignored)
457{
458 if (ignored && silent_flag)
459 return;
460
461#ifdef VMS
462 if (!(exit_code & 1))
463 error (NILF,
464 (ignored ? _("*** [%s] Error 0x%x (ignored)")
465 : _("*** [%s] Error 0x%x")),
466 target_name, exit_code);
467#else
468 if (exit_sig == 0)
469 error (NILF, ignored ? _("[%s] Error %d (ignored)") :
470 _("*** [%s] Error %d"),
471 target_name, exit_code);
472 else
473 error (NILF, "*** [%s] %s%s",
474 target_name, strsignal (exit_sig),
475 coredump ? _(" (core dumped)") : "");
476#endif /* VMS */
477}
478
479
480
481/* Handle a dead child. This handler may or may not ever be installed.
482
483 If we're using the jobserver feature, we need it. First, installing it
484 ensures the read will interrupt on SIGCHLD. Second, we close the dup'd
485 read FD to ensure we don't enter another blocking read without reaping all
486 the dead children. In this case we don't need the dead_children count.
487
488 If we don't have either waitpid or wait3, then make is unreliable, but we
489 use the dead_children count to reap children as best we can. */
490
491static unsigned int dead_children = 0;
492
493RETSIGTYPE
494child_handler (int sig UNUSED)
495{
496 ++dead_children;
497
498 if (job_rfd >= 0)
499 {
500 close (job_rfd);
501 job_rfd = -1;
502 }
503
504#if defined __EMX__ && !defined(__INNOTEK_LIBC__) /* bird */
505 /* The signal handler must called only once! */
506 signal (SIGCHLD, SIG_DFL);
507#endif
508
509 /* This causes problems if the SIGCHLD interrupts a printf().
510 DB (DB_JOBS, (_("Got a SIGCHLD; %u unreaped children.\n"), dead_children));
511 */
512}
513
514extern int shell_function_pid, shell_function_completed;
515
516/* Reap all dead children, storing the returned status and the new command
517 state (`cs_finished') in the `file' member of the `struct child' for the
518 dead child, and removing the child from the chain. In addition, if BLOCK
519 nonzero, we block in this function until we've reaped at least one
520 complete child, waiting for it to die if necessary. If ERR is nonzero,
521 print an error message first. */
522
523void
524reap_children (int block, int err)
525{
526#ifndef WINDOWS32
527 WAIT_T status;
528 /* Initially, assume we have some. */
529 int reap_more = 1;
530#endif
531
532#ifdef WAIT_NOHANG
533# define REAP_MORE reap_more
534#else
535# define REAP_MORE dead_children
536#endif
537
538 /* As long as:
539
540 We have at least one child outstanding OR a shell function in progress,
541 AND
542 We're blocking for a complete child OR there are more children to reap
543
544 we'll keep reaping children. */
545
546 while ((children != 0 || shell_function_pid != 0)
547 && (block || REAP_MORE))
548 {
549 int remote = 0;
550 pid_t pid;
551 int exit_code, exit_sig, coredump;
552 register struct child *lastc, *c;
553 int child_failed;
554 int any_remote, any_local;
555 int dontcare;
556#ifdef CONFIG_WITH_KMK_BUILTIN
557 struct child *completed_child = NULL;
558#endif
559
560 if (err && block)
561 {
562 static int printed = 0;
563
564 /* We might block for a while, so let the user know why.
565 Only print this message once no matter how many jobs are left. */
566 fflush (stdout);
567 if (!printed)
568 error (NILF, _("*** Waiting for unfinished jobs...."));
569 printed = 1;
570 }
571
572 /* We have one less dead child to reap. As noted in
573 child_handler() above, this count is completely unimportant for
574 all modern, POSIX-y systems that support wait3() or waitpid().
575 The rest of this comment below applies only to early, broken
576 pre-POSIX systems. We keep the count only because... it's there...
577
578 The test and decrement are not atomic; if it is compiled into:
579 register = dead_children - 1;
580 dead_children = register;
581 a SIGCHLD could come between the two instructions.
582 child_handler increments dead_children.
583 The second instruction here would lose that increment. But the
584 only effect of dead_children being wrong is that we might wait
585 longer than necessary to reap a child, and lose some parallelism;
586 and we might print the "Waiting for unfinished jobs" message above
587 when not necessary. */
588
589 if (dead_children > 0)
590 --dead_children;
591
592 any_remote = 0;
593 any_local = shell_function_pid != 0;
594 for (c = children; c != 0; c = c->next)
595 {
596 any_remote |= c->remote;
597 any_local |= ! c->remote;
598#ifdef CONFIG_WITH_KMK_BUILTIN
599 if (c->has_status)
600 {
601 completed_child = c;
602 DB (DB_JOBS, (_("builtin child %p (%s) PID %s %s Status %ld\n"),
603 (void *)c, c->file->name,
604 pid2str (c->pid), c->remote ? _(" (remote)") : "",
605 (long) c->status));
606 }
607 else
608#endif
609 DB (DB_JOBS, (_("Live child %p (%s) PID %s %s\n"),
610 (void *)c, c->file->name, pid2str (c->pid),
611 c->remote ? _(" (remote)") : ""));
612#ifdef VMS
613 break;
614#endif
615 }
616
617 /* First, check for remote children. */
618 if (any_remote)
619 pid = remote_status (&exit_code, &exit_sig, &coredump, 0);
620 else
621 pid = 0;
622
623 if (pid > 0)
624 /* We got a remote child. */
625 remote = 1;
626 else if (pid < 0)
627 {
628 /* A remote status command failed miserably. Punt. */
629 remote_status_lose:
630 pfatal_with_name ("remote_status");
631 }
632 else
633 {
634 /* No remote children. Check for local children. */
635#ifdef CONFIG_WITH_KMK_BUILTIN
636 if (completed_child)
637 {
638 pid = completed_child->pid;
639# if defined(WINDOWS32)
640 exit_code = completed_child->status;
641 exit_sig = 0;
642 coredump = 0;
643# else
644 status = (WAIT_T)completed_child->status;
645# endif
646 }
647 else
648#endif /* CONFIG_WITH_KMK_BUILTIN */
649#if !defined(__MSDOS__) && !defined(_AMIGA) && !defined(WINDOWS32)
650 if (any_local)
651 {
652#ifdef VMS
653 vmsWaitForChildren (&status);
654 pid = c->pid;
655#else
656#ifdef WAIT_NOHANG
657 if (!block)
658 pid = WAIT_NOHANG (&status);
659 else
660#endif
661 EINTRLOOP(pid, wait (&status));
662#endif /* !VMS */
663 }
664 else
665 pid = 0;
666
667 if (pid < 0)
668 {
669 /* The wait*() failed miserably. Punt. */
670 pfatal_with_name ("wait");
671 }
672 else if (pid > 0)
673 {
674 /* We got a child exit; chop the status word up. */
675 exit_code = WEXITSTATUS (status);
676 exit_sig = WIFSIGNALED (status) ? WTERMSIG (status) : 0;
677 coredump = WCOREDUMP (status);
678
679 /* If we have started jobs in this second, remove one. */
680 if (job_counter)
681 --job_counter;
682 }
683 else
684 {
685 /* No local children are dead. */
686 reap_more = 0;
687
688 if (!block || !any_remote)
689 break;
690
691 /* Now try a blocking wait for a remote child. */
692 pid = remote_status (&exit_code, &exit_sig, &coredump, 1);
693 if (pid < 0)
694 goto remote_status_lose;
695 else if (pid == 0)
696 /* No remote children either. Finally give up. */
697 break;
698
699 /* We got a remote child. */
700 remote = 1;
701 }
702#endif /* !__MSDOS__, !Amiga, !WINDOWS32. */
703
704#ifdef __MSDOS__
705 /* Life is very different on MSDOS. */
706 pid = dos_pid - 1;
707 status = dos_status;
708 exit_code = WEXITSTATUS (status);
709 if (exit_code == 0xff)
710 exit_code = -1;
711 exit_sig = WIFSIGNALED (status) ? WTERMSIG (status) : 0;
712 coredump = 0;
713#endif /* __MSDOS__ */
714#ifdef _AMIGA
715 /* Same on Amiga */
716 pid = amiga_pid - 1;
717 status = amiga_status;
718 exit_code = amiga_status;
719 exit_sig = 0;
720 coredump = 0;
721#endif /* _AMIGA */
722#ifdef WINDOWS32
723 {
724 HANDLE hPID;
725 int werr;
726 HANDLE hcTID, hcPID;
727 exit_code = 0;
728 exit_sig = 0;
729 coredump = 0;
730
731 /* Record the thread ID of the main process, so that we
732 could suspend it in the signal handler. */
733 if (!main_thread)
734 {
735 hcTID = GetCurrentThread ();
736 hcPID = GetCurrentProcess ();
737 if (!DuplicateHandle (hcPID, hcTID, hcPID, &main_thread, 0,
738 FALSE, DUPLICATE_SAME_ACCESS))
739 {
740 DWORD e = GetLastError ();
741 fprintf (stderr,
742 "Determine main thread ID (Error %ld: %s)\n",
743 e, map_windows32_error_to_string(e));
744 }
745 else
746 DB (DB_VERBOSE, ("Main thread handle = %p\n", main_thread));
747 }
748
749 /* wait for anything to finish */
750 hPID = process_wait_for_any();
751 if (hPID)
752 {
753
754 /* was an error found on this process? */
755 werr = process_last_err(hPID);
756
757 /* get exit data */
758 exit_code = process_exit_code(hPID);
759
760 if (werr)
761 fprintf(stderr, "make (e=%d): %s",
762 exit_code, map_windows32_error_to_string(exit_code));
763
764 /* signal */
765 exit_sig = process_signal(hPID);
766
767 /* cleanup process */
768 process_cleanup(hPID);
769
770 coredump = 0;
771 }
772 else if (!process_used_slots())
773 {
774 /* The wait*() failed miserably. Punt. */
775 errno = ECHILD;
776 pfatal_with_name ("wait");
777 }
778
779 pid = (pid_t) hPID;
780 }
781#endif /* WINDOWS32 */
782 }
783
784 /* Check if this is the child of the `shell' function. */
785 if (!remote && pid == shell_function_pid)
786 {
787 /* It is. Leave an indicator for the `shell' function. */
788 if (exit_sig == 0 && exit_code == 127)
789 shell_function_completed = -1;
790 else
791 shell_function_completed = 1;
792 break;
793 }
794
795 child_failed = exit_sig != 0 || exit_code != 0;
796
797 /* Search for a child matching the deceased one. */
798 lastc = 0;
799 for (c = children; c != 0; lastc = c, c = c->next)
800 if (c->remote == remote && c->pid == pid)
801 break;
802
803 if (c == 0)
804 /* An unknown child died.
805 Ignore it; it was inherited from our invoker. */
806 continue;
807
808 DB (DB_JOBS, (child_failed
809 ? _("Reaping losing child %p PID %s %s\n")
810 : _("Reaping winning child %p PID %s %s\n"),
811 (void *)c, pid2str (c->pid), c->remote ? _(" (remote)") : ""));
812
813 if (c->sh_batch_file) {
814 DB (DB_JOBS, (_("Cleaning up temp batch file %s\n"),
815 c->sh_batch_file));
816
817 /* just try and remove, don't care if this fails */
818 remove (c->sh_batch_file);
819
820 /* all done with memory */
821 free (c->sh_batch_file);
822 c->sh_batch_file = NULL;
823 }
824
825 /* If this child had the good stdin, say it is now free. */
826 if (c->good_stdin)
827 good_stdin_used = 0;
828
829 dontcare = c->dontcare;
830
831 if (child_failed && !c->noerror && !ignore_errors_flag)
832 {
833 /* The commands failed. Write an error message,
834 delete non-precious targets, and abort. */
835 static int delete_on_error = -1;
836
837 if (!dontcare)
838#ifdef KMK
839 {
840 child_error (c->file->name, exit_code, exit_sig, coredump, 0);
841 if (( c->file->cmds->lines_flags[c->command_line - 1]
842 & (COMMANDS_SILENT | COMMANDS_RECURSE))
843 == COMMANDS_SILENT)
844 message (0, "The failing command:\n%s", c->file->cmds->command_lines[c->command_line - 1]);
845 }
846#else /* !KMK */
847 child_error (c->file->name, exit_code, exit_sig, coredump, 0);
848#endif /* !KMK */
849
850 c->file->update_status = 2;
851 if (delete_on_error == -1)
852 {
853 struct file *f = lookup_file (".DELETE_ON_ERROR");
854 delete_on_error = f != 0 && f->is_target;
855 }
856 if (exit_sig != 0 || delete_on_error)
857 delete_child_targets (c);
858 }
859 else
860 {
861 if (child_failed)
862 {
863 /* The commands failed, but we don't care. */
864 child_error (c->file->name,
865 exit_code, exit_sig, coredump, 1);
866 child_failed = 0;
867 }
868
869 /* If there are more commands to run, try to start them. */
870 if (job_next_command (c))
871 {
872 if (handling_fatal_signal)
873 {
874 /* Never start new commands while we are dying.
875 Since there are more commands that wanted to be run,
876 the target was not completely remade. So we treat
877 this as if a command had failed. */
878 c->file->update_status = 2;
879 }
880 else
881 {
882 /* Check again whether to start remotely.
883 Whether or not we want to changes over time.
884 Also, start_remote_job may need state set up
885 by start_remote_job_p. */
886 c->remote = start_remote_job_p (0);
887 start_job_command (c);
888 /* Fatal signals are left blocked in case we were
889 about to put that child on the chain. But it is
890 already there, so it is safe for a fatal signal to
891 arrive now; it will clean up this child's targets. */
892 unblock_sigs ();
893 if (c->file->command_state == cs_running)
894 /* We successfully started the new command.
895 Loop to reap more children. */
896 continue;
897 }
898
899 if (c->file->update_status != 0)
900 /* We failed to start the commands. */
901 delete_child_targets (c);
902 }
903 else
904 /* There are no more commands. We got through them all
905 without an unignored error. Now the target has been
906 successfully updated. */
907 c->file->update_status = 0;
908 }
909
910 /* When we get here, all the commands for C->file are finished
911 (or aborted) and C->file->update_status contains 0 or 2. But
912 C->file->command_state is still cs_running if all the commands
913 ran; notice_finish_file looks for cs_running to tell it that
914 it's interesting to check the file's modtime again now. */
915
916 if (! handling_fatal_signal)
917 /* Notice if the target of the commands has been changed.
918 This also propagates its values for command_state and
919 update_status to its also_make files. */
920 notice_finished_file (c->file);
921
922 DB (DB_JOBS, (_("Removing child %p PID %s%s from chain.\n"),
923 (void *)c, pid2str (c->pid), c->remote ? _(" (remote)") : ""));
924
925 /* Block fatal signals while frobnicating the list, so that
926 children and job_slots_used are always consistent. Otherwise
927 a fatal signal arriving after the child is off the chain and
928 before job_slots_used is decremented would believe a child was
929 live and call reap_children again. */
930 block_sigs ();
931
932 /* There is now another slot open. */
933 if (job_slots_used > 0)
934 --job_slots_used;
935
936 /* Remove the child from the chain and free it. */
937 if (lastc == 0)
938 children = c->next;
939 else
940 lastc->next = c->next;
941
942 free_child (c);
943
944 unblock_sigs ();
945
946 /* If the job failed, and the -k flag was not given, die,
947 unless we are already in the process of dying. */
948 if (!err && child_failed && !dontcare && !keep_going_flag &&
949 /* fatal_error_signal will die with the right signal. */
950 !handling_fatal_signal)
951 die (2);
952
953 /* Only block for one child. */
954 block = 0;
955 }
956
957 return;
958}
959
960
961/* Free the storage allocated for CHILD. */
962
963static void
964free_child (struct child *child)
965{
966#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
967 print_job_time (child);
968#endif
969 if (!jobserver_tokens)
970 fatal (NILF, "INTERNAL: Freeing child %p (%s) but no tokens left!\n",
971 (void *)child, child->file->name);
972
973 /* If we're using the jobserver and this child is not the only outstanding
974 job, put a token back into the pipe for it. */
975
976 if (job_fds[1] >= 0 && jobserver_tokens > 1)
977 {
978 char token = '+';
979 int r;
980
981 /* Write a job token back to the pipe. */
982
983 EINTRLOOP (r, write (job_fds[1], &token, 1));
984 if (r != 1)
985 pfatal_with_name (_("write jobserver"));
986
987 DB (DB_JOBS, (_("Released token for child %p (%s).\n"),
988 (void *)child, child->file->name));
989 }
990
991 --jobserver_tokens;
992
993 if (handling_fatal_signal) /* Don't bother free'ing if about to die. */
994 return;
995
996 if (child->command_lines != 0)
997 {
998 register unsigned int i;
999 for (i = 0; i < child->file->cmds->ncommand_lines; ++i)
1000 free (child->command_lines[i]);
1001 free (child->command_lines);
1002 }
1003
1004 if (child->environment != 0)
1005 {
1006 register char **ep = child->environment;
1007 while (*ep != 0)
1008 free (*ep++);
1009 free (child->environment);
1010 }
1011
1012#ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS
1013 /* Free the chopped command lines for simple targets when
1014 there are no more active references to them. */
1015
1016 child->file->cmds->refs--;
1017 if ( !child->file->intermediate
1018 && !child->file->pat_variables
1019 && child->file->cmds->refs == 0)
1020 {
1021 struct commands *cmds = child->file->cmds;
1022 unsigned int i;
1023
1024 for (i = 0; i < cmds->ncommand_lines; ++i)
1025 {
1026 free (cmds->command_lines[i]);
1027 cmds->command_lines[i] = 0;
1028 }
1029 free (cmds->command_lines);
1030 cmds->command_lines = 0;
1031 free (cmds->lines_flags);
1032 cmds->lines_flags = 0;
1033 cmds->ncommand_lines = 0;
1034 }
1035#endif /* CONFIG_WITH_MEMORY_OPTIMIZATIONS */
1036
1037 free (child);
1038}
1039
1040
1041#ifdef POSIX
1042extern sigset_t fatal_signal_set;
1043#endif
1044
1045void
1046block_sigs (void)
1047{
1048#ifdef POSIX
1049 (void) sigprocmask (SIG_BLOCK, &fatal_signal_set, (sigset_t *) 0);
1050#else
1051# ifdef HAVE_SIGSETMASK
1052 (void) sigblock (fatal_signal_mask);
1053# endif
1054#endif
1055}
1056
1057#ifdef POSIX
1058void
1059unblock_sigs (void)
1060{
1061 sigset_t empty;
1062 sigemptyset (&empty);
1063 sigprocmask (SIG_SETMASK, &empty, (sigset_t *) 0);
1064}
1065#endif
1066
1067#ifdef MAKE_JOBSERVER
1068RETSIGTYPE
1069job_noop (int sig UNUSED)
1070{
1071}
1072/* Set the child handler action flags to FLAGS. */
1073static void
1074set_child_handler_action_flags (int set_handler, int set_alarm)
1075{
1076 struct sigaction sa;
1077 int rval = 0;
1078
1079#if defined(__EMX__) && !defined(__KLIBC__) /* bird */
1080 /* The child handler must be turned off here. */
1081 signal (SIGCHLD, SIG_DFL);
1082#endif
1083
1084 memset (&sa, '\0', sizeof sa);
1085 sa.sa_handler = child_handler;
1086 sa.sa_flags = set_handler ? 0 : SA_RESTART;
1087#if defined SIGCHLD
1088 rval = sigaction (SIGCHLD, &sa, NULL);
1089#endif
1090#if defined SIGCLD && SIGCLD != SIGCHLD
1091 rval = sigaction (SIGCLD, &sa, NULL);
1092#endif
1093 if (rval != 0)
1094 fprintf (stderr, "sigaction: %s (%d)\n", strerror (errno), errno);
1095#if defined SIGALRM
1096 if (set_alarm)
1097 {
1098 /* If we're about to enter the read(), set an alarm to wake up in a
1099 second so we can check if the load has dropped and we can start more
1100 work. On the way out, turn off the alarm and set SIG_DFL. */
1101 alarm (set_handler ? 1 : 0);
1102 sa.sa_handler = set_handler ? job_noop : SIG_DFL;
1103 sa.sa_flags = 0;
1104 sigaction (SIGALRM, &sa, NULL);
1105 }
1106#endif
1107}
1108#endif
1109
1110
1111/* Start a job to run the commands specified in CHILD.
1112 CHILD is updated to reflect the commands and ID of the child process.
1113
1114 NOTE: On return fatal signals are blocked! The caller is responsible
1115 for calling `unblock_sigs', once the new child is safely on the chain so
1116 it can be cleaned up in the event of a fatal signal. */
1117
1118static void
1119start_job_command (struct child *child)
1120{
1121#if !defined(_AMIGA) && !defined(WINDOWS32)
1122 static int bad_stdin = -1;
1123#endif
1124 char *p;
1125 /* Must be volatile to silence bogus GCC warning about longjmp/vfork. */
1126 /*volatile*/ int flags;
1127#ifdef VMS
1128 char *argv;
1129#else
1130 char **argv;
1131 char ** volatile volatile_argv;
1132 int volatile volatile_flags;
1133#endif
1134
1135 /* If we have a completely empty commandset, stop now. */
1136 if (!child->command_ptr)
1137 goto next_command;
1138
1139#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
1140 if (child->start_ts == -1)
1141 child->start_ts = nano_timestamp ();
1142#endif
1143
1144 /* Combine the flags parsed for the line itself with
1145 the flags specified globally for this target. */
1146 flags = (child->file->command_flags
1147 | child->file->cmds->lines_flags[child->command_line - 1]);
1148
1149 p = child->command_ptr;
1150 child->noerror = ((flags & COMMANDS_NOERROR) != 0);
1151
1152 while (*p != '\0')
1153 {
1154 if (*p == '@')
1155 flags |= COMMANDS_SILENT;
1156 else if (*p == '+')
1157 flags |= COMMANDS_RECURSE;
1158 else if (*p == '-')
1159 child->noerror = 1;
1160#ifdef CONFIG_WITH_COMMANDS_FUNC
1161 else if (*p == '%')
1162 flags |= COMMAND_GETTER_SKIP_IT;
1163#endif
1164 else if (!isblank ((unsigned char)*p))
1165#ifndef CONFIG_WITH_KMK_BUILTIN
1166 break;
1167#else /* CONFIG_WITH_KMK_BUILTIN */
1168
1169 {
1170 if ( !(flags & COMMANDS_KMK_BUILTIN)
1171 && !strncmp(p, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
1172 flags |= COMMANDS_KMK_BUILTIN;
1173 break;
1174 }
1175#endif /* CONFIG_WITH_KMK_BUILTIN */
1176 ++p;
1177 }
1178
1179 /* Update the file's command flags with any new ones we found. We only
1180 keep the COMMANDS_RECURSE setting. Even this isn't 100% correct; we are
1181 now marking more commands recursive than should be in the case of
1182 multiline define/endef scripts where only one line is marked "+". In
1183 order to really fix this, we'll have to keep a lines_flags for every
1184 actual line, after expansion. */
1185 child->file->cmds->lines_flags[child->command_line - 1]
1186 |= flags & COMMANDS_RECURSE;
1187
1188 /* Figure out an argument list from this command line. */
1189
1190 {
1191 char *end = 0;
1192#ifdef VMS
1193 argv = p;
1194#else
1195 argv = construct_command_argv (p, &end, child->file,
1196 child->file->cmds->lines_flags[child->command_line - 1],
1197 &child->sh_batch_file);
1198#endif
1199 if (end == NULL)
1200 child->command_ptr = NULL;
1201 else
1202 {
1203 *end++ = '\0';
1204 child->command_ptr = end;
1205 }
1206 }
1207
1208 /* If -q was given, say that updating `failed' if there was any text on the
1209 command line, or `succeeded' otherwise. The exit status of 1 tells the
1210 user that -q is saying `something to do'; the exit status for a random
1211 error is 2. */
1212 if (argv != 0 && question_flag && !(flags & COMMANDS_RECURSE))
1213 {
1214#ifndef VMS
1215 free (argv[0]);
1216 free (argv);
1217#endif
1218 child->file->update_status = 1;
1219 notice_finished_file (child->file);
1220 return;
1221 }
1222
1223 if (touch_flag && !(flags & COMMANDS_RECURSE))
1224 {
1225 /* Go on to the next command. It might be the recursive one.
1226 We construct ARGV only to find the end of the command line. */
1227#ifndef VMS
1228 if (argv)
1229 {
1230 free (argv[0]);
1231 free (argv);
1232 }
1233#endif
1234 argv = 0;
1235 }
1236
1237 if (argv == 0)
1238 {
1239 next_command:
1240#ifdef __MSDOS__
1241 execute_by_shell = 0; /* in case construct_command_argv sets it */
1242#endif
1243 /* This line has no commands. Go to the next. */
1244 if (job_next_command (child))
1245 start_job_command (child);
1246 else
1247 {
1248 /* No more commands. Make sure we're "running"; we might not be if
1249 (e.g.) all commands were skipped due to -n. */
1250 set_command_state (child->file, cs_running);
1251 child->file->update_status = 0;
1252 notice_finished_file (child->file);
1253 }
1254 return;
1255 }
1256
1257 /* Print out the command. If silent, we call `message' with null so it
1258 can log the working directory before the command's own error messages
1259 appear. */
1260#ifdef CONFIG_PRETTY_COMMAND_PRINTING
1261 if ( pretty_command_printing
1262 && (just_print_flag || (!(flags & COMMANDS_SILENT) && !silent_flag))
1263 && argv[0][0] != '\0')
1264 {
1265 unsigned i;
1266 for (i = 0; argv[i]; i++)
1267 message (0, "%s'%s'%s", i ? "\t" : "> ", argv[i], argv[i + 1] ? " \\" : "");
1268 }
1269 else
1270#endif /* CONFIG_PRETTY_COMMAND_PRINTING */
1271 message (0, (just_print_flag || (!(flags & COMMANDS_SILENT) && !silent_flag))
1272 ? "%s" : (char *) 0, p);
1273
1274 /* Tell update_goal_chain that a command has been started on behalf of
1275 this target. It is important that this happens here and not in
1276 reap_children (where we used to do it), because reap_children might be
1277 reaping children from a different target. We want this increment to
1278 guaranteedly indicate that a command was started for the dependency
1279 chain (i.e., update_file recursion chain) we are processing. */
1280
1281 ++commands_started;
1282
1283 /* Optimize an empty command. People use this for timestamp rules,
1284 so avoid forking a useless shell. Do this after we increment
1285 commands_started so make still treats this special case as if it
1286 performed some action (makes a difference as to what messages are
1287 printed, etc. */
1288
1289#if !defined(VMS) && !defined(_AMIGA)
1290 if (
1291#if defined __MSDOS__ || defined (__EMX__)
1292 unixy_shell /* the test is complicated and we already did it */
1293#else
1294 (argv[0] && is_bourne_compatible_shell(argv[0]))
1295#endif
1296 && (argv[1] && argv[1][0] == '-'
1297 &&
1298 ((argv[1][1] == 'c' && argv[1][2] == '\0')
1299 ||
1300 (argv[1][1] == 'e' && argv[1][2] == 'c' && argv[1][3] == '\0')))
1301 && (argv[2] && argv[2][0] == ':' && argv[2][1] == '\0')
1302 && argv[3] == NULL)
1303 {
1304 free (argv[0]);
1305 free (argv);
1306 goto next_command;
1307 }
1308#endif /* !VMS && !_AMIGA */
1309
1310 /* If -n was given, recurse to get the next line in the sequence. */
1311
1312 if (just_print_flag && !(flags & COMMANDS_RECURSE))
1313 {
1314#ifndef VMS
1315 free (argv[0]);
1316 free (argv);
1317#endif
1318 goto next_command;
1319 }
1320
1321#ifdef CONFIG_WITH_KMK_BUILTIN
1322 /* If builtin command then pass it on to the builtin shell interpreter. */
1323
1324 if ((flags & COMMANDS_KMK_BUILTIN) && !just_print_flag)
1325 {
1326 int rc;
1327 char **argv_spawn = NULL;
1328 char **p2 = argv;
1329 while (*p2 && strncmp (*p2, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
1330 p2++;
1331 assert (*p2);
1332 set_command_state (child->file, cs_running);
1333 child->pid = 0;
1334 if (p2 != argv)
1335 rc = kmk_builtin_command (*p2, &argv_spawn, &child->pid);
1336 else
1337 {
1338 int argc = 1;
1339 while (argv[argc])
1340 argc++;
1341 rc = kmk_builtin_command_parsed (argc, argv, &argv_spawn, &child->pid);
1342 }
1343
1344# ifndef VMS
1345 free (argv[0]);
1346 free ((char *) argv);
1347# endif
1348
1349 /* synchronous command execution? */
1350 if (!rc && !argv_spawn)
1351 goto next_command;
1352
1353 /* spawned a child? */
1354 if (!rc && child->pid)
1355 {
1356 ++job_counter;
1357 return;
1358 }
1359
1360 /* failure? */
1361 if (rc)
1362 {
1363 child->pid = (pid_t)42424242;
1364 child->status = rc << 8;
1365 child->has_status = 1;
1366 unblock_sigs();
1367 return;
1368 }
1369
1370 /* conditional check == true; kicking off a child (not kmk_builtin_*). */
1371 argv = argv_spawn;
1372 }
1373#endif /* CONFIG_WITH_KMK_BUILTIN */
1374
1375 /* Flush the output streams so they won't have things written twice. */
1376
1377 fflush (stdout);
1378 fflush (stderr);
1379
1380#ifndef VMS
1381#if !defined(WINDOWS32) && !defined(_AMIGA) && !defined(__MSDOS__)
1382
1383 /* Set up a bad standard input that reads from a broken pipe. */
1384
1385 if (bad_stdin == -1)
1386 {
1387 /* Make a file descriptor that is the read end of a broken pipe.
1388 This will be used for some children's standard inputs. */
1389 int pd[2];
1390 if (pipe (pd) == 0)
1391 {
1392 /* Close the write side. */
1393 (void) close (pd[1]);
1394 /* Save the read side. */
1395 bad_stdin = pd[0];
1396
1397 /* Set the descriptor to close on exec, so it does not litter any
1398 child's descriptor table. When it is dup2'd onto descriptor 0,
1399 that descriptor will not close on exec. */
1400 CLOSE_ON_EXEC (bad_stdin);
1401 }
1402 }
1403
1404#endif /* !WINDOWS32 && !_AMIGA && !__MSDOS__ */
1405
1406 /* Decide whether to give this child the `good' standard input
1407 (one that points to the terminal or whatever), or the `bad' one
1408 that points to the read side of a broken pipe. */
1409
1410 child->good_stdin = !good_stdin_used;
1411 if (child->good_stdin)
1412 good_stdin_used = 1;
1413
1414#endif /* !VMS */
1415
1416 child->deleted = 0;
1417
1418#ifndef _AMIGA
1419 /* Set up the environment for the child. */
1420 if (child->environment == 0)
1421 child->environment = target_environment (child->file);
1422#endif
1423
1424#if !defined(__MSDOS__) && !defined(_AMIGA) && !defined(WINDOWS32)
1425
1426#ifndef VMS
1427 /* start_waiting_job has set CHILD->remote if we can start a remote job. */
1428 if (child->remote)
1429 {
1430 int is_remote, id, used_stdin;
1431 if (start_remote_job (argv, child->environment,
1432 child->good_stdin ? 0 : bad_stdin,
1433 &is_remote, &id, &used_stdin))
1434 /* Don't give up; remote execution may fail for various reasons. If
1435 so, simply run the job locally. */
1436 goto run_local;
1437 else
1438 {
1439 if (child->good_stdin && !used_stdin)
1440 {
1441 child->good_stdin = 0;
1442 good_stdin_used = 0;
1443 }
1444 child->remote = is_remote;
1445 child->pid = id;
1446 }
1447 }
1448 else
1449#endif /* !VMS */
1450 {
1451 /* Fork the child process. */
1452
1453 char **parent_environ;
1454
1455 run_local:
1456 block_sigs ();
1457
1458 child->remote = 0;
1459
1460#ifdef VMS
1461 if (!child_execute_job (argv, child)) {
1462 /* Fork failed! */
1463 perror_with_name ("vfork", "");
1464 goto error;
1465 }
1466
1467#else
1468
1469 parent_environ = environ;
1470
1471# ifdef __EMX__
1472 /* If we aren't running a recursive command and we have a jobserver
1473 pipe, close it before exec'ing. */
1474 if (!(flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
1475 {
1476 CLOSE_ON_EXEC (job_fds[0]);
1477 CLOSE_ON_EXEC (job_fds[1]);
1478 }
1479 if (job_rfd >= 0)
1480 CLOSE_ON_EXEC (job_rfd);
1481
1482 /* Never use fork()/exec() here! Use spawn() instead in exec_command() */
1483 child->pid = child_execute_job (child->good_stdin ? 0 : bad_stdin, 1,
1484 argv, child->environment);
1485 if (child->pid < 0)
1486 {
1487 /* spawn failed! */
1488 unblock_sigs ();
1489 perror_with_name ("spawn", "");
1490 goto error;
1491 }
1492
1493 /* undo CLOSE_ON_EXEC() after the child process has been started */
1494 if (!(flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
1495 {
1496 fcntl (job_fds[0], F_SETFD, 0);
1497 fcntl (job_fds[1], F_SETFD, 0);
1498 }
1499 if (job_rfd >= 0)
1500 fcntl (job_rfd, F_SETFD, 0);
1501
1502#else /* !__EMX__ */
1503 volatile_argv = argv; /* shut up gcc */
1504 volatile_flags = flags; /* ditto */
1505
1506 child->pid = vfork ();
1507 environ = parent_environ; /* Restore value child may have clobbered. */
1508 argv = volatile_argv; /* shut up gcc */
1509 if (child->pid == 0)
1510 {
1511 /* We are the child side. */
1512 unblock_sigs ();
1513
1514 /* If we aren't running a recursive command and we have a jobserver
1515 pipe, close it before exec'ing. */
1516 if (!(volatile_flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
1517 {
1518 close (job_fds[0]);
1519 close (job_fds[1]);
1520 }
1521 if (job_rfd >= 0)
1522 close (job_rfd);
1523
1524#ifdef SET_STACK_SIZE
1525 /* Reset limits, if necessary. */
1526 if (stack_limit.rlim_cur)
1527 setrlimit (RLIMIT_STACK, &stack_limit);
1528#endif
1529
1530 child_execute_job (child->good_stdin ? 0 : bad_stdin, 1,
1531 argv, child->environment);
1532 }
1533 else if (child->pid < 0)
1534 {
1535 /* Fork failed! */
1536 unblock_sigs ();
1537 perror_with_name ("vfork", "");
1538 goto error;
1539 }
1540# endif /* !__EMX__ */
1541#endif /* !VMS */
1542 }
1543
1544#else /* __MSDOS__ or Amiga or WINDOWS32 */
1545#ifdef __MSDOS__
1546 {
1547 int proc_return;
1548
1549 block_sigs ();
1550 dos_status = 0;
1551
1552 /* We call `system' to do the job of the SHELL, since stock DOS
1553 shell is too dumb. Our `system' knows how to handle long
1554 command lines even if pipes/redirection is needed; it will only
1555 call COMMAND.COM when its internal commands are used. */
1556 if (execute_by_shell)
1557 {
1558 char *cmdline = argv[0];
1559 /* We don't have a way to pass environment to `system',
1560 so we need to save and restore ours, sigh... */
1561 char **parent_environ = environ;
1562
1563 environ = child->environment;
1564
1565 /* If we have a *real* shell, tell `system' to call
1566 it to do everything for us. */
1567 if (unixy_shell)
1568 {
1569 /* A *real* shell on MSDOS may not support long
1570 command lines the DJGPP way, so we must use `system'. */
1571 cmdline = argv[2]; /* get past "shell -c" */
1572 }
1573
1574 dos_command_running = 1;
1575 proc_return = system (cmdline);
1576 environ = parent_environ;
1577 execute_by_shell = 0; /* for the next time */
1578 }
1579 else
1580 {
1581 dos_command_running = 1;
1582 proc_return = spawnvpe (P_WAIT, argv[0], argv, child->environment);
1583 }
1584
1585 /* Need to unblock signals before turning off
1586 dos_command_running, so that child's signals
1587 will be treated as such (see fatal_error_signal). */
1588 unblock_sigs ();
1589 dos_command_running = 0;
1590
1591 /* If the child got a signal, dos_status has its
1592 high 8 bits set, so be careful not to alter them. */
1593 if (proc_return == -1)
1594 dos_status |= 0xff;
1595 else
1596 dos_status |= (proc_return & 0xff);
1597 ++dead_children;
1598 child->pid = dos_pid++;
1599 }
1600#endif /* __MSDOS__ */
1601#ifdef _AMIGA
1602 amiga_status = MyExecute (argv);
1603
1604 ++dead_children;
1605 child->pid = amiga_pid++;
1606 if (amiga_batch_file)
1607 {
1608 amiga_batch_file = 0;
1609 DeleteFile (amiga_bname); /* Ignore errors. */
1610 }
1611#endif /* Amiga */
1612#ifdef WINDOWS32
1613 {
1614 HANDLE hPID;
1615 char* arg0;
1616
1617 /* make UNC paths safe for CreateProcess -- backslash format */
1618 arg0 = argv[0];
1619 if (arg0 && arg0[0] == '/' && arg0[1] == '/')
1620 for ( ; arg0 && *arg0; arg0++)
1621 if (*arg0 == '/')
1622 *arg0 = '\\';
1623
1624 /* make sure CreateProcess() has Path it needs */
1625 sync_Path_environment();
1626
1627 hPID = process_easy(argv, child->environment);
1628
1629 if (hPID != INVALID_HANDLE_VALUE)
1630 child->pid = (pid_t) hPID;
1631 else {
1632 int i;
1633 unblock_sigs();
1634 fprintf(stderr,
1635 _("process_easy() failed to launch process (e=%ld)\n"),
1636 process_last_err(hPID));
1637 for (i = 0; argv[i]; i++)
1638 fprintf(stderr, "%s ", argv[i]);
1639 fprintf(stderr, _("\nCounted %d args in failed launch\n"), i);
1640 goto error;
1641 }
1642 }
1643#endif /* WINDOWS32 */
1644#endif /* __MSDOS__ or Amiga or WINDOWS32 */
1645
1646 /* Bump the number of jobs started in this second. */
1647 ++job_counter;
1648
1649 /* We are the parent side. Set the state to
1650 say the commands are running and return. */
1651
1652 set_command_state (child->file, cs_running);
1653
1654 /* Free the storage used by the child's argument list. */
1655#ifdef KMK /* leak */
1656 cleanup_argv:
1657#endif
1658#ifndef VMS
1659 free (argv[0]);
1660 free (argv);
1661#endif
1662
1663 return;
1664
1665 error:
1666 child->file->update_status = 2;
1667 notice_finished_file (child->file);
1668#ifdef KMK /* fix leak */
1669 goto cleanup_argv;
1670#else
1671 return;
1672#endif
1673}
1674
1675/* Try to start a child running.
1676 Returns nonzero if the child was started (and maybe finished), or zero if
1677 the load was too high and the child was put on the `waiting_jobs' chain. */
1678
1679static int
1680start_waiting_job (struct child *c)
1681{
1682 struct file *f = c->file;
1683#ifdef DB_KMK
1684 DB (DB_KMK, (_("start_waiting_job %p (`%s') command_flags=%#x slots=%d/%d\n"),
1685 (void *)c, c->file->name, c->file->command_flags, job_slots_used, job_slots));
1686#endif
1687
1688 /* If we can start a job remotely, we always want to, and don't care about
1689 the local load average. We record that the job should be started
1690 remotely in C->remote for start_job_command to test. */
1691
1692 c->remote = start_remote_job_p (1);
1693
1694#ifdef CONFIG_WITH_EXTENDED_NOTPARALLEL
1695 if (c->file->command_flags & COMMANDS_NOTPARALLEL)
1696 {
1697 DB (DB_KMK, (_("not_parallel %d -> %d (file=%p `%s') [start_waiting_job]\n"),
1698 not_parallel, not_parallel + 1, (void *)c->file, c->file->name));
1699 assert(not_parallel >= 0);
1700 ++not_parallel;
1701 }
1702#endif /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
1703
1704 /* If we are running at least one job already and the load average
1705 is too high, make this one wait. */
1706 if (!c->remote
1707#ifdef CONFIG_WITH_EXTENDED_NOTPARALLEL
1708 && ((job_slots_used > 0 && (not_parallel > 0 || load_too_high ()))
1709#else
1710 && ((job_slots_used > 0 && load_too_high ())
1711#endif
1712#ifdef WINDOWS32
1713 || (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
1714#endif
1715 ))
1716 {
1717#ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
1718 /* Put this child on the chain of children waiting for the load average
1719 to go down. */
1720 set_command_state (f, cs_running);
1721 c->next = waiting_jobs;
1722 waiting_jobs = c;
1723
1724#else /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
1725
1726 /* Put this child on the chain of children waiting for the load average
1727 to go down. If not parallel, put it last. */
1728 set_command_state (f, cs_running);
1729 c->next = waiting_jobs;
1730 if (c->next && (c->file->command_flags & COMMANDS_NOTPARALLEL))
1731 {
1732 struct child *prev = waiting_jobs;
1733 while (prev->next)
1734 prev = prev->next;
1735 c->next = 0;
1736 prev->next = c;
1737 }
1738 else /* FIXME: insert after the last node with COMMANDS_NOTPARALLEL set */
1739 waiting_jobs = c;
1740 DB (DB_KMK, (_("queued child %p (`%s')\n"), (void *)c, c->file->name));
1741#endif /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
1742 return 0;
1743 }
1744
1745 /* Start the first command; reap_children will run later command lines. */
1746 start_job_command (c);
1747
1748 switch (f->command_state)
1749 {
1750 case cs_running:
1751 c->next = children;
1752 DB (DB_JOBS, (_("Putting child %p (%s) PID %s%s on the chain.\n"),
1753 (void *)c, c->file->name, pid2str (c->pid),
1754 c->remote ? _(" (remote)") : ""));
1755 children = c;
1756 /* One more job slot is in use. */
1757 ++job_slots_used;
1758 unblock_sigs ();
1759 break;
1760
1761 case cs_not_started:
1762 /* All the command lines turned out to be empty. */
1763 f->update_status = 0;
1764 /* FALLTHROUGH */
1765
1766 case cs_finished:
1767 notice_finished_file (f);
1768 free_child (c);
1769 break;
1770
1771 default:
1772 assert (f->command_state == cs_finished);
1773 break;
1774 }
1775
1776 return 1;
1777}
1778
1779/* Create a `struct child' for FILE and start its commands running. */
1780
1781void
1782new_job (struct file *file)
1783{
1784 struct commands *cmds = file->cmds;
1785 struct child *c;
1786 char **lines;
1787 unsigned int i;
1788
1789 /* Let any previously decided-upon jobs that are waiting
1790 for the load to go down start before this new one. */
1791 start_waiting_jobs ();
1792
1793 /* Reap any children that might have finished recently. */
1794 reap_children (0, 0);
1795
1796 /* Chop the commands up into lines if they aren't already. */
1797 chop_commands (cmds);
1798#ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS
1799 cmds->refs++; /* retain the chopped lines. */
1800#endif
1801
1802 /* Expand the command lines and store the results in LINES. */
1803 lines = xmalloc (cmds->ncommand_lines * sizeof (char *));
1804 for (i = 0; i < cmds->ncommand_lines; ++i)
1805 {
1806 /* Collapse backslash-newline combinations that are inside variable
1807 or function references. These are left alone by the parser so
1808 that they will appear in the echoing of commands (where they look
1809 nice); and collapsed by construct_command_argv when it tokenizes.
1810 But letting them survive inside function invocations loses because
1811 we don't want the functions to see them as part of the text. */
1812
1813 char *in, *out, *ref;
1814
1815 /* IN points to where in the line we are scanning.
1816 OUT points to where in the line we are writing.
1817 When we collapse a backslash-newline combination,
1818 IN gets ahead of OUT. */
1819
1820 in = out = cmds->command_lines[i];
1821 while ((ref = strchr (in, '$')) != 0)
1822 {
1823 ++ref; /* Move past the $. */
1824
1825 if (out != in)
1826 /* Copy the text between the end of the last chunk
1827 we processed (where IN points) and the new chunk
1828 we are about to process (where REF points). */
1829 memmove (out, in, ref - in);
1830
1831 /* Move both pointers past the boring stuff. */
1832 out += ref - in;
1833 in = ref;
1834
1835 if (*ref == '(' || *ref == '{')
1836 {
1837 char openparen = *ref;
1838 char closeparen = openparen == '(' ? ')' : '}';
1839 int count;
1840 char *p;
1841
1842 *out++ = *in++; /* Copy OPENPAREN. */
1843 /* IN now points past the opening paren or brace.
1844 Count parens or braces until it is matched. */
1845 count = 0;
1846 while (*in != '\0')
1847 {
1848 if (*in == closeparen && --count < 0)
1849 break;
1850 else if (*in == '\\' && in[1] == '\n')
1851 {
1852 /* We have found a backslash-newline inside a
1853 variable or function reference. Eat it and
1854 any following whitespace. */
1855
1856 int quoted = 0;
1857 for (p = in - 1; p > ref && *p == '\\'; --p)
1858 quoted = !quoted;
1859
1860 if (quoted)
1861 /* There were two or more backslashes, so this is
1862 not really a continuation line. We don't collapse
1863 the quoting backslashes here as is done in
1864 collapse_continuations, because the line will
1865 be collapsed again after expansion. */
1866 *out++ = *in++;
1867 else
1868 {
1869 /* Skip the backslash, newline and
1870 any following whitespace. */
1871 in = next_token (in + 2);
1872
1873 /* Discard any preceding whitespace that has
1874 already been written to the output. */
1875 while (out > ref
1876 && isblank ((unsigned char)out[-1]))
1877 --out;
1878
1879 /* Replace it all with a single space. */
1880 *out++ = ' ';
1881 }
1882 }
1883 else
1884 {
1885 if (*in == openparen)
1886 ++count;
1887
1888 *out++ = *in++;
1889 }
1890 }
1891 }
1892 }
1893
1894 /* There are no more references in this line to worry about.
1895 Copy the remaining uninteresting text to the output. */
1896 if (out != in)
1897 memmove (out, in, strlen (in) + 1);
1898
1899 /* Finally, expand the line. */
1900 lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i],
1901 file);
1902 }
1903
1904 /* Start the command sequence, record it in a new
1905 `struct child', and add that to the chain. */
1906
1907 c = xcalloc (sizeof (struct child));
1908 c->file = file;
1909 c->command_lines = lines;
1910 c->sh_batch_file = NULL;
1911#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
1912 c->start_ts = -1;
1913#endif
1914
1915 /* Cache dontcare flag because file->dontcare can be changed once we
1916 return. Check dontcare inheritance mechanism for details. */
1917 c->dontcare = file->dontcare;
1918
1919 /* Fetch the first command line to be run. */
1920 job_next_command (c);
1921
1922 /* Wait for a job slot to be freed up. If we allow an infinite number
1923 don't bother; also job_slots will == 0 if we're using the jobserver. */
1924
1925 if (job_slots != 0)
1926 while (job_slots_used == job_slots)
1927 reap_children (1, 0);
1928
1929#ifdef MAKE_JOBSERVER
1930 /* If we are controlling multiple jobs make sure we have a token before
1931 starting the child. */
1932
1933 /* This can be inefficient. There's a decent chance that this job won't
1934 actually have to run any subprocesses: the command script may be empty
1935 or otherwise optimized away. It would be nice if we could defer
1936 obtaining a token until just before we need it, in start_job_command.
1937 To do that we'd need to keep track of whether we'd already obtained a
1938 token (since start_job_command is called for each line of the job, not
1939 just once). Also more thought needs to go into the entire algorithm;
1940 this is where the old parallel job code waits, so... */
1941
1942 else if (job_fds[0] >= 0)
1943 while (1)
1944 {
1945 char token;
1946 int got_token;
1947 int saved_errno;
1948
1949 DB (DB_JOBS, ("Need a job token; we %shave children\n",
1950 children ? "" : "don't "));
1951
1952 /* If we don't already have a job started, use our "free" token. */
1953 if (!jobserver_tokens)
1954 break;
1955
1956 /* Read a token. As long as there's no token available we'll block.
1957 We enable interruptible system calls before the read(2) so that if
1958 we get a SIGCHLD while we're waiting, we'll return with EINTR and
1959 we can process the death(s) and return tokens to the free pool.
1960
1961 Once we return from the read, we immediately reinstate restartable
1962 system calls. This allows us to not worry about checking for
1963 EINTR on all the other system calls in the program.
1964
1965 There is one other twist: there is a span between the time
1966 reap_children() does its last check for dead children and the time
1967 the read(2) call is entered, below, where if a child dies we won't
1968 notice. This is extremely serious as it could cause us to
1969 deadlock, given the right set of events.
1970
1971 To avoid this, we do the following: before we reap_children(), we
1972 dup(2) the read FD on the jobserver pipe. The read(2) call below
1973 uses that new FD. In the signal handler, we close that FD. That
1974 way, if a child dies during the section mentioned above, the
1975 read(2) will be invoked with an invalid FD and will return
1976 immediately with EBADF. */
1977
1978 /* Make sure we have a dup'd FD. */
1979 if (job_rfd < 0)
1980 {
1981 DB (DB_JOBS, ("Duplicate the job FD\n"));
1982 job_rfd = dup (job_fds[0]);
1983 }
1984
1985 /* Reap anything that's currently waiting. */
1986 reap_children (0, 0);
1987
1988 /* Kick off any jobs we have waiting for an opportunity that
1989 can run now (ie waiting for load). */
1990 start_waiting_jobs ();
1991
1992 /* If our "free" slot has become available, use it; we don't need an
1993 actual token. */
1994 if (!jobserver_tokens)
1995 break;
1996
1997 /* There must be at least one child already, or we have no business
1998 waiting for a token. */
1999 if (!children)
2000 fatal (NILF, "INTERNAL: no children as we go to sleep on read\n");
2001
2002 /* Set interruptible system calls, and read() for a job token. */
2003 set_child_handler_action_flags (1, waiting_jobs != NULL);
2004 got_token = read (job_rfd, &token, 1);
2005 saved_errno = errno;
2006 set_child_handler_action_flags (0, waiting_jobs != NULL);
2007
2008 /* If we got one, we're done here. */
2009 if (got_token == 1)
2010 {
2011 DB (DB_JOBS, (_("Obtained token for child %p (%s).\n"),
2012 (void *)c, c->file->name));
2013 break;
2014 }
2015
2016 /* If the error _wasn't_ expected (EINTR or EBADF), punt. Otherwise,
2017 go back and reap_children(), and try again. */
2018 errno = saved_errno;
2019 if (errno != EINTR && errno != EBADF)
2020 pfatal_with_name (_("read jobs pipe"));
2021 if (errno == EBADF)
2022 DB (DB_JOBS, ("Read returned EBADF.\n"));
2023 }
2024#endif
2025
2026 ++jobserver_tokens;
2027
2028 /* The job is now primed. Start it running.
2029 (This will notice if there is in fact no recipe.) */
2030 if (cmds->fileinfo.filenm)
2031 DB (DB_BASIC, (_("Invoking recipe from %s:%lu to update target `%s'.\n"),
2032 cmds->fileinfo.filenm, cmds->fileinfo.lineno,
2033 c->file->name));
2034 else
2035 DB (DB_BASIC, (_("Invoking builtin recipe to update target `%s'.\n"),
2036 c->file->name));
2037
2038
2039 start_waiting_job (c);
2040
2041#ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
2042 if (job_slots == 1 || not_parallel)
2043 /* Since there is only one job slot, make things run linearly.
2044 Wait for the child to die, setting the state to `cs_finished'. */
2045 while (file->command_state == cs_running)
2046 reap_children (1, 0);
2047
2048#else /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
2049
2050 if (job_slots == 1 || not_parallel < 0)
2051 {
2052 /* Since there is only one job slot, make things run linearly.
2053 Wait for the child to die, setting the state to `cs_finished'. */
2054 while (file->command_state == cs_running)
2055 reap_children (1, 0);
2056 }
2057 else if (not_parallel > 0)
2058 {
2059 /* wait for all live children to finish and then continue
2060 with the not-parallel child(s). FIXME: this loop could be better? */
2061 while (file->command_state == cs_running
2062 && (children != 0 || shell_function_pid != 0) /* reap_child condition */
2063 && not_parallel > 0)
2064 reap_children (1, 0);
2065 }
2066#endif /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
2067
2068 return;
2069}
2070
2071
2072/* Move CHILD's pointers to the next command for it to execute.
2073 Returns nonzero if there is another command. */
2074
2075static int
2076job_next_command (struct child *child)
2077{
2078 while (child->command_ptr == 0 || *child->command_ptr == '\0')
2079 {
2080 /* There are no more lines in the expansion of this line. */
2081 if (child->command_line == child->file->cmds->ncommand_lines)
2082 {
2083 /* There are no more lines to be expanded. */
2084 child->command_ptr = 0;
2085 return 0;
2086 }
2087 else
2088 /* Get the next line to run. */
2089 child->command_ptr = child->command_lines[child->command_line++];
2090 }
2091 return 1;
2092}
2093
2094/* Determine if the load average on the system is too high to start a new job.
2095 The real system load average is only recomputed once a second. However, a
2096 very parallel make can easily start tens or even hundreds of jobs in a
2097 second, which brings the system to its knees for a while until that first
2098 batch of jobs clears out.
2099
2100 To avoid this we use a weighted algorithm to try to account for jobs which
2101 have been started since the last second, and guess what the load average
2102 would be now if it were computed.
2103
2104 This algorithm was provided by Thomas Riedl <thomas.riedl@siemens.com>,
2105 who writes:
2106
2107! calculate something load-oid and add to the observed sys.load,
2108! so that latter can catch up:
2109! - every job started increases jobctr;
2110! - every dying job decreases a positive jobctr;
2111! - the jobctr value gets zeroed every change of seconds,
2112! after its value*weight_b is stored into the 'backlog' value last_sec
2113! - weight_a times the sum of jobctr and last_sec gets
2114! added to the observed sys.load.
2115!
2116! The two weights have been tried out on 24 and 48 proc. Sun Solaris-9
2117! machines, using a several-thousand-jobs-mix of cpp, cc, cxx and smallish
2118! sub-shelled commands (rm, echo, sed...) for tests.
2119! lowering the 'direct influence' factor weight_a (e.g. to 0.1)
2120! resulted in significant excession of the load limit, raising it
2121! (e.g. to 0.5) took bad to small, fast-executing jobs and didn't
2122! reach the limit in most test cases.
2123!
2124! lowering the 'history influence' weight_b (e.g. to 0.1) resulted in
2125! exceeding the limit for longer-running stuff (compile jobs in
2126! the .5 to 1.5 sec. range),raising it (e.g. to 0.5) overrepresented
2127! small jobs' effects.
2128
2129 */
2130
2131#define LOAD_WEIGHT_A 0.25
2132#define LOAD_WEIGHT_B 0.25
2133
2134static int
2135load_too_high (void)
2136{
2137#if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__) || defined(__HAIKU__)
2138 return 1;
2139#else
2140 static double last_sec;
2141 static time_t last_now;
2142 double load, guess;
2143 time_t now;
2144
2145#ifdef WINDOWS32
2146 /* sub_proc.c cannot wait for more than MAXIMUM_WAIT_OBJECTS children */
2147 if (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
2148 return 1;
2149#endif
2150
2151 if (max_load_average < 0)
2152 return 0;
2153
2154 /* Find the real system load average. */
2155 make_access ();
2156 if (getloadavg (&load, 1) != 1)
2157 {
2158 static int lossage = -1;
2159 /* Complain only once for the same error. */
2160 if (lossage == -1 || errno != lossage)
2161 {
2162 if (errno == 0)
2163 /* An errno value of zero means getloadavg is just unsupported. */
2164 error (NILF,
2165 _("cannot enforce load limits on this operating system"));
2166 else
2167 perror_with_name (_("cannot enforce load limit: "), "getloadavg");
2168 }
2169 lossage = errno;
2170 load = 0;
2171 }
2172 user_access ();
2173
2174 /* If we're in a new second zero the counter and correct the backlog
2175 value. Only keep the backlog for one extra second; after that it's 0. */
2176 now = time (NULL);
2177 if (last_now < now)
2178 {
2179 if (last_now == now - 1)
2180 last_sec = LOAD_WEIGHT_B * job_counter;
2181 else
2182 last_sec = 0.0;
2183
2184 job_counter = 0;
2185 last_now = now;
2186 }
2187
2188 /* Try to guess what the load would be right now. */
2189 guess = load + (LOAD_WEIGHT_A * (job_counter + last_sec));
2190
2191 DB (DB_JOBS, ("Estimated system load = %f (actual = %f) (max requested = %f)\n",
2192 guess, load, max_load_average));
2193
2194 return guess >= max_load_average;
2195#endif
2196}
2197
2198/* Start jobs that are waiting for the load to be lower. */
2199
2200void
2201start_waiting_jobs (void)
2202{
2203 struct child *job;
2204
2205 if (waiting_jobs == 0)
2206 return;
2207
2208 do
2209 {
2210 /* Check for recently deceased descendants. */
2211 reap_children (0, 0);
2212
2213 /* Take a job off the waiting list. */
2214 job = waiting_jobs;
2215 waiting_jobs = job->next;
2216
2217#ifdef CONFIG_WITH_EXTENDED_NOTPARALLEL
2218 /* If it's a not-parallel job, we've already counted it once
2219 when it was queued in start_waiting_job, so decrement
2220 before sending it to start_waiting_job again. */
2221 if (job->file->command_flags & COMMANDS_NOTPARALLEL)
2222 {
2223 DB (DB_KMK, (_("not_parallel %d -> %d (file=%p `%s') [start_waiting_jobs]\n"),
2224 not_parallel, not_parallel - 1, (void *) job->file, job->file->name));
2225 assert(not_parallel > 0);
2226 --not_parallel;
2227 }
2228#endif /* CONFIG_WITH_EXTENDED_NOTPARALLEL */
2229
2230 /* Try to start that job. We break out of the loop as soon
2231 as start_waiting_job puts one back on the waiting list. */
2232 }
2233 while (start_waiting_job (job) && waiting_jobs != 0);
2234
2235 return;
2236}
2237
2238
2239#ifndef WINDOWS32
2240
2241/* EMX: Start a child process. This function returns the new pid. */
2242# if defined __EMX__
2243int
2244child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp)
2245{
2246 int pid;
2247 /* stdin_fd == 0 means: nothing to do for stdin;
2248 stdout_fd == 1 means: nothing to do for stdout */
2249 int save_stdin = (stdin_fd != 0) ? dup (0) : 0;
2250 int save_stdout = (stdout_fd != 1) ? dup (1): 1;
2251
2252 /* < 0 only if dup() failed */
2253 if (save_stdin < 0)
2254 fatal (NILF, _("no more file handles: could not duplicate stdin\n"));
2255 if (save_stdout < 0)
2256 fatal (NILF, _("no more file handles: could not duplicate stdout\n"));
2257
2258 /* Close unnecessary file handles for the child. */
2259 if (save_stdin != 0)
2260 CLOSE_ON_EXEC (save_stdin);
2261 if (save_stdout != 1)
2262 CLOSE_ON_EXEC (save_stdout);
2263
2264 /* Connect the pipes to the child process. */
2265 if (stdin_fd != 0)
2266 (void) dup2 (stdin_fd, 0);
2267 if (stdout_fd != 1)
2268 (void) dup2 (stdout_fd, 1);
2269
2270 /* stdin_fd and stdout_fd must be closed on exit because we are
2271 still in the parent process */
2272 if (stdin_fd != 0)
2273 CLOSE_ON_EXEC (stdin_fd);
2274 if (stdout_fd != 1)
2275 CLOSE_ON_EXEC (stdout_fd);
2276
2277 /* Run the command. */
2278 pid = exec_command (argv, envp);
2279
2280 /* Restore stdout/stdin of the parent and close temporary FDs. */
2281 if (stdin_fd != 0)
2282 {
2283 if (dup2 (save_stdin, 0) != 0)
2284 fatal (NILF, _("Could not restore stdin\n"));
2285 else
2286 close (save_stdin);
2287 }
2288
2289 if (stdout_fd != 1)
2290 {
2291 if (dup2 (save_stdout, 1) != 1)
2292 fatal (NILF, _("Could not restore stdout\n"));
2293 else
2294 close (save_stdout);
2295 }
2296
2297 return pid;
2298}
2299
2300#elif !defined (_AMIGA) && !defined (__MSDOS__) && !defined (VMS)
2301
2302/* UNIX:
2303 Replace the current process with one executing the command in ARGV.
2304 STDIN_FD and STDOUT_FD are used as the process's stdin and stdout; ENVP is
2305 the environment of the new program. This function does not return. */
2306void
2307child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp)
2308{
2309 if (stdin_fd != 0)
2310 (void) dup2 (stdin_fd, 0);
2311 if (stdout_fd != 1)
2312 (void) dup2 (stdout_fd, 1);
2313 if (stdin_fd != 0)
2314 (void) close (stdin_fd);
2315 if (stdout_fd != 1)
2316 (void) close (stdout_fd);
2317
2318 /* Run the command. */
2319 exec_command (argv, envp);
2320}
2321#endif /* !AMIGA && !__MSDOS__ && !VMS */
2322#endif /* !WINDOWS32 */
2323
2324
2325#ifndef _AMIGA
2326/* Replace the current process with one running the command in ARGV,
2327 with environment ENVP. This function does not return. */
2328
2329/* EMX: This function returns the pid of the child process. */
2330# ifdef __EMX__
2331int
2332# else
2333void
2334# endif
2335exec_command (char **argv, char **envp)
2336{
2337#ifdef VMS
2338 /* to work around a problem with signals and execve: ignore them */
2339#ifdef SIGCHLD
2340 signal (SIGCHLD,SIG_IGN);
2341#endif
2342 /* Run the program. */
2343 execve (argv[0], argv, envp);
2344 perror_with_name ("execve: ", argv[0]);
2345 _exit (EXIT_FAILURE);
2346#else
2347#ifdef WINDOWS32
2348 HANDLE hPID;
2349 HANDLE hWaitPID;
2350 int err = 0;
2351 int exit_code = EXIT_FAILURE;
2352
2353 /* make sure CreateProcess() has Path it needs */
2354 sync_Path_environment();
2355
2356 /* launch command */
2357 hPID = process_easy(argv, envp);
2358
2359 /* make sure launch ok */
2360 if (hPID == INVALID_HANDLE_VALUE)
2361 {
2362 int i;
2363 fprintf(stderr,
2364 _("process_easy() failed to launch process (e=%ld)\n"),
2365 process_last_err(hPID));
2366 for (i = 0; argv[i]; i++)
2367 fprintf(stderr, "%s ", argv[i]);
2368 fprintf(stderr, _("\nCounted %d args in failed launch\n"), i);
2369 exit(EXIT_FAILURE);
2370 }
2371
2372 /* wait and reap last child */
2373 hWaitPID = process_wait_for_any();
2374 while (hWaitPID)
2375 {
2376 /* was an error found on this process? */
2377 err = process_last_err(hWaitPID);
2378
2379 /* get exit data */
2380 exit_code = process_exit_code(hWaitPID);
2381
2382 if (err)
2383 fprintf(stderr, "make (e=%d, rc=%d): %s",
2384 err, exit_code, map_windows32_error_to_string(err));
2385
2386 /* cleanup process */
2387 process_cleanup(hWaitPID);
2388
2389 /* expect to find only last pid, warn about other pids reaped */
2390 if (hWaitPID == hPID)
2391 break;
2392 else
2393 {
2394 char *pidstr = xstrdup (pid2str ((pid_t)hWaitPID));
2395
2396 fprintf(stderr,
2397 _("make reaped child pid %s, still waiting for pid %s\n"),
2398 pidstr, pid2str ((pid_t)hPID));
2399 free (pidstr);
2400 }
2401 }
2402
2403 /* return child's exit code as our exit code */
2404 exit(exit_code);
2405
2406#else /* !WINDOWS32 */
2407
2408# ifdef __EMX__
2409 int pid;
2410# endif
2411
2412 /* Be the user, permanently. */
2413 child_access ();
2414
2415# ifdef __EMX__
2416
2417 /* Run the program. */
2418 pid = spawnvpe (P_NOWAIT, argv[0], argv, envp);
2419
2420 if (pid >= 0)
2421 return pid;
2422
2423 /* the file might have a strange shell extension */
2424 if (errno == ENOENT)
2425 errno = ENOEXEC;
2426
2427# else
2428
2429 /* Run the program. */
2430 environ = envp;
2431 execvp (argv[0], argv);
2432
2433# endif /* !__EMX__ */
2434
2435 switch (errno)
2436 {
2437 case ENOENT:
2438 error (NILF, _("%s: Command not found"), argv[0]);
2439 break;
2440 case ENOEXEC:
2441 {
2442 /* The file is not executable. Try it as a shell script. */
2443 extern char *getenv ();
2444 char *shell;
2445 char **new_argv;
2446 int argc;
2447 int i=1;
2448
2449# ifdef __EMX__
2450 /* Do not use $SHELL from the environment */
2451 struct variable *p = lookup_variable ("SHELL", 5);
2452 if (p)
2453 shell = p->value;
2454 else
2455 shell = 0;
2456# else
2457 shell = getenv ("SHELL");
2458# endif
2459 if (shell == 0)
2460 shell = default_shell;
2461
2462 argc = 1;
2463 while (argv[argc] != 0)
2464 ++argc;
2465
2466# ifdef __EMX__
2467 if (!unixy_shell)
2468 ++argc;
2469# endif
2470
2471 new_argv = alloca ((1 + argc + 1) * sizeof (char *));
2472 new_argv[0] = shell;
2473
2474# ifdef __EMX__
2475 if (!unixy_shell)
2476 {
2477 new_argv[1] = "/c";
2478 ++i;
2479 --argc;
2480 }
2481# endif
2482
2483 new_argv[i] = argv[0];
2484 while (argc > 0)
2485 {
2486 new_argv[i + argc] = argv[argc];
2487 --argc;
2488 }
2489
2490# ifdef __EMX__
2491 pid = spawnvpe (P_NOWAIT, shell, new_argv, envp);
2492 if (pid >= 0)
2493 break;
2494# else
2495 execvp (shell, new_argv);
2496# endif
2497 if (errno == ENOENT)
2498 error (NILF, _("%s: Shell program not found"), shell);
2499 else
2500 perror_with_name ("execvp: ", shell);
2501 break;
2502 }
2503
2504# ifdef __EMX__
2505 case EINVAL:
2506 /* this nasty error was driving me nuts :-( */
2507 error (NILF, _("spawnvpe: environment space might be exhausted"));
2508 /* FALLTHROUGH */
2509# endif
2510
2511 default:
2512 perror_with_name ("execvp: ", argv[0]);
2513 break;
2514 }
2515
2516# ifdef __EMX__
2517 return pid;
2518# else
2519 _exit (127);
2520# endif
2521#endif /* !WINDOWS32 */
2522#endif /* !VMS */
2523}
2524#else /* On Amiga */
2525void exec_command (char **argv)
2526{
2527 MyExecute (argv);
2528}
2529
2530void clean_tmp (void)
2531{
2532 DeleteFile (amiga_bname);
2533}
2534
2535#endif /* On Amiga */
2536
2537
2538#ifndef VMS
2539/* Figure out the argument list necessary to run LINE as a command. Try to
2540 avoid using a shell. This routine handles only ' quoting, and " quoting
2541 when no backslash, $ or ` characters are seen in the quotes. Starting
2542 quotes may be escaped with a backslash. If any of the characters in
2543 sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
2544 is the first word of a line, the shell is used.
2545
2546 If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
2547 If *RESTP is NULL, newlines will be ignored.
2548
2549 SHELL is the shell to use, or nil to use the default shell.
2550 IFS is the value of $IFS, or nil (meaning the default).
2551
2552 FLAGS is the value of lines_flags for this command line. It is
2553 used in the WINDOWS32 port to check whether + or $(MAKE) were found
2554 in this command line, in which case the effect of just_print_flag
2555 is overridden. */
2556
2557static char **
2558construct_command_argv_internal (char *line, char **restp, char *shell,
2559 char *shellflags, char *ifs, int flags,
2560 char **batch_filename_ptr)
2561{
2562#ifdef __MSDOS__
2563 /* MSDOS supports both the stock DOS shell and ports of Unixy shells.
2564 We call `system' for anything that requires ``slow'' processing,
2565 because DOS shells are too dumb. When $SHELL points to a real
2566 (unix-style) shell, `system' just calls it to do everything. When
2567 $SHELL points to a DOS shell, `system' does most of the work
2568 internally, calling the shell only for its internal commands.
2569 However, it looks on the $PATH first, so you can e.g. have an
2570 external command named `mkdir'.
2571
2572 Since we call `system', certain characters and commands below are
2573 actually not specific to COMMAND.COM, but to the DJGPP implementation
2574 of `system'. In particular:
2575
2576 The shell wildcard characters are in DOS_CHARS because they will
2577 not be expanded if we call the child via `spawnXX'.
2578
2579 The `;' is in DOS_CHARS, because our `system' knows how to run
2580 multiple commands on a single line.
2581
2582 DOS_CHARS also include characters special to 4DOS/NDOS, so we
2583 won't have to tell one from another and have one more set of
2584 commands and special characters. */
2585 static char sh_chars_dos[] = "*?[];|<>%^&()";
2586 static char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls",
2587 "copy", "ctty", "date", "del", "dir", "echo",
2588 "erase", "exit", "for", "goto", "if", "md",
2589 "mkdir", "path", "pause", "prompt", "rd",
2590 "rmdir", "rem", "ren", "rename", "set",
2591 "shift", "time", "type", "ver", "verify",
2592 "vol", ":", 0 };
2593
2594 static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^";
2595 static char *sh_cmds_sh[] = { "cd", "echo", "eval", "exec", "exit", "login",
2596 "logout", "set", "umask", "wait", "while",
2597 "for", "case", "if", ":", ".", "break",
2598 "continue", "export", "read", "readonly",
2599 "shift", "times", "trap", "switch", "unset",
2600 "ulimit", 0 };
2601
2602 char *sh_chars;
2603 char **sh_cmds;
2604#elif defined (__EMX__)
2605 static char sh_chars_dos[] = "*?[];|<>%^&()";
2606 static char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls",
2607 "copy", "ctty", "date", "del", "dir", "echo",
2608 "erase", "exit", "for", "goto", "if", "md",
2609 "mkdir", "path", "pause", "prompt", "rd",
2610 "rmdir", "rem", "ren", "rename", "set",
2611 "shift", "time", "type", "ver", "verify",
2612 "vol", ":", 0 };
2613
2614 static char sh_chars_os2[] = "*?[];|<>%^()\"'&";
2615 static char *sh_cmds_os2[] = { "call", "cd", "chcp", "chdir", "cls", "copy",
2616 "date", "del", "detach", "dir", "echo",
2617 "endlocal", "erase", "exit", "for", "goto", "if",
2618 "keys", "md", "mkdir", "move", "path", "pause",
2619 "prompt", "rd", "rem", "ren", "rename", "rmdir",
2620 "set", "setlocal", "shift", "start", "time",
2621 "type", "ver", "verify", "vol", ":", 0 };
2622
2623 static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^~'";
2624 static char *sh_cmds_sh[] = { "echo", "cd", "eval", "exec", "exit", "login",
2625 "logout", "set", "umask", "wait", "while",
2626 "for", "case", "if", ":", ".", "break",
2627 "continue", "export", "read", "readonly",
2628 "shift", "times", "trap", "switch", "unset",
2629 0 };
2630 char *sh_chars;
2631 char **sh_cmds;
2632
2633#elif defined (_AMIGA)
2634 static char sh_chars[] = "#;\"|<>()?*$`";
2635 static char *sh_cmds[] = { "cd", "eval", "if", "delete", "echo", "copy",
2636 "rename", "set", "setenv", "date", "makedir",
2637 "skip", "else", "endif", "path", "prompt",
2638 "unset", "unsetenv", "version",
2639 0 };
2640#elif defined (WINDOWS32)
2641 static char sh_chars_dos[] = "\"|&<>";
2642 static char *sh_cmds_dos[] = { "assoc", "break", "call", "cd", "chcp",
2643 "chdir", "cls", "color", "copy", "ctty",
2644 "date", "del", "dir", "echo", "echo.",
2645 "endlocal", "erase", "exit", "for", "ftype",
2646 "goto", "if", "if", "md", "mkdir", "path",
2647 "pause", "prompt", "rd", "rem", "ren",
2648 "rename", "rmdir", "set", "setlocal",
2649 "shift", "time", "title", "type", "ver",
2650 "verify", "vol", ":", 0 };
2651 static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^";
2652 static char *sh_cmds_sh[] = { "cd", "eval", "exec", "exit", "login",
2653 "logout", "set", "umask", "wait", "while", "for",
2654 "case", "if", ":", ".", "break", "continue",
2655 "export", "read", "readonly", "shift", "times",
2656 "trap", "switch", "test",
2657#ifdef BATCH_MODE_ONLY_SHELL
2658 "echo",
2659#endif
2660 0 };
2661 char* sh_chars;
2662 char** sh_cmds;
2663#elif defined(__riscos__)
2664 static char sh_chars[] = "";
2665 static char *sh_cmds[] = { 0 };
2666#else /* must be UNIX-ish */
2667 static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^~!"; /* kmk: +_sh */
2668 static char *sh_cmds_sh[] = { ".", ":", "break", "case", "cd", "continue", /* kmk: +_sh */
2669 "eval", "exec", "exit", "export", "for", "if",
2670 "login", "logout", "read", "readonly", "set",
2671 "shift", "switch", "test", "times", "trap",
2672 "ulimit", "umask", "unset", "wait", "while", 0 };
2673# ifdef HAVE_DOS_PATHS
2674 /* This is required if the MSYS/Cygwin ports (which do not define
2675 WINDOWS32) are compiled with HAVE_DOS_PATHS defined, which uses
2676 sh_chars_sh[] directly (see below). */
2677 static char *sh_chars_sh = sh_chars;
2678# endif /* HAVE_DOS_PATHS */
2679 char* sh_chars = sh_chars_sh; /* kmk: +_sh */
2680 char** sh_cmds = sh_cmds_sh; /* kmk: +_sh */
2681#endif
2682#ifdef KMK
2683 static char sh_chars_kash[] = "#;*?[]&|<>(){}$`^~!"; /* note: no \" - good idea? */
2684 static char *sh_cmds_kash[] = {
2685 ".", ":", "break", "case", "cd", "continue",
2686 "echo", "eval", "exec", "exit", "export", "for", "if",
2687 "login", "logout", "read", "readonly", "set",
2688 "shift", "switch", "test", "times", "trap",
2689 "umask", "wait", "while", 0
2690 };
2691 int is_kmk_shell = 0;
2692#endif
2693 int i;
2694 char *p;
2695 char *ap;
2696 char *end;
2697 int instring, word_has_equals, seen_nonequals, last_argument_was_empty;
2698 char **new_argv = 0;
2699 char *argstr = 0;
2700#ifdef WINDOWS32
2701 int slow_flag = 0;
2702
2703 if (!unixy_shell) {
2704 sh_cmds = sh_cmds_dos;
2705 sh_chars = sh_chars_dos;
2706 } else {
2707 sh_cmds = sh_cmds_sh;
2708 sh_chars = sh_chars_sh;
2709 }
2710#endif /* WINDOWS32 */
2711
2712 if (restp != NULL)
2713 *restp = NULL;
2714
2715 /* Make sure not to bother processing an empty line. */
2716 while (isblank ((unsigned char)*line))
2717 ++line;
2718 if (*line == '\0')
2719 return 0;
2720
2721 /* See if it is safe to parse commands internally. */
2722#ifdef KMK /* kmk_ash and kmk_kash are both fine, kmk_ash is the default btw. */
2723 if (shell == 0)
2724 {
2725 is_kmk_shell = 1;
2726 shell = (char *)get_default_kbuild_shell ();
2727 }
2728 else if (!strcmp (shell, get_default_kbuild_shell()))
2729 is_kmk_shell = 1;
2730 else
2731 {
2732 const char *psz = strstr (shell, "/kmk_ash");
2733 if (psz)
2734 psz += sizeof ("/kmk_ash") - 1;
2735 else
2736 {
2737 psz = strstr (shell, "/kmk_kash");
2738 if (psz)
2739 psz += sizeof ("/kmk_kash") - 1;
2740 }
2741# if defined (__OS2__) || defined (_WIN32) || defined (WINDOWS32)
2742 is_kmk_shell = psz && (*psz == '\0' || !stricmp (psz, ".exe"));
2743# else
2744 is_kmk_shell = psz && *psz == '\0';
2745# endif
2746 }
2747 if (is_kmk_shell)
2748 {
2749 sh_chars = sh_chars_kash;
2750 sh_cmds = sh_cmds_kash;
2751 }
2752#else /* !KMK */
2753 if (shell == 0)
2754 shell = default_shell;
2755#endif /* !KMK */
2756#ifdef WINDOWS32
2757 else if (strcmp (shell, default_shell))
2758 {
2759 char *s1 = _fullpath (NULL, shell, 0);
2760 char *s2 = _fullpath (NULL, default_shell, 0);
2761
2762 slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : ""));
2763
2764 if (s1)
2765 free (s1);
2766 if (s2)
2767 free (s2);
2768 }
2769 if (slow_flag)
2770 goto slow;
2771#else /* not WINDOWS32 */
2772#if defined (__MSDOS__) || defined (__EMX__)
2773 else if (strcasecmp (shell, default_shell))
2774 {
2775 extern int _is_unixy_shell (const char *_path);
2776
2777 DB (DB_BASIC, (_("$SHELL changed (was `%s', now `%s')\n"),
2778 default_shell, shell));
2779 unixy_shell = _is_unixy_shell (shell);
2780 /* we must allocate a copy of shell: construct_command_argv() will free
2781 * shell after this function returns. */
2782 default_shell = xstrdup (shell);
2783 }
2784 if (unixy_shell)
2785 {
2786 sh_chars = sh_chars_sh;
2787 sh_cmds = sh_cmds_sh;
2788 }
2789 else
2790 {
2791 sh_chars = sh_chars_dos;
2792 sh_cmds = sh_cmds_dos;
2793# ifdef __EMX__
2794 if (_osmode == OS2_MODE)
2795 {
2796 sh_chars = sh_chars_os2;
2797 sh_cmds = sh_cmds_os2;
2798 }
2799# endif
2800 }
2801#else /* !__MSDOS__ */
2802 else if (strcmp (shell, default_shell))
2803 goto slow;
2804#endif /* !__MSDOS__ && !__EMX__ */
2805#endif /* not WINDOWS32 */
2806
2807 if (ifs != 0)
2808 for (ap = ifs; *ap != '\0'; ++ap)
2809 if (*ap != ' ' && *ap != '\t' && *ap != '\n')
2810 goto slow;
2811
2812 if (shellflags != 0)
2813 if (shellflags[0] != '-'
2814 || ((shellflags[1] != 'c' || shellflags[2] != '\0')
2815 && (shellflags[1] != 'e' || shellflags[2] != 'c' || shellflags[3] != '\0')))
2816 goto slow;
2817
2818 i = strlen (line) + 1;
2819
2820 /* More than 1 arg per character is impossible. */
2821 new_argv = xmalloc (i * sizeof (char *));
2822
2823 /* All the args can fit in a buffer as big as LINE is. */
2824 ap = new_argv[0] = argstr = xmalloc (i);
2825 end = ap + i;
2826
2827 /* I is how many complete arguments have been found. */
2828 i = 0;
2829 instring = word_has_equals = seen_nonequals = last_argument_was_empty = 0;
2830 for (p = line; *p != '\0'; ++p)
2831 {
2832 assert (ap <= end);
2833
2834 if (instring)
2835 {
2836 /* Inside a string, just copy any char except a closing quote
2837 or a backslash-newline combination. */
2838 if (*p == instring)
2839 {
2840 instring = 0;
2841 if (ap == new_argv[0] || *(ap-1) == '\0')
2842 last_argument_was_empty = 1;
2843 }
2844 else if (*p == '\\' && p[1] == '\n')
2845 {
2846 /* Backslash-newline is handled differently depending on what
2847 kind of string we're in: inside single-quoted strings you
2848 keep them; in double-quoted strings they disappear.
2849 For DOS/Windows/OS2, if we don't have a POSIX shell,
2850 we keep the pre-POSIX behavior of removing the
2851 backslash-newline. */
2852 if (instring == '"'
2853#if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32)
2854 || !unixy_shell
2855#endif
2856 )
2857 ++p;
2858 else
2859 {
2860 *(ap++) = *(p++);
2861 *(ap++) = *p;
2862 }
2863 }
2864 else if (*p == '\n' && restp != NULL)
2865 {
2866 /* End of the command line. */
2867 *restp = p;
2868 goto end_of_line;
2869 }
2870 /* Backslash, $, and ` are special inside double quotes.
2871 If we see any of those, punt.
2872 But on MSDOS, if we use COMMAND.COM, double and single
2873 quotes have the same effect. */
2874 else if (instring == '"' && strchr ("\\$`", *p) != 0 && unixy_shell)
2875 goto slow;
2876 else
2877 *ap++ = *p;
2878 }
2879 else if (strchr (sh_chars, *p) != 0)
2880#ifdef KMK
2881 {
2882 /* Tilde is only special if at the start of a path spec,
2883 i.e. don't get excited when we by 8.3 files on windows. */
2884 if ( *p == '~'
2885 && p > line
2886 && !isspace (p[-1])
2887 && p[-1] != '='
2888 && p[-1] != ':'
2889 && p[-1] != '"'
2890 && p[-1] != '\'')
2891 *ap++ = *p;
2892 else
2893 /* Not inside a string, but it's a special char. */
2894 goto slow;
2895 }
2896#else /* !KMK */
2897 /* Not inside a string, but it's a special char. */
2898 goto slow;
2899#endif /* !KMK */
2900 else if (one_shell && *p == '\n')
2901 /* In .ONESHELL mode \n is a separator like ; or && */
2902 goto slow;
2903#ifdef __MSDOS__
2904 else if (*p == '.' && p[1] == '.' && p[2] == '.' && p[3] != '.')
2905 /* `...' is a wildcard in DJGPP. */
2906 goto slow;
2907#endif
2908 else
2909 /* Not a special char. */
2910 switch (*p)
2911 {
2912 case '=':
2913 /* Equals is a special character in leading words before the
2914 first word with no equals sign in it. This is not the case
2915 with sh -k, but we never get here when using nonstandard
2916 shell flags. */
2917 if (! seen_nonequals && unixy_shell)
2918 goto slow;
2919 word_has_equals = 1;
2920 *ap++ = '=';
2921 break;
2922
2923 case '\\':
2924 /* Backslash-newline has special case handling, ref POSIX.
2925 We're in the fastpath, so emulate what the shell would do. */
2926 if (p[1] == '\n')
2927 {
2928 /* Throw out the backslash and newline. */
2929 ++p;
2930
2931 /* If there's nothing in this argument yet, skip any
2932 whitespace before the start of the next word. */
2933 if (ap == new_argv[i])
2934 p = next_token (p + 1) - 1;
2935 }
2936 else if (p[1] != '\0')
2937 {
2938#ifdef HAVE_DOS_PATHS
2939 /* Only remove backslashes before characters special to Unixy
2940 shells. All other backslashes are copied verbatim, since
2941 they are probably DOS-style directory separators. This
2942 still leaves a small window for problems, but at least it
2943 should work for the vast majority of naive users. */
2944
2945#ifdef __MSDOS__
2946 /* A dot is only special as part of the "..."
2947 wildcard. */
2948 if (strneq (p + 1, ".\\.\\.", 5))
2949 {
2950 *ap++ = '.';
2951 *ap++ = '.';
2952 p += 4;
2953 }
2954 else
2955#endif
2956 if (p[1] != '\\' && p[1] != '\''
2957 && !isspace ((unsigned char)p[1])
2958# ifdef KMK
2959 && strchr (sh_chars, p[1]) == 0
2960 && (p[1] != '"' || !unixy_shell))
2961# else
2962 && strchr (sh_chars_sh, p[1]) == 0)
2963# endif
2964 /* back up one notch, to copy the backslash */
2965 --p;
2966#endif /* HAVE_DOS_PATHS */
2967
2968 /* Copy and skip the following char. */
2969 *ap++ = *++p;
2970 }
2971 break;
2972
2973 case '\'':
2974 case '"':
2975 instring = *p;
2976 break;
2977
2978 case '\n':
2979 if (restp != NULL)
2980 {
2981 /* End of the command line. */
2982 *restp = p;
2983 goto end_of_line;
2984 }
2985 else
2986 /* Newlines are not special. */
2987 *ap++ = '\n';
2988 break;
2989
2990 case ' ':
2991 case '\t':
2992 /* We have the end of an argument.
2993 Terminate the text of the argument. */
2994 *ap++ = '\0';
2995 new_argv[++i] = ap;
2996 last_argument_was_empty = 0;
2997
2998 /* Update SEEN_NONEQUALS, which tells us if every word
2999 heretofore has contained an `='. */
3000 seen_nonequals |= ! word_has_equals;
3001 if (word_has_equals && ! seen_nonequals)
3002 /* An `=' in a word before the first
3003 word without one is magical. */
3004 goto slow;
3005 word_has_equals = 0; /* Prepare for the next word. */
3006
3007 /* If this argument is the command name,
3008 see if it is a built-in shell command.
3009 If so, have the shell handle it. */
3010 if (i == 1)
3011 {
3012 register int j;
3013 for (j = 0; sh_cmds[j] != 0; ++j)
3014 {
3015 if (streq (sh_cmds[j], new_argv[0]))
3016 goto slow;
3017# ifdef __EMX__
3018 /* Non-Unix shells are case insensitive. */
3019 if (!unixy_shell
3020 && strcasecmp (sh_cmds[j], new_argv[0]) == 0)
3021 goto slow;
3022# endif
3023 }
3024 }
3025
3026 /* Ignore multiple whitespace chars. */
3027 p = next_token (p) - 1;
3028 break;
3029
3030 default:
3031 *ap++ = *p;
3032 break;
3033 }
3034 }
3035 end_of_line:
3036
3037 if (instring)
3038 /* Let the shell deal with an unterminated quote. */
3039 goto slow;
3040
3041 /* Terminate the last argument and the argument list. */
3042
3043 *ap = '\0';
3044 if (new_argv[i][0] != '\0' || last_argument_was_empty)
3045 ++i;
3046 new_argv[i] = 0;
3047
3048 if (i == 1)
3049 {
3050 register int j;
3051 for (j = 0; sh_cmds[j] != 0; ++j)
3052 if (streq (sh_cmds[j], new_argv[0]))
3053 goto slow;
3054 }
3055
3056 if (new_argv[0] == 0)
3057 {
3058 /* Line was empty. */
3059 free (argstr);
3060 free (new_argv);
3061 return 0;
3062 }
3063
3064 return new_argv;
3065
3066 slow:;
3067 /* We must use the shell. */
3068
3069 if (new_argv != 0)
3070 {
3071 /* Free the old argument list we were working on. */
3072 free (argstr);
3073 free (new_argv);
3074 }
3075
3076#ifdef __MSDOS__
3077 execute_by_shell = 1; /* actually, call `system' if shell isn't unixy */
3078#endif
3079
3080#ifdef _AMIGA
3081 {
3082 char *ptr;
3083 char *buffer;
3084 char *dptr;
3085
3086 buffer = xmalloc (strlen (line)+1);
3087
3088 ptr = line;
3089 for (dptr=buffer; *ptr; )
3090 {
3091 if (*ptr == '\\' && ptr[1] == '\n')
3092 ptr += 2;
3093 else if (*ptr == '@') /* Kludge: multiline commands */
3094 {
3095 ptr += 2;
3096 *dptr++ = '\n';
3097 }
3098 else
3099 *dptr++ = *ptr++;
3100 }
3101 *dptr = 0;
3102
3103 new_argv = xmalloc (2 * sizeof (char *));
3104 new_argv[0] = buffer;
3105 new_argv[1] = 0;
3106 }
3107#else /* Not Amiga */
3108#ifdef WINDOWS32
3109 /*
3110 * Not eating this whitespace caused things like
3111 *
3112 * sh -c "\n"
3113 *
3114 * which gave the shell fits. I think we have to eat
3115 * whitespace here, but this code should be considered
3116 * suspicious if things start failing....
3117 */
3118
3119 /* Make sure not to bother processing an empty line. */
3120 while (isspace ((unsigned char)*line))
3121 ++line;
3122 if (*line == '\0')
3123 return 0;
3124#endif /* WINDOWS32 */
3125
3126 {
3127 /* SHELL may be a multi-word command. Construct a command line
3128 "$(SHELL) $(.SHELLFLAGS) LINE", with all special chars in LINE escaped.
3129 Then recurse, expanding this command line to get the final
3130 argument list. */
3131
3132 unsigned int shell_len = strlen (shell);
3133 unsigned int line_len = strlen (line);
3134 unsigned int sflags_len = strlen (shellflags);
3135 char *command_ptr = NULL; /* used for batch_mode_shell mode */
3136 char *new_line;
3137
3138# ifdef __EMX__ /* is this necessary? */
3139 if (!unixy_shell)
3140 shellflags[0] = '/'; /* "/c" */
3141# endif
3142
3143 /* In .ONESHELL mode we are allowed to throw the entire current
3144 recipe string at a single shell and trust that the user
3145 has configured the shell and shell flags, and formatted
3146 the string, appropriately. */
3147 if (one_shell)
3148 {
3149 /* If the shell is Bourne compatible, we must remove and ignore
3150 interior special chars [@+-] because they're meaningless to
3151 the shell itself. If, however, we're in .ONESHELL mode and
3152 have changed SHELL to something non-standard, we should
3153 leave those alone because they could be part of the
3154 script. In this case we must also leave in place
3155 any leading [@+-] for the same reason. */
3156
3157 /* Remove and ignore interior prefix chars [@+-] because they're
3158 meaningless given a single shell. */
3159#if defined __MSDOS__ || defined (__EMX__)
3160 if (unixy_shell) /* the test is complicated and we already did it */
3161#else
3162 if (is_bourne_compatible_shell(shell))
3163#endif
3164 {
3165 const char *f = line;
3166 char *t = line;
3167
3168 /* Copy the recipe, removing and ignoring interior prefix chars
3169 [@+-]: they're meaningless in .ONESHELL mode. */
3170 while (f[0] != '\0')
3171 {
3172 int esc = 0;
3173
3174 /* This is the start of a new recipe line.
3175 Skip whitespace and prefix characters. */
3176 while (isblank (*f) || *f == '-' || *f == '@' || *f == '+')
3177 ++f;
3178
3179 /* Copy until we get to the next logical recipe line. */
3180 while (*f != '\0')
3181 {
3182 *(t++) = *(f++);
3183 if (f[-1] == '\\')
3184 esc = !esc;
3185 else
3186 {
3187 /* On unescaped newline, we're done with this line. */
3188 if (f[-1] == '\n' && ! esc)
3189 break;
3190
3191 /* Something else: reset the escape sequence. */
3192 esc = 0;
3193 }
3194 }
3195 }
3196 *t = '\0';
3197 }
3198
3199 new_argv = xmalloc (4 * sizeof (char *));
3200 new_argv[0] = xstrdup(shell);
3201 new_argv[1] = xstrdup(shellflags);
3202 new_argv[2] = line;
3203 new_argv[3] = NULL;
3204 return new_argv;
3205 }
3206
3207 new_line = alloca (shell_len + 1 + sflags_len + 1
3208 + (line_len*2) + 1);
3209 ap = new_line;
3210 memcpy (ap, shell, shell_len);
3211 ap += shell_len;
3212 *(ap++) = ' ';
3213 memcpy (ap, shellflags, sflags_len);
3214 ap += sflags_len;
3215 *(ap++) = ' ';
3216 command_ptr = ap;
3217 for (p = line; *p != '\0'; ++p)
3218 {
3219 if (restp != NULL && *p == '\n')
3220 {
3221 *restp = p;
3222 break;
3223 }
3224 else if (*p == '\\' && p[1] == '\n')
3225 {
3226 /* POSIX says we keep the backslash-newline. If we don't have a
3227 POSIX shell on DOS/Windows/OS2, mimic the pre-POSIX behavior
3228 and remove the backslash/newline. */
3229#if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32)
3230# define PRESERVE_BSNL unixy_shell
3231#else
3232# define PRESERVE_BSNL 1
3233#endif
3234 if (PRESERVE_BSNL)
3235 {
3236 *(ap++) = '\\';
3237 /* Only non-batch execution needs another backslash,
3238 because it will be passed through a recursive
3239 invocation of this function. */
3240 if (!batch_mode_shell)
3241 *(ap++) = '\\';
3242 *(ap++) = '\n';
3243 }
3244 ++p;
3245 continue;
3246 }
3247
3248 /* DOS shells don't know about backslash-escaping. */
3249 if (unixy_shell && !batch_mode_shell &&
3250 (*p == '\\' || *p == '\'' || *p == '"'
3251 || isspace ((unsigned char)*p)
3252 || strchr (sh_chars, *p) != 0))
3253 *ap++ = '\\';
3254#ifdef __MSDOS__
3255 else if (unixy_shell && strneq (p, "...", 3))
3256 {
3257 /* The case of `...' wildcard again. */
3258 strcpy (ap, "\\.\\.\\");
3259 ap += 5;
3260 p += 2;
3261 }
3262#endif
3263 *ap++ = *p;
3264 }
3265 if (ap == new_line + shell_len + sflags_len + 2)
3266 /* Line was empty. */
3267 return 0;
3268 *ap = '\0';
3269
3270#ifdef WINDOWS32
3271 /* Some shells do not work well when invoked as 'sh -c xxx' to run a
3272 command line (e.g. Cygnus GNUWIN32 sh.exe on WIN32 systems). In these
3273 cases, run commands via a script file. */
3274 if (just_print_flag && !(flags & COMMANDS_RECURSE)) {
3275 /* Need to allocate new_argv, although it's unused, because
3276 start_job_command will want to free it and its 0'th element. */
3277 new_argv = xmalloc(2 * sizeof (char *));
3278 new_argv[0] = xstrdup ("");
3279 new_argv[1] = NULL;
3280 } else if ((no_default_sh_exe || batch_mode_shell) && batch_filename_ptr) {
3281 int temp_fd;
3282 FILE* batch = NULL;
3283 int id = GetCurrentProcessId();
3284 PATH_VAR(fbuf);
3285
3286 /* create a file name */
3287 sprintf(fbuf, "make%d", id);
3288 *batch_filename_ptr = create_batch_file (fbuf, unixy_shell, &temp_fd);
3289
3290 DB (DB_JOBS, (_("Creating temporary batch file %s\n"),
3291 *batch_filename_ptr));
3292
3293 /* Create a FILE object for the batch file, and write to it the
3294 commands to be executed. Put the batch file in TEXT mode. */
3295 _setmode (temp_fd, _O_TEXT);
3296 batch = _fdopen (temp_fd, "wt");
3297 if (!unixy_shell)
3298 fputs ("@echo off\n", batch);
3299 fputs (command_ptr, batch);
3300 fputc ('\n', batch);
3301 fclose (batch);
3302 DB (DB_JOBS, (_("Batch file contents:%s\n\t%s\n"),
3303 !unixy_shell ? "\n\t@echo off" : "", command_ptr));
3304
3305 /* create argv */
3306 new_argv = xmalloc(3 * sizeof (char *));
3307 if (unixy_shell) {
3308 new_argv[0] = xstrdup (shell);
3309 new_argv[1] = *batch_filename_ptr; /* only argv[0] gets freed later */
3310 } else {
3311 new_argv[0] = xstrdup (*batch_filename_ptr);
3312 new_argv[1] = NULL;
3313 }
3314 new_argv[2] = NULL;
3315 } else
3316#endif /* WINDOWS32 */
3317
3318 if (unixy_shell)
3319 new_argv = construct_command_argv_internal (new_line, 0, 0, 0, 0, flags, 0);
3320
3321#ifdef __EMX__
3322 else if (!unixy_shell)
3323 {
3324 /* new_line is local, must not be freed therefore
3325 We use line here instead of new_line because we run the shell
3326 manually. */
3327 size_t line_len = strlen (line);
3328 char *p = new_line;
3329 char *q = new_line;
3330 memcpy (new_line, line, line_len + 1);
3331 /* Replace all backslash-newline combination and also following tabs.
3332 Important: stop at the first '\n' because that's what the loop above
3333 did. The next line starting at restp[0] will be executed during the
3334 next call of this function. */
3335 while (*q != '\0' && *q != '\n')
3336 {
3337 if (q[0] == '\\' && q[1] == '\n')
3338 q += 2; /* remove '\\' and '\n' */
3339 else
3340 *p++ = *q++;
3341 }
3342 *p = '\0';
3343
3344# ifndef NO_CMD_DEFAULT
3345 if (strnicmp (new_line, "echo", 4) == 0
3346 && (new_line[4] == ' ' || new_line[4] == '\t'))
3347 {
3348 /* the builtin echo command: handle it separately */
3349 size_t echo_len = line_len - 5;
3350 char *echo_line = new_line + 5;
3351
3352 /* special case: echo 'x="y"'
3353 cmd works this way: a string is printed as is, i.e., no quotes
3354 are removed. But autoconf uses a command like echo 'x="y"' to
3355 determine whether make works. autoconf expects the output x="y"
3356 so we will do exactly that.
3357 Note: if we do not allow cmd to be the default shell
3358 we do not need this kind of voodoo */
3359 if (echo_line[0] == '\''
3360 && echo_line[echo_len - 1] == '\''
3361 && strncmp (echo_line + 1, "ac_maketemp=",
3362 strlen ("ac_maketemp=")) == 0)
3363 {
3364 /* remove the enclosing quotes */
3365 memmove (echo_line, echo_line + 1, echo_len - 2);
3366 echo_line[echo_len - 2] = '\0';
3367 }
3368 }
3369# endif
3370
3371 {
3372 /* Let the shell decide what to do. Put the command line into the
3373 2nd command line argument and hope for the best ;-) */
3374 size_t sh_len = strlen (shell);
3375
3376 /* exactly 3 arguments + NULL */
3377 new_argv = xmalloc (4 * sizeof (char *));
3378 /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times
3379 the trailing '\0' */
3380 new_argv[0] = xmalloc (sh_len + line_len + 5);
3381 memcpy (new_argv[0], shell, sh_len + 1);
3382 new_argv[1] = new_argv[0] + sh_len + 1;
3383 memcpy (new_argv[1], "/c", 3);
3384 new_argv[2] = new_argv[1] + 3;
3385 memcpy (new_argv[2], new_line, line_len + 1);
3386 new_argv[3] = NULL;
3387 }
3388 }
3389#elif defined(__MSDOS__)
3390 else
3391 {
3392 /* With MSDOS shells, we must construct the command line here
3393 instead of recursively calling ourselves, because we
3394 cannot backslash-escape the special characters (see above). */
3395 new_argv = xmalloc (sizeof (char *));
3396 line_len = strlen (new_line) - shell_len - sflags_len - 2;
3397 new_argv[0] = xmalloc (line_len + 1);
3398 strncpy (new_argv[0],
3399 new_line + shell_len + sflags_len + 2, line_len);
3400 new_argv[0][line_len] = '\0';
3401 }
3402#else
3403 else
3404 fatal (NILF, _("%s (line %d) Bad shell context (!unixy && !batch_mode_shell)\n"),
3405 __FILE__, __LINE__);
3406#endif
3407 }
3408#endif /* ! AMIGA */
3409
3410 return new_argv;
3411}
3412#endif /* !VMS */
3413
3414/* Figure out the argument list necessary to run LINE as a command. Try to
3415 avoid using a shell. This routine handles only ' quoting, and " quoting
3416 when no backslash, $ or ` characters are seen in the quotes. Starting
3417 quotes may be escaped with a backslash. If any of the characters in
3418 sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
3419 is the first word of a line, the shell is used.
3420
3421 If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
3422 If *RESTP is NULL, newlines will be ignored.
3423
3424 FILE is the target whose commands these are. It is used for
3425 variable expansion for $(SHELL) and $(IFS). */
3426
3427char **
3428construct_command_argv (char *line, char **restp, struct file *file,
3429 int cmd_flags, char **batch_filename_ptr)
3430{
3431 char *shell, *ifs, *shellflags;
3432 char **argv;
3433
3434#ifdef VMS
3435 char *cptr;
3436 int argc;
3437
3438 argc = 0;
3439 cptr = line;
3440 for (;;)
3441 {
3442 while ((*cptr != 0)
3443 && (isspace ((unsigned char)*cptr)))
3444 cptr++;
3445 if (*cptr == 0)
3446 break;
3447 while ((*cptr != 0)
3448 && (!isspace((unsigned char)*cptr)))
3449 cptr++;
3450 argc++;
3451 }
3452
3453 argv = xmalloc (argc * sizeof (char *));
3454 if (argv == 0)
3455 abort ();
3456
3457 cptr = line;
3458 argc = 0;
3459 for (;;)
3460 {
3461 while ((*cptr != 0)
3462 && (isspace ((unsigned char)*cptr)))
3463 cptr++;
3464 if (*cptr == 0)
3465 break;
3466 DB (DB_JOBS, ("argv[%d] = [%s]\n", argc, cptr));
3467 argv[argc++] = cptr;
3468 while ((*cptr != 0)
3469 && (!isspace((unsigned char)*cptr)))
3470 cptr++;
3471 if (*cptr != 0)
3472 *cptr++ = 0;
3473 }
3474#else
3475 {
3476 /* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
3477 int save = warn_undefined_variables_flag;
3478 warn_undefined_variables_flag = 0;
3479
3480 shell = allocated_variable_expand_for_file ("$(SHELL)", file);
3481#ifdef WINDOWS32
3482 /*
3483 * Convert to forward slashes so that construct_command_argv_internal()
3484 * is not confused.
3485 */
3486 if (shell) {
3487 char *p = w32ify (shell, 0);
3488 strcpy (shell, p);
3489 }
3490#endif
3491#ifdef __EMX__
3492 {
3493 static const char *unixroot = NULL;
3494 static const char *last_shell = "";
3495 static int init = 0;
3496 if (init == 0)
3497 {
3498 unixroot = getenv ("UNIXROOT");
3499 /* unixroot must be NULL or not empty */
3500 if (unixroot && unixroot[0] == '\0') unixroot = NULL;
3501 init = 1;
3502 }
3503
3504 /* if we have an unixroot drive and if shell is not default_shell
3505 (which means it's either cmd.exe or the test has already been
3506 performed) and if shell is an absolute path without drive letter,
3507 try whether it exists e.g.: if "/bin/sh" does not exist use
3508 "$UNIXROOT/bin/sh" instead. */
3509 if (unixroot && shell && strcmp (shell, last_shell) != 0
3510 && (shell[0] == '/' || shell[0] == '\\'))
3511 {
3512 /* trying a new shell, check whether it exists */
3513 size_t size = strlen (shell);
3514 char *buf = xmalloc (size + 7);
3515 memcpy (buf, shell, size);
3516 memcpy (buf + size, ".exe", 5); /* including the trailing '\0' */
3517 if (access (shell, F_OK) != 0 && access (buf, F_OK) != 0)
3518 {
3519 /* try the same for the unixroot drive */
3520 memmove (buf + 2, buf, size + 5);
3521 buf[0] = unixroot[0];
3522 buf[1] = unixroot[1];
3523 if (access (buf, F_OK) == 0)
3524 /* we have found a shell! */
3525 /* free(shell); */
3526 shell = buf;
3527 else
3528 free (buf);
3529 }
3530 else
3531 free (buf);
3532 }
3533 }
3534#endif /* __EMX__ */
3535
3536 shellflags = allocated_variable_expand_for_file ("$(.SHELLFLAGS)", file);
3537 ifs = allocated_variable_expand_for_file ("$(IFS)", file);
3538
3539 warn_undefined_variables_flag = save;
3540 }
3541
3542#ifdef CONFIG_WITH_KMK_BUILTIN
3543 /* If it's a kmk_builtin command, make sure we're treated like a
3544 unix shell and and don't get batch files. */
3545 if ( ( !unixy_shell
3546 || batch_mode_shell
3547# ifdef WINDOWS32
3548 || no_default_sh_exe
3549# endif
3550 )
3551 && line
3552 && !strncmp(line, "kmk_builtin_", sizeof("kmk_builtin_") - 1))
3553 {
3554 int saved_batch_mode_shell = batch_mode_shell;
3555 int saved_unixy_shell = unixy_shell;
3556# ifdef WINDOWS32
3557 int saved_no_default_sh_exe = no_default_sh_exe;
3558 no_default_sh_exe = 0;
3559# endif
3560 unixy_shell = 1;
3561 batch_mode_shell = 0;
3562 argv = construct_command_argv_internal (line, restp, shell, shellflags, ifs,
3563 cmd_flags, batch_filename_ptr);
3564 batch_mode_shell = saved_batch_mode_shell;
3565 unixy_shell = saved_unixy_shell;
3566# ifdef WINDOWS32
3567 no_default_sh_exe = saved_no_default_sh_exe;
3568# endif
3569 }
3570 else
3571#endif /* CONFIG_WITH_KMK_BUILTIN */
3572 argv = construct_command_argv_internal (line, restp, shell, shellflags, ifs,
3573 cmd_flags, batch_filename_ptr);
3574
3575 free (shell);
3576 free (shellflags);
3577 free (ifs);
3578#endif /* !VMS */
3579 return argv;
3580}
3581
3582
3583#if !defined(HAVE_DUP2) && !defined(_AMIGA)
3584int
3585dup2 (int old, int new)
3586{
3587 int fd;
3588
3589 (void) close (new);
3590 fd = dup (old);
3591 if (fd != new)
3592 {
3593 (void) close (fd);
3594 errno = EMFILE;
3595 return -1;
3596 }
3597
3598 return fd;
3599}
3600#endif /* !HAVE_DUP2 && !_AMIGA */
3601
3602#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
3603/* Prints the time elapsed while executing the commands for the given job. */
3604void print_job_time (struct child *c)
3605{
3606 if ( !handling_fatal_signal
3607 && print_time_min != -1
3608 && c->start_ts != -1)
3609 {
3610 big_int elapsed = nano_timestamp () - c->start_ts;
3611 if (elapsed >= print_time_min * BIG_INT_C(1000000000))
3612 {
3613 char buf[64];
3614 int len = format_elapsed_nano (buf, sizeof (buf), elapsed);
3615 if (len > print_time_width)
3616 print_time_width = len;
3617 message (1, _("%*s - %s"), print_time_width, buf, c ->file->name);
3618 }
3619 }
3620}
3621#endif
3622
3623/* On VMS systems, include special VMS functions. */
3624
3625#ifdef VMS
3626#include "vmsjobs.c"
3627#endif
Note: See TracBrowser for help on using the repository browser.