VirtualBox

source: kBuild/trunk/src/kmk/job.c@ 2846

Last change on this file since 2846 was 2846, checked in by bird, 9 years ago

fixes

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette