VirtualBox

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

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

kmk build fixes for win.amd64.

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