1 /* Job execution and handling for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96,97,99 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
33 /* Default shell to use. */
35 char *default_shell
= "sh.exe";
36 int no_default_sh_exe
= 1;
37 int batch_mode_shell
= 1;
40 char default_shell
[] = "";
41 extern int MyExecute (char **);
44 /* The default shell is a pointer so we can change it if Makefile
45 says so. It is without an explicit path so we get a chance
46 to search the $PATH for it (since MSDOS doesn't have standard
47 directories we could trust). */
48 char *default_shell
= "command.com";
49 # else /* __MSDOS__ */
52 char default_shell
[] = "";
54 char default_shell
[] = "/bin/sh";
56 # endif /* __MSDOS__ */
57 int batch_mode_shell
= 0;
59 #endif /* WINDOWS32 */
63 static int execute_by_shell
;
64 static int dos_pid
= 123;
66 int dos_command_running
;
67 #endif /* __MSDOS__ */
70 # include <proto/dos.h>
71 static int amiga_pid
= 123;
72 static int amiga_status
;
73 static char amiga_bname
[32];
74 static int amiga_batch_file
;
79 # include <processes.h>
82 # include <lib$routines.h>
89 # include "sub_proc.h"
91 # include "pathstuff.h"
92 #endif /* WINDOWS32 */
97 # include <sys/file.h>
100 #if defined (HAVE_SYS_WAIT_H) || defined (HAVE_UNION_WAIT)
101 # include <sys/wait.h>
105 # define WAIT_NOHANG(status) waitpid (-1, (status), WNOHANG)
106 #else /* Don't have waitpid. */
111 # define WAIT_NOHANG(status) wait3 ((status), WNOHANG, (struct rusage *) 0)
112 # endif /* Have wait3. */
113 #endif /* Have waitpid. */
115 #if !defined (wait) && !defined (POSIX)
119 #ifndef HAVE_UNION_WAIT
124 # define WTERMSIG(x) ((x) & 0x7f)
127 # define WCOREDUMP(x) ((x) & 0x80)
130 # define WEXITSTATUS(x) (((x) >> 8) & 0xff)
133 # define WIFSIGNALED(x) (WTERMSIG (x) != 0)
136 # define WIFEXITED(x) (WTERMSIG (x) == 0)
139 #else /* Have `union wait'. */
141 # define WAIT_T union wait
143 # define WTERMSIG(x) ((x).w_termsig)
146 # define WCOREDUMP(x) ((x).w_coredump)
149 # define WEXITSTATUS(x) ((x).w_retcode)
152 # define WIFSIGNALED(x) (WTERMSIG(x) != 0)
155 # define WIFEXITED(x) (WTERMSIG(x) == 0)
158 #endif /* Don't have `union wait'. */
160 /* How to set close-on-exec for a file descriptor. */
163 # define CLOSE_ON_EXEC(_d)
166 # define FD_CLOEXEC 1
168 # define CLOSE_ON_EXEC(_d) (void) fcntl ((_d), F_SETFD, FD_CLOEXEC)
172 static int vms_jobsefnmask
= 0;
175 #ifndef HAVE_UNISTD_H
177 extern int execve ();
178 extern void _exit ();
180 extern int geteuid ();
181 extern int getegid ();
182 extern int setgid ();
183 extern int getgid ();
187 extern char *allocated_variable_expand_for_file
PARAMS ((char *line
, struct file
*file
));
189 extern int getloadavg
PARAMS ((double loadavg
[], int nelem
));
190 extern int start_remote_job
PARAMS ((char **argv
, char **envp
, int stdin_fd
,
191 int *is_remote
, int *id_ptr
, int *used_stdin
));
192 extern int start_remote_job_p
PARAMS ((int));
193 extern int remote_status
PARAMS ((int *exit_code_ptr
, int *signal_ptr
,
194 int *coredump_ptr
, int block
));
196 RETSIGTYPE child_handler
PARAMS ((int));
197 static void free_child
PARAMS ((struct child
*));
198 static void start_job_command
PARAMS ((struct child
*child
));
199 static int load_too_high
PARAMS ((void));
200 static int job_next_command
PARAMS ((struct child
*));
201 static int start_waiting_job
PARAMS ((struct child
*));
203 static void vmsWaitForChildren
PARAMS ((int *));
206 /* Chain of all live (or recently deceased) children. */
208 struct child
*children
= 0;
210 /* Number of children currently running. */
212 unsigned int job_slots_used
= 0;
214 /* Nonzero if the `good' standard input is in use. */
216 static int good_stdin_used
= 0;
218 /* Chain of children waiting to run until the load average goes down. */
220 static struct child
*waiting_jobs
= 0;
222 /* Non-zero if we use a *real* shell (always so on Unix). */
229 * The macro which references this function is defined in make.h.
231 int w32_kill(int pid
, int sig
)
233 return ((process_kill(pid
, sig
) == TRUE
) ? 0 : -1);
235 #endif /* WINDOWS32 */
237 /* Write an error message describing the exit status given in
238 EXIT_CODE, EXIT_SIG, and COREDUMP, for the target TARGET_NAME.
239 Append "(ignored)" if IGNORED is nonzero. */
242 child_error (target_name
, exit_code
, exit_sig
, coredump
, ignored
)
244 int exit_code
, exit_sig
, coredump
;
247 if (ignored
&& silent_flag
)
251 if (!(exit_code
& 1))
253 (ignored
? _("*** [%s] Error 0x%x (ignored)")
254 : _("*** [%s] Error 0x%x")),
255 target_name
, exit_code
);
258 error (NILF
, ignored
? _("[%s] Error %d (ignored)") :
259 _("*** [%s] Error %d"),
260 target_name
, exit_code
);
262 error (NILF
, "*** [%s] %s%s",
263 target_name
, strsignal (exit_sig
),
264 coredump
? _(" (core dumped)") : "");
269 /* Wait for nchildren children to terminate */
271 vmsWaitForChildren(int *status
)
275 if (!vms_jobsefnmask
)
281 *status
= sys$
wflor (32, vms_jobsefnmask
);
286 /* Set up IO redirection. */
289 vms_redirect (desc
, fname
, ibuf
)
290 struct dsc$descriptor_s
*desc
;
295 extern char *vmsify ();
298 while (isspace ((unsigned char)*ibuf
))
301 while (*ibuf
&& !isspace ((unsigned char)*ibuf
))
304 if (strcmp (fptr
, "/dev/null") != 0)
306 strcpy (fname
, vmsify (fptr
, 0));
307 if (strchr (fname
, '.') == 0)
310 desc
->dsc$w_length
= strlen(fname
);
311 desc
->dsc$a_pointer
= fname
;
312 desc
->dsc$b_dtype
= DSC$K_DTYPE_T
;
313 desc
->dsc$b_class
= DSC$K_CLASS_S
;
316 printf (_("Warning: Empty redirection\n"));
322 found apostrophe at (p-1)
324 inc p until after closing apostrophe. */
327 handle_apos (char *p
)
332 #define SEPCHARS ",/()= "
352 fprintf (stderr
, _("Syntax error, still inside '\"'\n"));
359 if (strchr (SEPCHARS
, *p
))
380 /* Handle a dead child. This handler may or may not ever be installed.
382 If we're using the jobserver feature, we need it. First, installing it
383 ensures the read will interrupt on SIGCHLD. Second, we close the dup'd
384 read FD to ensure we don't enter another blocking read without reaping all
385 the dead children. In this case we don't need the dead_children count.
387 If we don't have either waitpid or wait3, then make is unreliable, but we
388 use the dead_children count to reap children as best we can. */
390 static unsigned int dead_children
= 0;
404 DB (DB_JOBS
, (_("Got a SIGCHLD; %u unreaped children.\n"), dead_children
));
408 extern int shell_function_pid
, shell_function_completed
;
410 /* Reap all dead children, storing the returned status and the new command
411 state (`cs_finished') in the `file' member of the `struct child' for the
412 dead child, and removing the child from the chain. In addition, if BLOCK
413 nonzero, we block in this function until we've reaped at least one
414 complete child, waiting for it to die if necessary. If ERR is nonzero,
415 print an error message first. */
418 reap_children (block
, err
)
422 /* Initially, assume we have some. */
426 # define REAP_MORE reap_more
428 # define REAP_MORE dead_children
433 We have at least one child outstanding OR a shell function in progress,
435 We're blocking for a complete child OR there are more children to reap
437 we'll keep reaping children. */
439 while ((children
!= 0 || shell_function_pid
!= 0)
440 && (block
|| REAP_MORE
))
444 int exit_code
, exit_sig
, coredump
;
445 register struct child
*lastc
, *c
;
447 int any_remote
, any_local
;
451 /* We might block for a while, so let the user know why. */
453 error (NILF
, _("*** Waiting for unfinished jobs...."));
456 /* We have one less dead child to reap. As noted in
457 child_handler() above, this count is completely unimportant for
458 all modern, POSIX-y systems that support wait3() or waitpid().
459 The rest of this comment below applies only to early, broken
460 pre-POSIX systems. We keep the count only because... it's there...
462 The test and decrement are not atomic; if it is compiled into:
463 register = dead_children - 1;
464 dead_children = register;
465 a SIGCHLD could come between the two instructions.
466 child_handler increments dead_children.
467 The second instruction here would lose that increment. But the
468 only effect of dead_children being wrong is that we might wait
469 longer than necessary to reap a child, and lose some parallelism;
470 and we might print the "Waiting for unfinished jobs" message above
471 when not necessary. */
473 if (dead_children
> 0)
477 any_local
= shell_function_pid
!= 0;
478 for (c
= children
; c
!= 0; c
= c
->next
)
480 any_remote
|= c
->remote
;
481 any_local
|= ! c
->remote
;
482 DB (DB_JOBS
, (_("Live child 0x%08lx (%s) PID %ld %s\n"),
483 (unsigned long int) c
, c
->file
->name
,
484 (long) c
->pid
, c
->remote
? _(" (remote)") : ""));
490 /* First, check for remote children. */
492 pid
= remote_status (&exit_code
, &exit_sig
, &coredump
, 0);
497 /* We got a remote child. */
501 /* A remote status command failed miserably. Punt. */
503 pfatal_with_name ("remote_status");
507 /* No remote children. Check for local children. */
508 #if !defined(__MSDOS__) && !defined(_AMIGA) && !defined(WINDOWS32)
512 vmsWaitForChildren (&status
);
517 pid
= WAIT_NOHANG (&status
);
520 pid
= wait (&status
);
528 /* The wait*() failed miserably. Punt. */
529 pfatal_with_name ("wait");
533 /* We got a child exit; chop the status word up. */
534 exit_code
= WEXITSTATUS (status
);
535 exit_sig
= WIFSIGNALED (status
) ? WTERMSIG (status
) : 0;
536 coredump
= WCOREDUMP (status
);
540 /* No local children are dead. */
543 if (!block
|| !any_remote
)
546 /* Now try a blocking wait for a remote child. */
547 pid
= remote_status (&exit_code
, &exit_sig
, &coredump
, 1);
549 goto remote_status_lose
;
551 /* No remote children either. Finally give up. */
554 /* We got a remote child. */
557 #endif /* !__MSDOS__, !Amiga, !WINDOWS32. */
560 /* Life is very different on MSDOS. */
563 exit_code
= WEXITSTATUS (status
);
564 if (exit_code
== 0xff)
566 exit_sig
= WIFSIGNALED (status
) ? WTERMSIG (status
) : 0;
568 #endif /* __MSDOS__ */
572 status
= amiga_status
;
573 exit_code
= amiga_status
;
582 /* wait for anything to finish */
583 if (hPID
= process_wait_for_any()) {
585 /* was an error found on this process? */
586 err
= process_last_err(hPID
);
589 exit_code
= process_exit_code(hPID
);
592 fprintf(stderr
, "make (e=%d): %s",
593 exit_code
, map_windows32_error_to_string(exit_code
));
596 exit_sig
= process_signal(hPID
);
598 /* cleanup process */
599 process_cleanup(hPID
);
605 #endif /* WINDOWS32 */
608 /* Check if this is the child of the `shell' function. */
609 if (!remote
&& pid
== shell_function_pid
)
611 /* It is. Leave an indicator for the `shell' function. */
612 if (exit_sig
== 0 && exit_code
== 127)
613 shell_function_completed
= -1;
615 shell_function_completed
= 1;
619 child_failed
= exit_sig
!= 0 || exit_code
!= 0;
621 /* Search for a child matching the deceased one. */
623 for (c
= children
; c
!= 0; lastc
= c
, c
= c
->next
)
624 if (c
->remote
== remote
&& c
->pid
== pid
)
628 /* An unknown child died.
629 Ignore it; it was inherited from our invoker. */
632 DB (DB_JOBS
, (child_failed
633 ? _("Reaping losing child 0x%08lx PID %ld %s\n")
634 : _("Reaping winning child 0x%08lx PID %ld %s\n"),
635 (unsigned long int) c
, (long) c
->pid
,
636 c
->remote
? _(" (remote)") : ""));
638 if (c
->sh_batch_file
) {
639 DB (DB_JOBS
, (_("Cleaning up temp batch file %s\n"),
642 /* just try and remove, don't care if this fails */
643 remove (c
->sh_batch_file
);
645 /* all done with memory */
646 free (c
->sh_batch_file
);
647 c
->sh_batch_file
= NULL
;
650 /* If this child had the good stdin, say it is now free. */
654 if (child_failed
&& !c
->noerror
&& !ignore_errors_flag
)
656 /* The commands failed. Write an error message,
657 delete non-precious targets, and abort. */
658 static int delete_on_error
= -1;
659 child_error (c
->file
->name
, exit_code
, exit_sig
, coredump
, 0);
660 c
->file
->update_status
= 2;
661 if (delete_on_error
== -1)
663 struct file
*f
= lookup_file (".DELETE_ON_ERROR");
664 delete_on_error
= f
!= 0 && f
->is_target
;
666 if (exit_sig
!= 0 || delete_on_error
)
667 delete_child_targets (c
);
673 /* The commands failed, but we don't care. */
674 child_error (c
->file
->name
,
675 exit_code
, exit_sig
, coredump
, 1);
679 /* If there are more commands to run, try to start them. */
680 if (job_next_command (c
))
682 if (handling_fatal_signal
)
684 /* Never start new commands while we are dying.
685 Since there are more commands that wanted to be run,
686 the target was not completely remade. So we treat
687 this as if a command had failed. */
688 c
->file
->update_status
= 2;
692 /* Check again whether to start remotely.
693 Whether or not we want to changes over time.
694 Also, start_remote_job may need state set up
695 by start_remote_job_p. */
696 c
->remote
= start_remote_job_p (0);
697 start_job_command (c
);
698 /* Fatal signals are left blocked in case we were
699 about to put that child on the chain. But it is
700 already there, so it is safe for a fatal signal to
701 arrive now; it will clean up this child's targets. */
703 if (c
->file
->command_state
== cs_running
)
704 /* We successfully started the new command.
705 Loop to reap more children. */
709 if (c
->file
->update_status
!= 0)
710 /* We failed to start the commands. */
711 delete_child_targets (c
);
714 /* There are no more commands. We got through them all
715 without an unignored error. Now the target has been
716 successfully updated. */
717 c
->file
->update_status
= 0;
720 /* When we get here, all the commands for C->file are finished
721 (or aborted) and C->file->update_status contains 0 or 2. But
722 C->file->command_state is still cs_running if all the commands
723 ran; notice_finish_file looks for cs_running to tell it that
724 it's interesting to check the file's modtime again now. */
726 if (! handling_fatal_signal
)
727 /* Notice if the target of the commands has been changed.
728 This also propagates its values for command_state and
729 update_status to its also_make files. */
730 notice_finished_file (c
->file
);
732 DB (DB_JOBS
, (_("Removing child 0x%08lx PID %ld%s from chain.\n"),
733 (unsigned long int) c
, (long) c
->pid
,
734 c
->remote
? _(" (remote)") : ""));
736 /* Block fatal signals while frobnicating the list, so that
737 children and job_slots_used are always consistent. Otherwise
738 a fatal signal arriving after the child is off the chain and
739 before job_slots_used is decremented would believe a child was
740 live and call reap_children again. */
743 /* There is now another slot open. */
744 if (job_slots_used
> 0)
747 /* Remove the child from the chain and free it. */
751 lastc
->next
= c
->next
;
757 /* If the job failed, and the -k flag was not given, die,
758 unless we are already in the process of dying. */
759 if (!err
&& child_failed
&& !keep_going_flag
&&
760 /* fatal_error_signal will die with the right signal. */
761 !handling_fatal_signal
)
764 /* Only block for one child. */
771 /* Free the storage allocated for CHILD. */
775 register struct child
*child
;
777 /* If this child is the only one it was our "free" job, so don't put a
778 token back for it. This child has already been removed from the list,
779 so if there any left this wasn't the last one. */
781 if (job_fds
[1] >= 0 && children
)
785 /* Write a job token back to the pipe. */
787 if (write (job_fds
[1], &token
, 1) != 1)
788 pfatal_with_name (_("write jobserver"));
790 DB (DB_JOBS
, (_("Released token for child 0x%08lx (%s).\n"),
791 (unsigned long int) child
, child
->file
->name
));
794 if (handling_fatal_signal
) /* Don't bother free'ing if about to die. */
797 if (child
->command_lines
!= 0)
799 register unsigned int i
;
800 for (i
= 0; i
< child
->file
->cmds
->ncommand_lines
; ++i
)
801 free (child
->command_lines
[i
]);
802 free ((char *) child
->command_lines
);
805 if (child
->environment
!= 0)
807 register char **ep
= child
->environment
;
810 free ((char *) child
->environment
);
813 free ((char *) child
);
817 extern sigset_t fatal_signal_set
;
824 (void) sigprocmask (SIG_BLOCK
, &fatal_signal_set
, (sigset_t
*) 0);
826 # ifdef HAVE_SIGSETMASK
827 (void) sigblock (fatal_signal_mask
);
837 sigemptyset (&empty
);
838 sigprocmask (SIG_SETMASK
, &empty
, (sigset_t
*) 0);
842 #ifdef MAKE_JOBSERVER
843 /* Set the child handler action flags to FLAGS. */
845 set_child_handler_action_flags (flags
)
849 bzero ((char *) &sa
, sizeof sa
);
850 sa
.sa_handler
= child_handler
;
853 sigaction (SIGCHLD
, &sa
, NULL
);
855 #if defined SIGCLD && SIGCLD != SIGCHLD
856 sigaction (SIGCLD
, &sa
, NULL
);
862 /* Start a job to run the commands specified in CHILD.
863 CHILD is updated to reflect the commands and ID of the child process.
865 NOTE: On return fatal signals are blocked! The caller is responsible
866 for calling `unblock_sigs', once the new child is safely on the chain so
867 it can be cleaned up in the event of a fatal signal. */
870 start_job_command (child
)
871 register struct child
*child
;
874 static int bad_stdin
= -1;
884 /* If we have a completely empty commandset, stop now. */
885 if (!child
->command_ptr
)
888 /* Combine the flags parsed for the line itself with
889 the flags specified globally for this target. */
890 flags
= (child
->file
->command_flags
891 | child
->file
->cmds
->lines_flags
[child
->command_line
- 1]);
893 p
= child
->command_ptr
;
894 child
->noerror
= flags
& COMMANDS_NOERROR
;
899 flags
|= COMMANDS_SILENT
;
901 flags
|= COMMANDS_RECURSE
;
904 else if (!isblank ((unsigned char)*p
))
909 /* Update the file's command flags with any new ones we found. We only
910 keep the COMMANDS_RECURSE setting. Even this isn't 100% correct; we are
911 now marking more commands recursive than should be in the case of
912 multiline define/endef scripts where only one line is marked "+". In
913 order to really fix this, we'll have to keep a lines_flags for every
914 actual line, after expansion. */
915 child
->file
->cmds
->lines_flags
[child
->command_line
- 1]
916 |= flags
& COMMANDS_RECURSE
;
918 /* Figure out an argument list from this command line. */
925 argv
= construct_command_argv (p
, &end
, child
->file
, &child
->sh_batch_file
);
928 child
->command_ptr
= NULL
;
932 child
->command_ptr
= end
;
936 /* If -q was given, say that updating `failed' if there was any text on the
937 command line, or `succeeded' otherwise. The exit status of 1 tells the
938 user that -q is saying `something to do'; the exit status for a random
940 if (argv
!= 0 && question_flag
&& !(flags
& COMMANDS_RECURSE
))
944 free ((char *) argv
);
946 child
->file
->update_status
= 1;
947 notice_finished_file (child
->file
);
951 if (touch_flag
&& !(flags
& COMMANDS_RECURSE
))
953 /* Go on to the next command. It might be the recursive one.
954 We construct ARGV only to find the end of the command line. */
959 free ((char *) argv
);
969 execute_by_shell
= 0; /* in case construct_command_argv sets it */
971 /* This line has no commands. Go to the next. */
972 if (job_next_command (child
))
973 start_job_command (child
);
976 /* No more commands. Make sure we're "running"; we might not be if
977 (e.g.) all commands were skipped due to -n. */
978 set_command_state (child
->file
, cs_running
);
979 child
->file
->update_status
= 0;
980 notice_finished_file (child
->file
);
985 /* Print out the command. If silent, we call `message' with null so it
986 can log the working directory before the command's own error messages
989 message (0, (just_print_flag
|| (!(flags
& COMMANDS_SILENT
) && !silent_flag
))
990 ? "%s" : (char *) 0, p
);
992 /* Tell update_goal_chain that a command has been started on behalf of
993 this target. It is important that this happens here and not in
994 reap_children (where we used to do it), because reap_children might be
995 reaping children from a different target. We want this increment to
996 guaranteedly indicate that a command was started for the dependency
997 chain (i.e., update_file recursion chain) we are processing. */
1001 /* Optimize an empty command. People use this for timestamp rules,
1002 so avoid forking a useless shell. Do this after we increment
1003 commands_started so make still treats this special case as if it
1004 performed some action (makes a difference as to what messages are
1007 #if !defined(VMS) && !defined(_AMIGA)
1010 unixy_shell
/* the test is complicated and we already did it */
1012 (argv
[0] && !strcmp (argv
[0], "/bin/sh"))
1015 && argv
[1][0] == '-' && argv
[1][1] == 'c' && argv
[1][2] == '\0')
1016 && (argv
[2] && argv
[2][0] == ':' && argv
[2][1] == '\0')
1020 free ((char *) argv
);
1023 #endif /* !VMS && !_AMIGA */
1025 /* If -n was given, recurse to get the next line in the sequence. */
1027 if (just_print_flag
&& !(flags
& COMMANDS_RECURSE
))
1031 free ((char *) argv
);
1036 /* Flush the output streams so they won't have things written twice. */
1042 #if !defined(WINDOWS32) && !defined(_AMIGA) && !defined(__MSDOS__)
1044 /* Set up a bad standard input that reads from a broken pipe. */
1046 if (bad_stdin
== -1)
1048 /* Make a file descriptor that is the read end of a broken pipe.
1049 This will be used for some children's standard inputs. */
1053 /* Close the write side. */
1054 (void) close (pd
[1]);
1055 /* Save the read side. */
1058 /* Set the descriptor to close on exec, so it does not litter any
1059 child's descriptor table. When it is dup2'd onto descriptor 0,
1060 that descriptor will not close on exec. */
1061 CLOSE_ON_EXEC (bad_stdin
);
1065 #endif /* !WINDOWS32 && !_AMIGA && !__MSDOS__ */
1067 /* Decide whether to give this child the `good' standard input
1068 (one that points to the terminal or whatever), or the `bad' one
1069 that points to the read side of a broken pipe. */
1071 child
->good_stdin
= !good_stdin_used
;
1072 if (child
->good_stdin
)
1073 good_stdin_used
= 1;
1080 /* Set up the environment for the child. */
1081 if (child
->environment
== 0)
1082 child
->environment
= target_environment (child
->file
);
1085 #if !defined(__MSDOS__) && !defined(_AMIGA) && !defined(WINDOWS32)
1088 /* start_waiting_job has set CHILD->remote if we can start a remote job. */
1091 int is_remote
, id
, used_stdin
;
1092 if (start_remote_job (argv
, child
->environment
,
1093 child
->good_stdin
? 0 : bad_stdin
,
1094 &is_remote
, &id
, &used_stdin
))
1095 /* Don't give up; remote execution may fail for various reasons. If
1096 so, simply run the job locally. */
1100 if (child
->good_stdin
&& !used_stdin
)
1102 child
->good_stdin
= 0;
1103 good_stdin_used
= 0;
1105 child
->remote
= is_remote
;
1112 /* Fork the child process. */
1114 char **parent_environ
;
1123 if (!child_execute_job (argv
, child
)) {
1125 perror_with_name ("vfork", "");
1131 parent_environ
= environ
;
1132 child
->pid
= vfork ();
1133 environ
= parent_environ
; /* Restore value child may have clobbered. */
1134 if (child
->pid
== 0)
1136 /* We are the child side. */
1139 /* If we aren't running a recursive command and we have a jobserver
1140 pipe, close it before exec'ing. */
1141 if (!(flags
& COMMANDS_RECURSE
) && job_fds
[0] >= 0)
1149 child_execute_job (child
->good_stdin
? 0 : bad_stdin
, 1,
1150 argv
, child
->environment
);
1152 else if (child
->pid
< 0)
1156 perror_with_name ("vfork", "");
1162 #else /* __MSDOS__ or Amiga or WINDOWS32 */
1170 /* We call `system' to do the job of the SHELL, since stock DOS
1171 shell is too dumb. Our `system' knows how to handle long
1172 command lines even if pipes/redirection is needed; it will only
1173 call COMMAND.COM when its internal commands are used. */
1174 if (execute_by_shell
)
1176 char *cmdline
= argv
[0];
1177 /* We don't have a way to pass environment to `system',
1178 so we need to save and restore ours, sigh... */
1179 char **parent_environ
= environ
;
1181 environ
= child
->environment
;
1183 /* If we have a *real* shell, tell `system' to call
1184 it to do everything for us. */
1187 /* A *real* shell on MSDOS may not support long
1188 command lines the DJGPP way, so we must use `system'. */
1189 cmdline
= argv
[2]; /* get past "shell -c" */
1192 dos_command_running
= 1;
1193 proc_return
= system (cmdline
);
1194 environ
= parent_environ
;
1195 execute_by_shell
= 0; /* for the next time */
1199 dos_command_running
= 1;
1200 proc_return
= spawnvpe (P_WAIT
, argv
[0], argv
, child
->environment
);
1203 /* Need to unblock signals before turning off
1204 dos_command_running, so that child's signals
1205 will be treated as such (see fatal_error_signal). */
1207 dos_command_running
= 0;
1209 /* If the child got a signal, dos_status has its
1210 high 8 bits set, so be careful not to alter them. */
1211 if (proc_return
== -1)
1214 dos_status
|= (proc_return
& 0xff);
1216 child
->pid
= dos_pid
++;
1218 #endif /* __MSDOS__ */
1220 amiga_status
= MyExecute (argv
);
1223 child
->pid
= amiga_pid
++;
1224 if (amiga_batch_file
)
1226 amiga_batch_file
= 0;
1227 DeleteFile (amiga_bname
); /* Ignore errors. */
1235 /* make UNC paths safe for CreateProcess -- backslash format */
1237 if (arg0
&& arg0
[0] == '/' && arg0
[1] == '/')
1238 for ( ; arg0
&& *arg0
; arg0
++)
1242 /* make sure CreateProcess() has Path it needs */
1243 sync_Path_environment();
1245 hPID
= process_easy(argv
, child
->environment
);
1247 if (hPID
!= INVALID_HANDLE_VALUE
)
1248 child
->pid
= (int) hPID
;
1253 _("process_easy() failed failed to launch process (e=%d)\n"),
1254 process_last_err(hPID
));
1255 for (i
= 0; argv
[i
]; i
++)
1256 fprintf(stderr
, "%s ", argv
[i
]);
1257 fprintf(stderr
, _("\nCounted %d args in failed launch\n"), i
);
1260 #endif /* WINDOWS32 */
1261 #endif /* __MSDOS__ or Amiga or WINDOWS32 */
1263 /* We are the parent side. Set the state to
1264 say the commands are running and return. */
1266 set_command_state (child
->file
, cs_running
);
1268 /* Free the storage used by the child's argument list. */
1271 free ((char *) argv
);
1277 child
->file
->update_status
= 2;
1278 notice_finished_file (child
->file
);
1282 /* Try to start a child running.
1283 Returns nonzero if the child was started (and maybe finished), or zero if
1284 the load was too high and the child was put on the `waiting_jobs' chain. */
1287 start_waiting_job (c
)
1290 struct file
*f
= c
->file
;
1292 /* If we can start a job remotely, we always want to, and don't care about
1293 the local load average. We record that the job should be started
1294 remotely in C->remote for start_job_command to test. */
1296 c
->remote
= start_remote_job_p (1);
1298 /* If we are running at least one job already and the load average
1299 is too high, make this one wait. */
1300 if (!c
->remote
&& job_slots_used
> 0 && load_too_high ())
1302 /* Put this child on the chain of children waiting for the load average
1304 set_command_state (f
, cs_running
);
1305 c
->next
= waiting_jobs
;
1310 /* Start the first command; reap_children will run later command lines. */
1311 start_job_command (c
);
1313 switch (f
->command_state
)
1317 DB (DB_JOBS
, (_("Putting child 0x%08lx (%s) PID %ld%s on the chain.\n"),
1318 (unsigned long int) c
, c
->file
->name
,
1319 (long) c
->pid
, c
->remote
? _(" (remote)") : ""));
1321 /* One more job slot is in use. */
1326 case cs_not_started
:
1327 /* All the command lines turned out to be empty. */
1328 f
->update_status
= 0;
1332 notice_finished_file (f
);
1337 assert (f
->command_state
== cs_finished
);
1344 /* Create a `struct child' for FILE and start its commands running. */
1348 register struct file
*file
;
1350 register struct commands
*cmds
= file
->cmds
;
1351 register struct child
*c
;
1353 register unsigned int i
;
1355 /* Let any previously decided-upon jobs that are waiting
1356 for the load to go down start before this new one. */
1357 start_waiting_jobs ();
1359 /* Reap any children that might have finished recently. */
1360 reap_children (0, 0);
1362 /* Chop the commands up into lines if they aren't already. */
1363 chop_commands (cmds
);
1365 /* Expand the command lines and store the results in LINES. */
1366 lines
= (char **) xmalloc (cmds
->ncommand_lines
* sizeof (char *));
1367 for (i
= 0; i
< cmds
->ncommand_lines
; ++i
)
1369 /* Collapse backslash-newline combinations that are inside variable
1370 or function references. These are left alone by the parser so
1371 that they will appear in the echoing of commands (where they look
1372 nice); and collapsed by construct_command_argv when it tokenizes.
1373 But letting them survive inside function invocations loses because
1374 we don't want the functions to see them as part of the text. */
1376 char *in
, *out
, *ref
;
1378 /* IN points to where in the line we are scanning.
1379 OUT points to where in the line we are writing.
1380 When we collapse a backslash-newline combination,
1381 IN gets ahead of OUT. */
1383 in
= out
= cmds
->command_lines
[i
];
1384 while ((ref
= strchr (in
, '$')) != 0)
1386 ++ref
; /* Move past the $. */
1389 /* Copy the text between the end of the last chunk
1390 we processed (where IN points) and the new chunk
1391 we are about to process (where REF points). */
1392 bcopy (in
, out
, ref
- in
);
1394 /* Move both pointers past the boring stuff. */
1398 if (*ref
== '(' || *ref
== '{')
1400 char openparen
= *ref
;
1401 char closeparen
= openparen
== '(' ? ')' : '}';
1405 *out
++ = *in
++; /* Copy OPENPAREN. */
1406 /* IN now points past the opening paren or brace.
1407 Count parens or braces until it is matched. */
1411 if (*in
== closeparen
&& --count
< 0)
1413 else if (*in
== '\\' && in
[1] == '\n')
1415 /* We have found a backslash-newline inside a
1416 variable or function reference. Eat it and
1417 any following whitespace. */
1420 for (p
= in
- 1; p
> ref
&& *p
== '\\'; --p
)
1424 /* There were two or more backslashes, so this is
1425 not really a continuation line. We don't collapse
1426 the quoting backslashes here as is done in
1427 collapse_continuations, because the line will
1428 be collapsed again after expansion. */
1432 /* Skip the backslash, newline and
1433 any following whitespace. */
1434 in
= next_token (in
+ 2);
1436 /* Discard any preceding whitespace that has
1437 already been written to the output. */
1439 && isblank ((unsigned char)out
[-1]))
1442 /* Replace it all with a single space. */
1448 if (*in
== openparen
)
1457 /* There are no more references in this line to worry about.
1458 Copy the remaining uninteresting text to the output. */
1462 /* Finally, expand the line. */
1463 lines
[i
] = allocated_variable_expand_for_file (cmds
->command_lines
[i
],
1467 /* Start the command sequence, record it in a new
1468 `struct child', and add that to the chain. */
1470 c
= (struct child
*) xmalloc (sizeof (struct child
));
1471 bzero ((char *)c
, sizeof (struct child
));
1473 c
->command_lines
= lines
;
1474 c
->sh_batch_file
= NULL
;
1476 /* Fetch the first command line to be run. */
1477 job_next_command (c
);
1479 /* Wait for a job slot to be freed up. If we allow an infinite number
1480 don't bother; also job_slots will == 0 if we're using the jobserver. */
1483 while (job_slots_used
== job_slots
)
1484 reap_children (1, 0);
1486 #ifdef MAKE_JOBSERVER
1487 /* If we are controlling multiple jobs make sure we have a token before
1488 starting the child. */
1490 /* This can be inefficient. There's a decent chance that this job won't
1491 actually have to run any subprocesses: the command script may be empty
1492 or otherwise optimized away. It would be nice if we could defer
1493 obtaining a token until just before we need it, in start_job_command.
1494 To do that we'd need to keep track of whether we'd already obtained a
1495 token (since start_job_command is called for each line of the job, not
1496 just once). Also more thought needs to go into the entire algorithm;
1497 this is where the old parallel job code waits, so... */
1499 else if (job_fds
[0] >= 0)
1506 DB (DB_JOBS
, ("Need a job token; we %shave children\n",
1507 children
? "" : "don't "));
1509 /* If we don't already have a job started, use our "free" token. */
1513 /* Read a token. As long as there's no token available we'll block.
1514 We enable interruptible system calls before the read(2) so that if
1515 we get a SIGCHLD while we're waiting, we'll return with EINTR and
1516 we can process the death(s) and return tokens to the free pool.
1518 Once we return from the read, we immediately reinstate restartable
1519 system calls. This allows us to not worry about checking for
1520 EINTR on all the other system calls in the program.
1522 There is one other twist: there is a span between the time
1523 reap_children() does its last check for dead children and the time
1524 the read(2) call is entered, below, where if a child dies we won't
1525 notice. This is extremely serious as it could cause us to
1526 deadlock, given the right set of events.
1528 To avoid this, we do the following: before we reap_children(), we
1529 dup(2) the read FD on the jobserver pipe. The read(2) call below
1530 uses that new FD. In the signal handler, we close that FD. That
1531 way, if a child dies during the section mentioned above, the
1532 read(2) will be invoked with an invalid FD and will return
1533 immediately with EBADF. */
1535 /* Make sure we have a dup'd FD. */
1538 DB (DB_JOBS
, ("Duplicate the job FD\n"));
1539 job_rfd
= dup (job_fds
[0]);
1542 /* Reap anything that's currently waiting. */
1543 reap_children (0, 0);
1545 /* If our "free" token has become available, use it. */
1549 /* Set interruptible system calls, and read() for a job token. */
1550 set_child_handler_action_flags (0);
1551 got_token
= read (job_rfd
, &token
, 1);
1552 saved_errno
= errno
;
1553 set_child_handler_action_flags (SA_RESTART
);
1555 /* If we got one, we're done here. */
1558 DB (DB_JOBS
, (_("Obtained token for child 0x%08lx (%s).\n"),
1559 (unsigned long int) c
, c
->file
->name
));
1563 /* If the error _wasn't_ expected (EINTR or EBADF), punt. Otherwise,
1564 go back and reap_children(), and try again. */
1565 errno
= saved_errno
;
1566 if (errno
!= EINTR
&& errno
!= EBADF
)
1567 pfatal_with_name (_("read jobs pipe"));
1569 DB (DB_JOBS
, ("Read returned EBADF.\n"));
1573 /* The job is now primed. Start it running.
1574 (This will notice if there are in fact no commands.) */
1575 (void) start_waiting_job (c
);
1577 if (job_slots
== 1 || not_parallel
)
1578 /* Since there is only one job slot, make things run linearly.
1579 Wait for the child to die, setting the state to `cs_finished'. */
1580 while (file
->command_state
== cs_running
)
1581 reap_children (1, 0);
1586 /* Move CHILD's pointers to the next command for it to execute.
1587 Returns nonzero if there is another command. */
1590 job_next_command (child
)
1591 struct child
*child
;
1593 while (child
->command_ptr
== 0 || *child
->command_ptr
== '\0')
1595 /* There are no more lines in the expansion of this line. */
1596 if (child
->command_line
== child
->file
->cmds
->ncommand_lines
)
1598 /* There are no more lines to be expanded. */
1599 child
->command_ptr
= 0;
1603 /* Get the next line to run. */
1604 child
->command_ptr
= child
->command_lines
[child
->command_line
++];
1612 #if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA)
1617 if (max_load_average
< 0)
1621 if (getloadavg (&load
, 1) != 1)
1623 static int lossage
= -1;
1624 /* Complain only once for the same error. */
1625 if (lossage
== -1 || errno
!= lossage
)
1628 /* An errno value of zero means getloadavg is just unsupported. */
1630 _("cannot enforce load limits on this operating system"));
1632 perror_with_name (_("cannot enforce load limit: "), "getloadavg");
1639 DB (DB_JOBS
, ("Current system load = %f (max requested = %f)\n",
1640 load
, max_load_average
));
1641 return load
>= max_load_average
;
1645 /* Start jobs that are waiting for the load to be lower. */
1648 start_waiting_jobs ()
1652 if (waiting_jobs
== 0)
1657 /* Check for recently deceased descendants. */
1658 reap_children (0, 0);
1660 /* Take a job off the waiting list. */
1662 waiting_jobs
= job
->next
;
1664 /* Try to start that job. We break out of the loop as soon
1665 as start_waiting_job puts one back on the waiting list. */
1667 while (start_waiting_job (job
) && waiting_jobs
!= 0);
1674 #include <descrip.h>
1677 /* This is called as an AST when a child process dies (it won't get
1678 interrupted by anything except a higher level AST).
1680 int vmsHandleChildTerm(struct child
*child
)
1683 register struct child
*lastc
, *c
;
1686 vms_jobsefnmask
&= ~(1 << (child
->efn
- 32));
1688 lib$
free_ef(&child
->efn
);
1690 (void) sigblock (fatal_signal_mask
);
1692 child_failed
= !(child
->cstatus
& 1 || ((child
->cstatus
& 7) == 0));
1694 /* Search for a child matching the deceased one. */
1696 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */
1697 for (c
= children
; c
!= 0 && c
!= child
; lastc
= c
, c
= c
->next
);
1702 if (child_failed
&& !c
->noerror
&& !ignore_errors_flag
)
1704 /* The commands failed. Write an error message,
1705 delete non-precious targets, and abort. */
1706 child_error (c
->file
->name
, c
->cstatus
, 0, 0, 0);
1707 c
->file
->update_status
= 1;
1708 delete_child_targets (c
);
1714 /* The commands failed, but we don't care. */
1715 child_error (c
->file
->name
, c
->cstatus
, 0, 0, 1);
1719 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */
1720 /* If there are more commands to run, try to start them. */
1723 switch (c
->file
->command_state
)
1726 /* Successfully started. */
1730 if (c
->file
->update_status
!= 0) {
1731 /* We failed to start the commands. */
1732 delete_child_targets (c
);
1737 error (NILF
, _("internal error: `%s' command_state"),
1742 #endif /* RECURSIVEJOBS */
1745 /* Set the state flag to say the commands have finished. */
1746 c
->file
->command_state
= cs_finished
;
1747 notice_finished_file (c
->file
);
1749 #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */
1750 /* Remove the child from the chain and free it. */
1754 lastc
->next
= c
->next
;
1756 #endif /* RECURSIVEJOBS */
1758 /* There is now another slot open. */
1759 if (job_slots_used
> 0)
1762 /* If the job failed, and the -k flag was not given, die. */
1763 if (child_failed
&& !keep_going_flag
)
1766 (void) sigsetmask (sigblock (0) & ~(fatal_signal_mask
));
1772 Spawn a process executing the command in ARGV and return its pid. */
1774 #define MAXCMDLEN 200
1776 /* local helpers to make ctrl+c and ctrl+y working, see below */
1778 #include <libclidef.h>
1781 static int ctrlMask
= LIB$M_CLI_CTRLY
;
1782 static int oldCtrlMask
;
1783 static int setupYAstTried
= 0;
1784 static int pidToAbort
= 0;
1787 static void reEnableAst(void) {
1788 lib$
enable_ctrl (&oldCtrlMask
,0);
1791 static astHandler (void) {
1793 sys$
forcex (&pidToAbort
, 0, SS$_ABORT
);
1796 kill (getpid(),SIGQUIT
);
1799 static void tryToSetupYAst(void) {
1800 $
DESCRIPTOR(inputDsc
,"SYS$COMMAND");
1803 short int status
, count
;
1810 status
= sys$
assign(&inputDsc
,&chan
,0,0);
1811 if (!(status
&SS$_NORMAL
)) {
1816 status
= sys$
qiow (0, chan
, IO$_SETMODE
|IO$M_CTRLYAST
,&iosb
,0,0,
1817 astHandler
,0,0,0,0,0);
1818 if (status
==SS$_ILLIOFUNC
) {
1820 #ifdef CTRLY_ENABLED_ANYWAY
1822 _("-warning, CTRL-Y will leave sub-process(es) around.\n"));
1827 if (status
==SS$_NORMAL
)
1828 status
= iosb
.status
;
1829 if (!(status
&SS$_NORMAL
)) {
1834 /* called from AST handler ? */
1835 if (setupYAstTried
>1)
1837 if (atexit(reEnableAst
))
1839 _("-warning, you may have to re-enable CTRL-Y handling from DCL.\n"));
1840 status
= lib$
disable_ctrl (&ctrlMask
, &oldCtrlMask
);
1841 if (!(status
&SS$_NORMAL
)) {
1847 child_execute_job (argv
, child
)
1849 struct child
*child
;
1852 static struct dsc$descriptor_s cmddsc
;
1853 static struct dsc$descriptor_s pnamedsc
;
1854 static struct dsc$descriptor_s ifiledsc
;
1855 static struct dsc$descriptor_s ofiledsc
;
1856 static struct dsc$descriptor_s efiledsc
;
1857 int have_redirection
= 0;
1858 int have_newline
= 0;
1860 int spflags
= CLI$M_NOWAIT
;
1862 char *cmd
= alloca (strlen (argv
) + 512), *p
, *q
;
1863 char ifile
[256], ofile
[256], efile
[256];
1867 /* Parse IO redirection. */
1873 DB (DB_JOBS
, ("child_execute_job (%s)\n", argv
));
1875 while (isspace ((unsigned char)*argv
))
1881 sprintf (procname
, "GMAKE_%05x", getpid () & 0xfffff);
1882 pnamedsc
.dsc$w_length
= strlen(procname
);
1883 pnamedsc
.dsc$a_pointer
= procname
;
1884 pnamedsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
1885 pnamedsc
.dsc$b_class
= DSC$K_CLASS_S
;
1887 /* Handle comments and redirection. */
1888 for (p
= argv
, q
= cmd
; *p
; p
++, q
++)
1900 if (isspace ((unsigned char)*p
))
1902 do { p
++; } while (isspace ((unsigned char)*p
));
1908 p
= vms_redirect (&ifiledsc
, ifile
, p
);
1910 have_redirection
= 1;
1913 have_redirection
= 1;
1917 if (strncmp (p
, ">&1", 3) == 0)
1920 strcpy (efile
, "sys$output");
1921 efiledsc
.dsc$w_length
= strlen(efile
);
1922 efiledsc
.dsc$a_pointer
= efile
;
1923 efiledsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
1924 efiledsc
.dsc$b_class
= DSC$K_CLASS_S
;
1928 p
= vms_redirect (&efiledsc
, efile
, p
);
1933 p
= vms_redirect (&ofiledsc
, ofile
, p
);
1946 if (strncmp (cmd
, "builtin_", 8) == 0)
1948 child
->pid
= 270163;
1952 DB (DB_JOBS
, (_("BUILTIN [%s][%s]\n"), cmd
, cmd
+8));
1958 && ((*(p
+2) == ' ') || (*(p
+2) == '\t')))
1961 while ((*p
== ' ') || (*p
== '\t'))
1963 DB (DB_JOBS
, (_("BUILTIN CD %s\n"), p
));
1969 else if ((*(p
) == 'r')
1971 && ((*(p
+2) == ' ') || (*(p
+2) == '\t')))
1977 while ((*p
== ' ') || (*p
== '\t'))
1981 DB (DB_JOBS
, (_("BUILTIN RM %s\n"), p
));
2002 printf(_("Unknown builtin command '%s'\n"), cmd
);
2008 /* Create a *.com file if either the command is too long for
2009 lib$spawn, or the command contains a newline, or if redirection
2010 is desired. Forcing commands with newlines into DCLs allows to
2011 store search lists on user mode logicals. */
2013 if (strlen (cmd
) > MAXCMDLEN
2014 || (have_redirection
!= 0)
2015 || (have_newline
!= 0))
2020 int alevel
= 0; /* apostrophe level */
2022 if (strlen (cmd
) == 0)
2024 printf (_("Error, empty command\n"));
2029 outfile
= open_tmpfile (&comname
, "sys$scratch:CMDXXXXXX.COM");
2031 pfatal_with_name (_("fopen (temporary file)"));
2035 fprintf (outfile
, "$ assign/user %s sys$input\n", ifile
);
2036 DB (DB_JOBS
, (_("Redirected input from %s\n"), ifile
));
2037 ifiledsc
.dsc$w_length
= 0;
2042 fprintf (outfile
, "$ define sys$error %s\n", efile
);
2043 DB (DB_JOBS
, (_("Redirected error to %s\n"), efile
));
2044 efiledsc
.dsc$w_length
= 0;
2049 fprintf (outfile
, "$ define sys$output %s\n", ofile
);
2050 DB (DB_JOBS
, (_("Redirected output to %s\n"), ofile
));
2051 ofiledsc
.dsc$w_length
= 0;
2055 for (c
= '\n'; c
; c
= *q
++)
2060 /* At a newline, skip any whitespace around a leading $
2061 from the command and issue exactly one $ into the DCL. */
2062 while (isspace ((unsigned char)*p
))
2066 while (isspace ((unsigned char)*p
))
2068 fwrite (p
, 1, q
- p
, outfile
);
2069 fputc ('$', outfile
);
2070 fputc (' ', outfile
);
2071 /* Reset variables. */
2075 /* Nice places for line breaks are after strings, after
2076 comma or space and before slash. */
2078 q
= handle_apos (q
+ 1);
2094 /* Enough stuff for a line. */
2095 fwrite (p
, 1, sep
- p
, outfile
);
2099 /* The command continues. */
2100 fputc ('-', outfile
);
2102 fputc ('\n', outfile
);
2106 fwrite (p
, 1, q
- p
, outfile
);
2107 fputc ('\n', outfile
);
2111 sprintf (cmd
, "$ @%s", comname
);
2113 DB (DB_JOBS
, (_("Executing %s instead\n"), cmd
));
2116 cmddsc
.dsc$w_length
= strlen(cmd
);
2117 cmddsc
.dsc$a_pointer
= cmd
;
2118 cmddsc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
2119 cmddsc
.dsc$b_class
= DSC$K_CLASS_S
;
2122 while (child
->efn
< 32 || child
->efn
> 63)
2124 status
= lib$
get_ef ((unsigned long *)&child
->efn
);
2129 sys$
clref (child
->efn
);
2131 vms_jobsefnmask
|= (1 << (child
->efn
- 32));
2134 LIB$SPAWN [command-string]
2139 [,process-id] [,completion-status-address] [,byte-integer-event-flag-num]
2140 [,AST-address] [,varying-AST-argument]
2141 [,prompt-string] [,cli] [,table]
2144 #ifndef DONTWAITFORCHILD
2146 * Code to make ctrl+c and ctrl+y working.
2147 * The problem starts with the synchronous case where after lib$spawn is
2148 * called any input will go to the child. But with input re-directed,
2149 * both control characters won't make it to any of the programs, neither
2150 * the spawning nor to the spawned one. Hence the caller needs to spawn
2151 * with CLI$M_NOWAIT to NOT give up the input focus. A sys$waitfr
2152 * has to follow to simulate the wanted synchronous behaviour.
2153 * The next problem is ctrl+y which isn't caught by the crtl and
2154 * therefore isn't converted to SIGQUIT (for a signal handler which is
2155 * already established). The only way to catch ctrl+y, is an AST
2156 * assigned to the input channel. But ctrl+y handling of DCL needs to be
2157 * disabled, otherwise it will handle it. Not to mention the previous
2158 * ctrl+y handling of DCL needs to be re-established before make exits.
2159 * One more: At the time of LIB$SPAWN signals are blocked. SIGQUIT will
2160 * make it to the signal handler after the child "normally" terminates.
2161 * This isn't enough. It seems reasonable for simple command lines like
2162 * a 'cc foobar.c' spawned in a subprocess but it is unacceptable for
2163 * spawning make. Therefore we need to abort the process in the AST.
2165 * Prior to the spawn it is checked if an AST is already set up for
2166 * ctrl+y, if not one is set up for a channel to SYS$COMMAND. In general
2167 * this will work except if make is run in a batch environment, but there
2168 * nobody can press ctrl+y. During the setup the DCL handling of ctrl+y
2169 * is disabled and an exit handler is established to re-enable it.
2170 * If the user interrupts with ctrl+y, the assigned AST will fire, force
2171 * an abort to the subprocess and signal SIGQUIT, which will be caught by
2172 * the already established handler and will bring us back to common code.
2173 * After the spawn (now /nowait) a sys$waitfr simulates the /wait and
2174 * enables the ctrl+y be delivered to this code. And the ctrl+c too,
2175 * which the crtl converts to SIGINT and which is caught by the common
2176 * signal handler. Because signals were blocked before entering this code
2177 * sys$waitfr will always complete and the SIGQUIT will be processed after
2178 * it (after termination of the current block, somewhere in common code).
2179 * And SIGINT too will be delayed. That is ctrl+c can only abort when the
2180 * current command completes. Anyway it's better than nothing :-)
2183 if (!setupYAstTried
)
2185 status
= lib$
spawn (&cmddsc
, /* cmd-string */
2186 (ifiledsc
.dsc$w_length
== 0)?0:&ifiledsc
, /* input-file */
2187 (ofiledsc
.dsc$w_length
== 0)?0:&ofiledsc
, /* output-file */
2188 &spflags
, /* flags */
2189 &pnamedsc
, /* proc name */
2190 &child
->pid
, &child
->cstatus
, &child
->efn
,
2193 pidToAbort
= child
->pid
;
2194 status
= sys$
waitfr (child
->efn
);
2196 vmsHandleChildTerm(child
);
2198 status
= lib$
spawn (&cmddsc
,
2199 (ifiledsc
.dsc$w_length
== 0)?0:&ifiledsc
,
2200 (ofiledsc
.dsc$w_length
== 0)?0:&ofiledsc
,
2203 &child
->pid
, &child
->cstatus
, &child
->efn
,
2204 vmsHandleChildTerm
, child
,
2210 printf (_("Error spawning, %d\n") ,status
);
2214 if (comname
&& !ISDB (DB_JOBS
))
2217 return (status
& 1);
2222 #if !defined (_AMIGA) && !defined (__MSDOS__)
2224 Replace the current process with one executing the command in ARGV.
2225 STDIN_FD and STDOUT_FD are used as the process's stdin and stdout; ENVP is
2226 the environment of the new program. This function does not return. */
2229 child_execute_job (stdin_fd
, stdout_fd
, argv
, envp
)
2230 int stdin_fd
, stdout_fd
;
2231 char **argv
, **envp
;
2234 (void) dup2 (stdin_fd
, 0);
2236 (void) dup2 (stdout_fd
, 1);
2238 (void) close (stdin_fd
);
2240 (void) close (stdout_fd
);
2242 /* Run the command. */
2243 exec_command (argv
, envp
);
2245 #endif /* !AMIGA && !__MSDOS__ */
2247 #endif /* !WINDOWS32 */
2250 /* Replace the current process with one running the command in ARGV,
2251 with environment ENVP. This function does not return. */
2254 exec_command (argv
, envp
)
2255 char **argv
, **envp
;
2258 /* to work around a problem with signals and execve: ignore them */
2260 signal (SIGCHLD
,SIG_IGN
);
2262 /* Run the program. */
2263 execve (argv
[0], argv
, envp
);
2264 perror_with_name ("execve: ", argv
[0]);
2265 _exit (EXIT_FAILURE
);
2271 int exit_code
= EXIT_FAILURE
;
2273 /* make sure CreateProcess() has Path it needs */
2274 sync_Path_environment();
2276 /* launch command */
2277 hPID
= process_easy(argv
, envp
);
2279 /* make sure launch ok */
2280 if (hPID
== INVALID_HANDLE_VALUE
)
2284 _("process_easy() failed failed to launch process (e=%d)\n"),
2285 process_last_err(hPID
));
2286 for (i
= 0; argv
[i
]; i
++)
2287 fprintf(stderr
, "%s ", argv
[i
]);
2288 fprintf(stderr
, _("\nCounted %d args in failed launch\n"), i
);
2292 /* wait and reap last child */
2293 while (hWaitPID
= process_wait_for_any())
2295 /* was an error found on this process? */
2296 err
= process_last_err(hWaitPID
);
2299 exit_code
= process_exit_code(hWaitPID
);
2302 fprintf(stderr
, "make (e=%d, rc=%d): %s",
2303 err
, exit_code
, map_windows32_error_to_string(err
));
2305 /* cleanup process */
2306 process_cleanup(hWaitPID
);
2308 /* expect to find only last pid, warn about other pids reaped */
2309 if (hWaitPID
== hPID
)
2313 _("make reaped child pid %d, still waiting for pid %d\n"),
2317 /* return child's exit code as our exit code */
2320 #else /* !WINDOWS32 */
2322 /* Be the user, permanently. */
2325 /* Run the program. */
2327 execvp (argv
[0], argv
);
2332 error (NILF
, _("%s: Command not found"), argv
[0]);
2336 /* The file is not executable. Try it as a shell script. */
2337 extern char *getenv ();
2342 shell
= getenv ("SHELL");
2344 shell
= default_shell
;
2347 while (argv
[argc
] != 0)
2350 new_argv
= (char **) alloca ((1 + argc
+ 1) * sizeof (char *));
2351 new_argv
[0] = shell
;
2352 new_argv
[1] = argv
[0];
2355 new_argv
[1 + argc
] = argv
[argc
];
2359 execvp (shell
, new_argv
);
2360 if (errno
== ENOENT
)
2361 error (NILF
, _("%s: Shell program not found"), shell
);
2363 perror_with_name ("execvp: ", shell
);
2368 perror_with_name ("execvp: ", argv
[0]);
2373 #endif /* !WINDOWS32 */
2376 #else /* On Amiga */
2377 void exec_command (argv
)
2383 void clean_tmp (void)
2385 DeleteFile (amiga_bname
);
2388 #endif /* On Amiga */
2391 /* Figure out the argument list necessary to run LINE as a command. Try to
2392 avoid using a shell. This routine handles only ' quoting, and " quoting
2393 when no backslash, $ or ` characters are seen in the quotes. Starting
2394 quotes may be escaped with a backslash. If any of the characters in
2395 sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
2396 is the first word of a line, the shell is used.
2398 If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
2399 If *RESTP is NULL, newlines will be ignored.
2401 SHELL is the shell to use, or nil to use the default shell.
2402 IFS is the value of $IFS, or nil (meaning the default). */
2405 construct_command_argv_internal (line
, restp
, shell
, ifs
, batch_filename_ptr
)
2406 char *line
, **restp
;
2408 char **batch_filename_ptr
;
2411 /* MSDOS supports both the stock DOS shell and ports of Unixy shells.
2412 We call `system' for anything that requires ``slow'' processing,
2413 because DOS shells are too dumb. When $SHELL points to a real
2414 (unix-style) shell, `system' just calls it to do everything. When
2415 $SHELL points to a DOS shell, `system' does most of the work
2416 internally, calling the shell only for its internal commands.
2417 However, it looks on the $PATH first, so you can e.g. have an
2418 external command named `mkdir'.
2420 Since we call `system', certain characters and commands below are
2421 actually not specific to COMMAND.COM, but to the DJGPP implementation
2422 of `system'. In particular:
2424 The shell wildcard characters are in DOS_CHARS because they will
2425 not be expanded if we call the child via `spawnXX'.
2427 The `;' is in DOS_CHARS, because our `system' knows how to run
2428 multiple commands on a single line.
2430 DOS_CHARS also include characters special to 4DOS/NDOS, so we
2431 won't have to tell one from another and have one more set of
2432 commands and special characters. */
2433 static char sh_chars_dos
[] = "*?[];|<>%^&()";
2434 static char *sh_cmds_dos
[] = { "break", "call", "cd", "chcp", "chdir", "cls",
2435 "copy", "ctty", "date", "del", "dir", "echo",
2436 "erase", "exit", "for", "goto", "if", "md",
2437 "mkdir", "path", "pause", "prompt", "rd",
2438 "rmdir", "rem", "ren", "rename", "set",
2439 "shift", "time", "type", "ver", "verify",
2442 static char sh_chars_sh
[] = "#;\"*?[]&|<>(){}$`^";
2443 static char *sh_cmds_sh
[] = { "cd", "echo", "eval", "exec", "exit", "login",
2444 "logout", "set", "umask", "wait", "while",
2445 "for", "case", "if", ":", ".", "break",
2446 "continue", "export", "read", "readonly",
2447 "shift", "times", "trap", "switch", "unset",
2454 static char sh_chars
[] = "#;\"|<>()?*$`";
2455 static char *sh_cmds
[] = { "cd", "eval", "if", "delete", "echo", "copy",
2456 "rename", "set", "setenv", "date", "makedir",
2457 "skip", "else", "endif", "path", "prompt",
2458 "unset", "unsetenv", "version",
2462 static char sh_chars_dos
[] = "\"|&<>";
2463 static char *sh_cmds_dos
[] = { "break", "call", "cd", "chcp", "chdir", "cls",
2464 "copy", "ctty", "date", "del", "dir", "echo",
2465 "erase", "exit", "for", "goto", "if", "if", "md",
2466 "mkdir", "path", "pause", "prompt", "rd", "rem",
2467 "ren", "rename", "rmdir", "set", "shift", "time",
2468 "type", "ver", "verify", "vol", ":", 0 };
2469 static char sh_chars_sh
[] = "#;\"*?[]&|<>(){}$`^";
2470 static char *sh_cmds_sh
[] = { "cd", "eval", "exec", "exit", "login",
2471 "logout", "set", "umask", "wait", "while", "for",
2472 "case", "if", ":", ".", "break", "continue",
2473 "export", "read", "readonly", "shift", "times",
2474 "trap", "switch", "test",
2475 #ifdef BATCH_MODE_ONLY_SHELL
2481 #else /* must be UNIX-ish */
2482 static char sh_chars
[] = "#;\"*?[]&|<>(){}$`^~";
2483 static char *sh_cmds
[] = { "cd", "eval", "exec", "exit", "login",
2484 "logout", "set", "umask", "wait", "while", "for",
2485 "case", "if", ":", ".", "break", "continue",
2486 "export", "read", "readonly", "shift", "times",
2487 "trap", "switch", 0 };
2488 #endif /* WINDOWS32 */
2490 #endif /* __MSDOS__ */
2495 int instring
, word_has_equals
, seen_nonequals
, last_argument_was_empty
;
2496 char **new_argv
= 0;
2500 if (no_default_sh_exe
) {
2501 sh_cmds
= sh_cmds_dos
;
2502 sh_chars
= sh_chars_dos
;
2504 sh_cmds
= sh_cmds_sh
;
2505 sh_chars
= sh_chars_sh
;
2507 #endif /* WINDOWS32 */
2512 /* Make sure not to bother processing an empty line. */
2513 while (isblank ((unsigned char)*line
))
2518 /* See if it is safe to parse commands internally. */
2520 shell
= default_shell
;
2522 else if (strcmp (shell
, default_shell
))
2524 char *s1
= _fullpath(NULL
, shell
, 0);
2525 char *s2
= _fullpath(NULL
, default_shell
, 0);
2527 slow_flag
= strcmp((s1
? s1
: ""), (s2
? s2
: ""));
2536 #else /* not WINDOWS32 */
2538 else if (stricmp (shell
, default_shell
))
2540 extern int _is_unixy_shell (const char *_path
);
2542 message (1, _("$SHELL changed (was `%s', now `%s')"), default_shell
, shell
);
2543 unixy_shell
= _is_unixy_shell (shell
);
2544 default_shell
= shell
;
2548 sh_chars
= sh_chars_sh
;
2549 sh_cmds
= sh_cmds_sh
;
2553 sh_chars
= sh_chars_dos
;
2554 sh_cmds
= sh_cmds_dos
;
2556 #else /* not __MSDOS__ */
2557 else if (strcmp (shell
, default_shell
))
2559 #endif /* not __MSDOS__ */
2560 #endif /* not WINDOWS32 */
2563 for (ap
= ifs
; *ap
!= '\0'; ++ap
)
2564 if (*ap
!= ' ' && *ap
!= '\t' && *ap
!= '\n')
2567 i
= strlen (line
) + 1;
2569 /* More than 1 arg per character is impossible. */
2570 new_argv
= (char **) xmalloc (i
* sizeof (char *));
2572 /* All the args can fit in a buffer as big as LINE is. */
2573 ap
= new_argv
[0] = (char *) xmalloc (i
);
2576 /* I is how many complete arguments have been found. */
2578 instring
= word_has_equals
= seen_nonequals
= last_argument_was_empty
= 0;
2579 for (p
= line
; *p
!= '\0'; ++p
)
2587 /* Inside a string, just copy any char except a closing quote
2588 or a backslash-newline combination. */
2592 if (ap
== new_argv
[0] || *(ap
-1) == '\0')
2593 last_argument_was_empty
= 1;
2595 else if (*p
== '\\' && p
[1] == '\n')
2596 goto swallow_escaped_newline
;
2597 else if (*p
== '\n' && restp
!= NULL
)
2599 /* End of the command line. */
2603 /* Backslash, $, and ` are special inside double quotes.
2604 If we see any of those, punt.
2605 But on MSDOS, if we use COMMAND.COM, double and single
2606 quotes have the same effect. */
2607 else if (instring
== '"' && strchr ("\\$`", *p
) != 0 && unixy_shell
)
2612 else if (strchr (sh_chars
, *p
) != 0)
2613 /* Not inside a string, but it's a special char. */
2616 else if (*p
== '.' && p
[1] == '.' && p
[2] == '.' && p
[3] != '.')
2617 /* `...' is a wildcard in DJGPP. */
2621 /* Not a special char. */
2625 /* Equals is a special character in leading words before the
2626 first word with no equals sign in it. This is not the case
2627 with sh -k, but we never get here when using nonstandard
2629 if (! seen_nonequals
&& unixy_shell
)
2631 word_has_equals
= 1;
2636 /* Backslash-newline combinations are eaten. */
2639 swallow_escaped_newline
:
2641 /* Eat the backslash, the newline, and following whitespace,
2642 replacing it all with a single space. */
2645 /* If there is a tab after a backslash-newline,
2646 remove it from the source line which will be echoed,
2647 since it was most likely used to line
2648 up the continued line with the previous one. */
2650 /* Note these overlap and strcpy() is undefined for
2651 overlapping objects in ANSI C. The strlen() _IS_ right,
2652 since we need to copy the nul byte too. */
2653 bcopy (p
+ 1, p
, strlen (p
));
2659 if (ap
!= new_argv
[i
])
2660 /* Treat this as a space, ending the arg.
2661 But if it's at the beginning of the arg, it should
2662 just get eaten, rather than becoming an empty arg. */
2665 p
= next_token (p
) - 1;
2668 else if (p
[1] != '\0')
2670 #ifdef HAVE_DOS_PATHS
2671 /* Only remove backslashes before characters special
2672 to Unixy shells. All other backslashes are copied
2673 verbatim, since they are probably DOS-style
2674 directory separators. This still leaves a small
2675 window for problems, but at least it should work
2676 for the vast majority of naive users. */
2679 /* A dot is only special as part of the "..."
2681 if (strneq (p
+ 1, ".\\.\\.", 5))
2689 if (p
[1] != '\\' && p
[1] != '\''
2690 && !isspace ((unsigned char)p
[1])
2691 && (strchr (sh_chars_sh
, p
[1]) == 0))
2692 /* back up one notch, to copy the backslash */
2694 #endif /* HAVE_DOS_PATHS */
2696 /* Copy and skip the following char. */
2709 /* End of the command line. */
2714 /* Newlines are not special. */
2721 /* We have the end of an argument.
2722 Terminate the text of the argument. */
2725 last_argument_was_empty
= 0;
2727 /* Update SEEN_NONEQUALS, which tells us if every word
2728 heretofore has contained an `='. */
2729 seen_nonequals
|= ! word_has_equals
;
2730 if (word_has_equals
&& ! seen_nonequals
)
2731 /* An `=' in a word before the first
2732 word without one is magical. */
2734 word_has_equals
= 0; /* Prepare for the next word. */
2736 /* If this argument is the command name,
2737 see if it is a built-in shell command.
2738 If so, have the shell handle it. */
2742 for (j
= 0; sh_cmds
[j
] != 0; ++j
)
2743 if (streq (sh_cmds
[j
], new_argv
[0]))
2747 /* Ignore multiple whitespace chars. */
2749 /* Next iteration should examine the first nonwhite char. */
2761 /* Let the shell deal with an unterminated quote. */
2764 /* Terminate the last argument and the argument list. */
2767 if (new_argv
[i
][0] != '\0' || last_argument_was_empty
)
2774 for (j
= 0; sh_cmds
[j
] != 0; ++j
)
2775 if (streq (sh_cmds
[j
], new_argv
[0]))
2779 if (new_argv
[0] == 0)
2780 /* Line was empty. */
2786 /* We must use the shell. */
2790 /* Free the old argument list we were working on. */
2792 free ((void *)new_argv
);
2796 execute_by_shell
= 1; /* actually, call `system' if shell isn't unixy */
2805 buffer
= (char *)xmalloc (strlen (line
)+1);
2808 for (dptr
=buffer
; *ptr
; )
2810 if (*ptr
== '\\' && ptr
[1] == '\n')
2812 else if (*ptr
== '@') /* Kludge: multiline commands */
2822 new_argv
= (char **) xmalloc (2 * sizeof (char *));
2823 new_argv
[0] = buffer
;
2826 #else /* Not Amiga */
2829 * Not eating this whitespace caused things like
2833 * which gave the shell fits. I think we have to eat
2834 * whitespace here, but this code should be considered
2835 * suspicious if things start failing....
2838 /* Make sure not to bother processing an empty line. */
2839 while (isspace ((unsigned char)*line
))
2843 #endif /* WINDOWS32 */
2845 /* SHELL may be a multi-word command. Construct a command line
2846 "SHELL -c LINE", with all special chars in LINE escaped.
2847 Then recurse, expanding this command line to get the final
2850 unsigned int shell_len
= strlen (shell
);
2852 static char minus_c
[] = " -c ";
2854 static char minus_c
[] = "";
2856 unsigned int line_len
= strlen (line
);
2858 char *new_line
= (char *) alloca (shell_len
+ (sizeof (minus_c
) - 1)
2859 + (line_len
* 2) + 1);
2860 char *command_ptr
= NULL
; /* used for batch_mode_shell mode */
2863 bcopy (shell
, ap
, shell_len
);
2865 bcopy (minus_c
, ap
, sizeof (minus_c
) - 1);
2866 ap
+= sizeof (minus_c
) - 1;
2868 for (p
= line
; *p
!= '\0'; ++p
)
2870 if (restp
!= NULL
&& *p
== '\n')
2875 else if (*p
== '\\' && p
[1] == '\n')
2877 /* Eat the backslash, the newline, and following whitespace,
2878 replacing it all with a single space (which is escaped
2882 /* If there is a tab after a backslash-newline,
2883 remove it from the source line which will be echoed,
2884 since it was most likely used to line
2885 up the continued line with the previous one. */
2887 bcopy (p
+ 1, p
, strlen (p
));
2891 if (unixy_shell
&& !batch_mode_shell
)
2897 /* DOS shells don't know about backslash-escaping. */
2898 if (unixy_shell
&& !batch_mode_shell
&&
2899 (*p
== '\\' || *p
== '\'' || *p
== '"'
2900 || isspace ((unsigned char)*p
)
2901 || strchr (sh_chars
, *p
) != 0))
2904 else if (unixy_shell
&& strneq (p
, "...", 3))
2906 /* The case of `...' wildcard again. */
2907 strcpy (ap
, "\\.\\.\\");
2914 if (ap
== new_line
+ shell_len
+ sizeof (minus_c
) - 1)
2915 /* Line was empty. */
2920 /* Some shells do not work well when invoked as 'sh -c xxx' to run a
2921 command line (e.g. Cygnus GNUWIN32 sh.exe on WIN32 systems). In these
2922 cases, run commands via a script file. */
2923 if ((no_default_sh_exe
|| batch_mode_shell
) && batch_filename_ptr
) {
2925 int id
= GetCurrentProcessId();
2929 /* create a file name */
2930 sprintf(fbuf
, "make%d", id
);
2931 fname
= tempnam(".", fbuf
);
2933 /* create batch file name */
2934 *batch_filename_ptr
= xmalloc(strlen(fname
) + 5);
2935 strcpy(*batch_filename_ptr
, fname
);
2937 /* make sure path name is in DOS backslash format */
2939 fname
= *batch_filename_ptr
;
2940 for (i
= 0; fname
[i
] != '\0'; ++i
)
2941 if (fname
[i
] == '/')
2943 strcat(*batch_filename_ptr
, ".bat");
2945 strcat(*batch_filename_ptr
, ".sh");
2948 DB (DB_JOBS
, (_("Creating temporary batch file %s\n"),
2949 *batch_filename_ptr
));
2951 /* create batch file to execute command */
2952 batch
= fopen (*batch_filename_ptr
, "w");
2954 fputs ("@echo off\n", batch
);
2955 fputs (command_ptr
, batch
);
2956 fputc ('\n', batch
);
2960 new_argv
= (char **) xmalloc(3 * sizeof (char *));
2962 new_argv
[0] = xstrdup (shell
);
2963 new_argv
[1] = *batch_filename_ptr
; /* only argv[0] gets freed later */
2965 new_argv
[0] = xstrdup (*batch_filename_ptr
);
2970 #endif /* WINDOWS32 */
2972 new_argv
= construct_command_argv_internal (new_line
, (char **) NULL
,
2973 (char *) 0, (char *) 0,
2978 /* With MSDOS shells, we must construct the command line here
2979 instead of recursively calling ourselves, because we
2980 cannot backslash-escape the special characters (see above). */
2981 new_argv
= (char **) xmalloc (sizeof (char *));
2982 line_len
= strlen (new_line
) - shell_len
- sizeof (minus_c
) + 1;
2983 new_argv
[0] = xmalloc (line_len
+ 1);
2984 strncpy (new_argv
[0],
2985 new_line
+ shell_len
+ sizeof (minus_c
) - 1, line_len
);
2986 new_argv
[0][line_len
] = '\0';
2990 fatal (NILF
, _("%s (line %d) Bad shell context (!unixy && !batch_mode_shell)\n"),
2991 __FILE__
, __LINE__
);
2994 #endif /* ! AMIGA */
3000 /* Figure out the argument list necessary to run LINE as a command. Try to
3001 avoid using a shell. This routine handles only ' quoting, and " quoting
3002 when no backslash, $ or ` characters are seen in the quotes. Starting
3003 quotes may be escaped with a backslash. If any of the characters in
3004 sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
3005 is the first word of a line, the shell is used.
3007 If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
3008 If *RESTP is NULL, newlines will be ignored.
3010 FILE is the target whose commands these are. It is used for
3011 variable expansion for $(SHELL) and $(IFS). */
3014 construct_command_argv (line
, restp
, file
, batch_filename_ptr
)
3015 char *line
, **restp
;
3017 char** batch_filename_ptr
;
3031 && (isspace ((unsigned char)*cptr
)))
3036 && (!isspace((unsigned char)*cptr
)))
3041 argv
= (char **)malloc (argc
* sizeof (char *));
3050 && (isspace ((unsigned char)*cptr
)))
3054 DB (DB_JOBS
, ("argv[%d] = [%s]\n", argc
, cptr
));
3055 argv
[argc
++] = cptr
;
3057 && (!isspace((unsigned char)*cptr
)))
3064 /* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
3065 int save
= warn_undefined_variables_flag
;
3066 warn_undefined_variables_flag
= 0;
3068 shell
= allocated_variable_expand_for_file ("$(SHELL)", file
);
3071 * Convert to forward slashes so that construct_command_argv_internal()
3075 char *p
= w32ify(shell
, 0);
3079 ifs
= allocated_variable_expand_for_file ("$(IFS)", file
);
3081 warn_undefined_variables_flag
= save
;
3084 argv
= construct_command_argv_internal (line
, restp
, shell
, ifs
, batch_filename_ptr
);
3092 #if !defined(HAVE_DUP2) && !defined(_AMIGA)
3110 #endif /* !HAPE_DUP2 && !_AMIGA */