1992-01-21 02:49:36 +08:00
|
|
|
|
/* Job execution and handling for GNU Make.
|
2013-05-17 13:46:11 +08:00
|
|
|
|
Copyright (C) 1988-2013 Free Software Foundation, Inc.
|
1992-01-21 02:49:36 +08:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
|
GNU Make is free software; you can redistribute it and/or modify it under the
|
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
2007-07-05 03:35:15 +08:00
|
|
|
|
Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
|
version.
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
|
GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
2007-07-05 03:35:15 +08:00
|
|
|
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-01-21 00:01:01 +08:00
|
|
|
|
#include "makeint.h"
|
2000-06-20 05:22:44 +08:00
|
|
|
|
|
1999-11-22 14:15:35 +08:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
#include "job.h"
|
1999-11-22 14:15:35 +08:00
|
|
|
|
#include "debug.h"
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#include "filedef.h"
|
|
|
|
|
#include "commands.h"
|
1992-01-21 02:49:36 +08:00
|
|
|
|
#include "variable.h"
|
1999-11-22 14:15:35 +08:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
/* Default shell to use. */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
2005-08-08 13:08:00 +08:00
|
|
|
|
#include <windows.h>
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
1996-05-23 05:51:45 +08:00
|
|
|
|
char *default_shell = "sh.exe";
|
|
|
|
|
int no_default_sh_exe = 1;
|
1998-07-31 04:54:47 +08:00
|
|
|
|
int batch_mode_shell = 1;
|
2005-08-08 13:08:00 +08:00
|
|
|
|
HANDLE main_thread;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
#elif defined (_AMIGA)
|
|
|
|
|
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
char default_shell[] = "";
|
|
|
|
|
extern int MyExecute (char **);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
int batch_mode_shell = 0;
|
|
|
|
|
|
|
|
|
|
#elif defined (__MSDOS__)
|
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
/* The default shell is a pointer so we can change it if Makefile
|
|
|
|
|
says so. It is without an explicit path so we get a chance
|
|
|
|
|
to search the $PATH for it (since MSDOS doesn't have standard
|
|
|
|
|
directories we could trust). */
|
|
|
|
|
char *default_shell = "command.com";
|
2003-03-25 07:14:15 +08:00
|
|
|
|
int batch_mode_shell = 0;
|
|
|
|
|
|
|
|
|
|
#elif defined (__EMX__)
|
|
|
|
|
|
2004-02-23 14:25:54 +08:00
|
|
|
|
char *default_shell = "/bin/sh";
|
2003-03-25 07:14:15 +08:00
|
|
|
|
int batch_mode_shell = 0;
|
|
|
|
|
|
|
|
|
|
#elif defined (VMS)
|
|
|
|
|
|
|
|
|
|
# include <descrip.h>
|
2000-01-22 13:43:03 +08:00
|
|
|
|
char default_shell[] = "";
|
2003-03-25 07:14:15 +08:00
|
|
|
|
int batch_mode_shell = 0;
|
|
|
|
|
|
2004-05-17 03:16:52 +08:00
|
|
|
|
#elif defined (__riscos__)
|
|
|
|
|
|
|
|
|
|
char default_shell[] = "";
|
|
|
|
|
int batch_mode_shell = 0;
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#else
|
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
char default_shell[] = "/bin/sh";
|
1998-07-31 04:54:47 +08:00
|
|
|
|
int batch_mode_shell = 0;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1994-07-26 07:23:03 +08:00
|
|
|
|
#ifdef __MSDOS__
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# include <process.h>
|
1997-04-07 15:21:16 +08:00
|
|
|
|
static int execute_by_shell;
|
1994-07-26 07:23:03 +08:00
|
|
|
|
static int dos_pid = 123;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
int dos_status;
|
|
|
|
|
int dos_command_running;
|
|
|
|
|
#endif /* __MSDOS__ */
|
1996-05-23 05:51:45 +08:00
|
|
|
|
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
#ifdef _AMIGA
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# include <proto/dos.h>
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
static int amiga_pid = 123;
|
|
|
|
|
static int amiga_status;
|
|
|
|
|
static char amiga_bname[32];
|
|
|
|
|
static int amiga_batch_file;
|
|
|
|
|
#endif /* Amiga. */
|
1994-07-26 07:23:03 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
2000-01-22 13:43:03 +08:00
|
|
|
|
# ifndef __GNUC__
|
|
|
|
|
# include <processes.h>
|
|
|
|
|
# endif
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# include <starlet.h>
|
|
|
|
|
# include <lib$routines.h>
|
2006-04-07 09:43:44 +08:00
|
|
|
|
static void vmsWaitForChildren (int *);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# include <windows.h>
|
|
|
|
|
# include <io.h>
|
|
|
|
|
# include <process.h>
|
|
|
|
|
# include "sub_proc.h"
|
|
|
|
|
# include "w32err.h"
|
|
|
|
|
# include "pathstuff.h"
|
2011-11-14 08:42:49 +08:00
|
|
|
|
# define WAIT_NOHANG 1
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
1996-05-23 05:51:45 +08:00
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#ifdef __EMX__
|
2003-05-02 09:44:59 +08:00
|
|
|
|
# include <process.h>
|
1995-08-02 02:38:49 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
1995-11-26 09:42:27 +08:00
|
|
|
|
#if defined (HAVE_SYS_WAIT_H) || defined (HAVE_UNION_WAIT)
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# include <sys/wait.h>
|
1993-01-23 06:31:27 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
#ifdef HAVE_WAITPID
|
2013-05-17 14:29:46 +08:00
|
|
|
|
# define WAIT_NOHANG(status) waitpid (-1, (status), WNOHANG)
|
|
|
|
|
#else /* Don't have waitpid. */
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# ifdef HAVE_WAIT3
|
|
|
|
|
# ifndef wait3
|
1992-01-21 02:49:36 +08:00
|
|
|
|
extern int wait3 ();
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
# define WAIT_NOHANG(status) wait3 ((status), WNOHANG, (struct rusage *) 0)
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# endif /* Have wait3. */
|
|
|
|
|
#endif /* Have waitpid. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
#if !defined (wait) && !defined (POSIX)
|
2006-04-07 09:43:44 +08:00
|
|
|
|
int wait ();
|
1992-01-21 02:49:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#ifndef HAVE_UNION_WAIT
|
1993-01-23 06:31:27 +08:00
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# define WAIT_T int
|
|
|
|
|
|
|
|
|
|
# ifndef WTERMSIG
|
|
|
|
|
# define WTERMSIG(x) ((x) & 0x7f)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WCOREDUMP
|
|
|
|
|
# define WCOREDUMP(x) ((x) & 0x80)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WEXITSTATUS
|
|
|
|
|
# define WEXITSTATUS(x) (((x) >> 8) & 0xff)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WIFSIGNALED
|
|
|
|
|
# define WIFSIGNALED(x) (WTERMSIG (x) != 0)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WIFEXITED
|
|
|
|
|
# define WIFEXITED(x) (WTERMSIG (x) == 0)
|
|
|
|
|
# endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#else /* Have 'union wait'. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# define WAIT_T union wait
|
|
|
|
|
# ifndef WTERMSIG
|
|
|
|
|
# define WTERMSIG(x) ((x).w_termsig)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WCOREDUMP
|
|
|
|
|
# define WCOREDUMP(x) ((x).w_coredump)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WEXITSTATUS
|
|
|
|
|
# define WEXITSTATUS(x) ((x).w_retcode)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WIFSIGNALED
|
|
|
|
|
# define WIFSIGNALED(x) (WTERMSIG(x) != 0)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef WIFEXITED
|
|
|
|
|
# define WIFEXITED(x) (WTERMSIG(x) == 0)
|
|
|
|
|
# endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#endif /* Don't have 'union wait'. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2010-07-19 15:10:53 +08:00
|
|
|
|
#if !defined(HAVE_UNISTD_H) && !defined(WINDOWS32)
|
2006-04-07 09:43:44 +08:00
|
|
|
|
int dup2 ();
|
|
|
|
|
int execve ();
|
|
|
|
|
void _exit ();
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# ifndef VMS
|
2006-04-07 09:43:44 +08:00
|
|
|
|
int geteuid ();
|
|
|
|
|
int getegid ();
|
|
|
|
|
int setgid ();
|
|
|
|
|
int getgid ();
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# endif
|
1992-06-11 13:25:28 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2010-07-06 02:32:03 +08:00
|
|
|
|
/* Different systems have different requirements for pid_t.
|
|
|
|
|
Plus we have to support gettext string translation... Argh. */
|
|
|
|
|
static const char *
|
|
|
|
|
pid2str (pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
static char pidstring[100];
|
2010-07-24 16:27:50 +08:00
|
|
|
|
#if defined(WINDOWS32) && (__GNUC__ > 3 || _MSC_VER > 1300)
|
|
|
|
|
/* %Id is only needed for 64-builds, which were not supported by
|
|
|
|
|
older versions of Windows compilers. */
|
2010-07-06 02:32:03 +08:00
|
|
|
|
sprintf (pidstring, "%Id", pid);
|
|
|
|
|
#else
|
|
|
|
|
sprintf (pidstring, "%lu", (unsigned long) pid);
|
|
|
|
|
#endif
|
|
|
|
|
return pidstring;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-07 09:43:44 +08:00
|
|
|
|
int getloadavg (double loadavg[], int nelem);
|
|
|
|
|
int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote,
|
|
|
|
|
int *id_ptr, int *used_stdin);
|
|
|
|
|
int start_remote_job_p (int);
|
|
|
|
|
int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr,
|
|
|
|
|
int block);
|
|
|
|
|
|
|
|
|
|
RETSIGTYPE child_handler (int);
|
|
|
|
|
static void free_child (struct child *);
|
|
|
|
|
static void start_job_command (struct child *child);
|
|
|
|
|
static int load_too_high (void);
|
|
|
|
|
static int job_next_command (struct child *);
|
|
|
|
|
static int start_waiting_job (struct child *);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1992-06-13 07:41:40 +08:00
|
|
|
|
/* Chain of all live (or recently deceased) children. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
struct child *children = 0;
|
|
|
|
|
|
|
|
|
|
/* Number of children currently running. */
|
|
|
|
|
|
|
|
|
|
unsigned int job_slots_used = 0;
|
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
/* Nonzero if the 'good' standard input is in use. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
static int good_stdin_used = 0;
|
1992-06-13 07:41:40 +08:00
|
|
|
|
|
|
|
|
|
/* Chain of children waiting to run until the load average goes down. */
|
|
|
|
|
|
|
|
|
|
static struct child *waiting_jobs = 0;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
/* Non-zero if we use a *real* shell (always so on Unix). */
|
|
|
|
|
|
|
|
|
|
int unixy_shell = 1;
|
1999-07-24 06:46:47 +08:00
|
|
|
|
|
2004-01-21 14:32:59 +08:00
|
|
|
|
/* Number of jobs started in the current second. */
|
|
|
|
|
|
|
|
|
|
unsigned long job_counter = 0;
|
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
/* Number of jobserver tokens this instance is currently using. */
|
|
|
|
|
|
|
|
|
|
unsigned int jobserver_tokens = 0;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-23 05:51:45 +08:00
|
|
|
|
/*
|
2013-01-21 00:01:01 +08:00
|
|
|
|
* The macro which references this function is defined in makeint.h.
|
1996-05-23 05:51:45 +08:00
|
|
|
|
*/
|
2003-03-25 07:14:15 +08:00
|
|
|
|
int
|
2013-05-17 14:29:46 +08:00
|
|
|
|
w32_kill (pid_t pid, int sig)
|
1996-05-23 05:51:45 +08:00
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
return ((process_kill ((HANDLE)pid, sig) == TRUE) ? 0 : -1);
|
2004-10-06 21:09:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-02-01 15:54:22 +08:00
|
|
|
|
/* This function creates a temporary file name with an extension specified
|
|
|
|
|
* by the unixy arg.
|
|
|
|
|
* Return an xmalloc'ed string of a newly created temp file and its
|
|
|
|
|
* file descriptor, or die. */
|
2004-10-06 21:09:22 +08:00
|
|
|
|
static char *
|
2006-02-01 15:54:22 +08:00
|
|
|
|
create_batch_file (char const *base, int unixy, int *fd)
|
2004-10-06 21:09:22 +08:00
|
|
|
|
{
|
|
|
|
|
const char *const ext = unixy ? "sh" : "bat";
|
2010-07-06 02:32:03 +08:00
|
|
|
|
const char *error_string = NULL;
|
2004-10-06 21:09:22 +08:00
|
|
|
|
char temp_path[MAXPATHLEN]; /* need to know its length */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
unsigned path_size = GetTempPath (sizeof temp_path, temp_path);
|
2004-10-06 21:09:22 +08:00
|
|
|
|
int path_is_dot = 0;
|
2012-12-07 22:11:15 +08:00
|
|
|
|
/* The following variable is static so we won't try to reuse a name
|
|
|
|
|
that was generated a little while ago, because that file might
|
|
|
|
|
not be on disk yet, since we use FILE_ATTRIBUTE_TEMPORARY below,
|
|
|
|
|
which tells the OS it doesn't need to flush the cache to disk.
|
|
|
|
|
If the file is not yet on disk, we might think the name is
|
|
|
|
|
available, while it really isn't. This happens in parallel
|
|
|
|
|
builds, where Make doesn't wait for one job to finish before it
|
|
|
|
|
launches the next one. */
|
2012-12-08 18:26:36 +08:00
|
|
|
|
static unsigned uniq = 0;
|
2012-12-07 22:11:15 +08:00
|
|
|
|
static int second_loop = 0;
|
2004-10-06 21:09:22 +08:00
|
|
|
|
const unsigned sizemax = strlen (base) + strlen (ext) + 10;
|
|
|
|
|
|
|
|
|
|
if (path_size == 0)
|
|
|
|
|
{
|
|
|
|
|
path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
|
|
|
|
|
path_is_dot = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-08 18:26:36 +08:00
|
|
|
|
++uniq;
|
|
|
|
|
if (uniq >= 0x10000 && !second_loop)
|
|
|
|
|
{
|
|
|
|
|
/* If we already had 64K batch files in this
|
2013-05-17 14:29:46 +08:00
|
|
|
|
process, make a second loop through the numbers,
|
|
|
|
|
looking for free slots, i.e. files that were
|
|
|
|
|
deleted in the meantime. */
|
2012-12-08 18:26:36 +08:00
|
|
|
|
second_loop = 1;
|
|
|
|
|
uniq = 1;
|
|
|
|
|
}
|
2004-10-06 21:09:22 +08:00
|
|
|
|
while (path_size > 0 &&
|
|
|
|
|
path_size + sizemax < sizeof temp_path &&
|
2012-12-07 22:11:15 +08:00
|
|
|
|
!(uniq >= 0x10000 && second_loop))
|
2004-10-06 21:09:22 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned size = sprintf (temp_path + path_size,
|
|
|
|
|
"%s%s-%x.%s",
|
|
|
|
|
temp_path[path_size - 1] == '\\' ? "" : "\\",
|
|
|
|
|
base, uniq, ext);
|
|
|
|
|
HANDLE h = CreateFile (temp_path, /* file name */
|
|
|
|
|
GENERIC_READ | GENERIC_WRITE, /* desired access */
|
|
|
|
|
0, /* no share mode */
|
|
|
|
|
NULL, /* default security attributes */
|
|
|
|
|
CREATE_NEW, /* creation disposition */
|
|
|
|
|
FILE_ATTRIBUTE_NORMAL | /* flags and attributes */
|
|
|
|
|
FILE_ATTRIBUTE_TEMPORARY, /* we'll delete it */
|
|
|
|
|
NULL); /* no template file */
|
|
|
|
|
|
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
const DWORD er = GetLastError ();
|
2004-10-06 21:09:22 +08:00
|
|
|
|
|
|
|
|
|
if (er == ERROR_FILE_EXISTS || er == ERROR_ALREADY_EXISTS)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
++uniq;
|
|
|
|
|
if (uniq == 0x10000 && !second_loop)
|
|
|
|
|
{
|
|
|
|
|
second_loop = 1;
|
|
|
|
|
uniq = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-06 21:09:22 +08:00
|
|
|
|
|
|
|
|
|
/* the temporary path is not guaranteed to exist */
|
|
|
|
|
else if (path_is_dot == 0)
|
|
|
|
|
{
|
|
|
|
|
path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
|
|
|
|
|
path_is_dot = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-07-06 02:32:03 +08:00
|
|
|
|
error_string = map_windows32_error_to_string (er);
|
2004-10-06 21:09:22 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const unsigned final_size = path_size + size + 1;
|
2006-04-10 06:09:24 +08:00
|
|
|
|
char *const path = xmalloc (final_size);
|
2004-10-06 21:09:22 +08:00
|
|
|
|
memcpy (path, temp_path, final_size);
|
2010-07-09 19:10:04 +08:00
|
|
|
|
*fd = _open_osfhandle ((intptr_t)h, 0);
|
2004-10-06 21:09:22 +08:00
|
|
|
|
if (unixy)
|
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
int ch;
|
|
|
|
|
for (p = path; (ch = *p) != 0; ++p)
|
|
|
|
|
if (ch == '\\')
|
|
|
|
|
*p = '/';
|
|
|
|
|
}
|
|
|
|
|
return path; /* good return */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-01 15:54:22 +08:00
|
|
|
|
*fd = -1;
|
2010-07-06 02:32:03 +08:00
|
|
|
|
if (error_string == NULL)
|
|
|
|
|
error_string = _("Cannot create a temporary file\n");
|
|
|
|
|
fatal (NILF, error_string);
|
2004-10-06 21:09:22 +08:00
|
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
|
return NULL;
|
1996-05-23 05:51:45 +08:00
|
|
|
|
}
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
#ifdef __EMX__
|
|
|
|
|
/* returns whether path is assumed to be a unix like shell. */
|
|
|
|
|
int
|
|
|
|
|
_is_unixy_shell (const char *path)
|
|
|
|
|
{
|
|
|
|
|
/* list of non unix shells */
|
|
|
|
|
const char *known_os2shells[] = {
|
|
|
|
|
"cmd.exe",
|
|
|
|
|
"cmd",
|
|
|
|
|
"4os2.exe",
|
|
|
|
|
"4os2",
|
|
|
|
|
"4dos.exe",
|
|
|
|
|
"4dos",
|
|
|
|
|
"command.com",
|
|
|
|
|
"command",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* find the rightmost '/' or '\\' */
|
|
|
|
|
const char *name = strrchr (path, '/');
|
|
|
|
|
const char *p = strrchr (path, '\\');
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
if (name && p) /* take the max */
|
|
|
|
|
name = (name > p) ? name : p;
|
|
|
|
|
else if (p) /* name must be 0 */
|
|
|
|
|
name = p;
|
|
|
|
|
else if (!name) /* name and p must be 0 */
|
|
|
|
|
name = path;
|
|
|
|
|
|
|
|
|
|
if (*name == '/' || *name == '\\') name++;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
while (known_os2shells[i] != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcasecmp (name, known_os2shells[i]) == 0)
|
|
|
|
|
return 0; /* not a unix shell */
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
/* in doubt assume a unix like shell */
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
#endif /* __EMX__ */
|
|
|
|
|
|
2010-07-12 13:23:19 +08:00
|
|
|
|
/* determines whether path looks to be a Bourne-like shell. */
|
|
|
|
|
int
|
|
|
|
|
is_bourne_compatible_shell (const char *path)
|
|
|
|
|
{
|
2013-07-22 05:52:13 +08:00
|
|
|
|
/* List of known POSIX (or POSIX-ish) shells. */
|
|
|
|
|
static const char *unix_shells[] = {
|
2010-07-12 13:23:19 +08:00
|
|
|
|
"sh",
|
|
|
|
|
"bash",
|
|
|
|
|
"ksh",
|
|
|
|
|
"rksh",
|
|
|
|
|
"zsh",
|
|
|
|
|
"ash",
|
|
|
|
|
"dash",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2013-07-22 05:52:13 +08:00
|
|
|
|
const char **s;
|
2010-07-12 13:23:19 +08:00
|
|
|
|
|
|
|
|
|
/* find the rightmost '/' or '\\' */
|
|
|
|
|
const char *name = strrchr (path, '/');
|
|
|
|
|
char *p = strrchr (path, '\\');
|
|
|
|
|
|
|
|
|
|
if (name && p) /* take the max */
|
|
|
|
|
name = (name > p) ? name : p;
|
|
|
|
|
else if (p) /* name must be 0 */
|
|
|
|
|
name = p;
|
|
|
|
|
else if (!name) /* name and p must be 0 */
|
|
|
|
|
name = path;
|
|
|
|
|
|
2013-07-22 05:52:13 +08:00
|
|
|
|
if (*name == '/' || *name == '\\')
|
|
|
|
|
++name;
|
2010-07-12 13:23:19 +08:00
|
|
|
|
|
|
|
|
|
/* this should be able to deal with extensions on Windows-like systems */
|
2013-07-22 05:52:13 +08:00
|
|
|
|
for (s = unix_shells; *s != NULL; ++s)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
2010-07-12 13:23:19 +08:00
|
|
|
|
#if defined(WINDOWS32) || defined(__MSDOS__)
|
2013-07-22 05:52:13 +08:00
|
|
|
|
unsigned int len = strlen (*s);
|
|
|
|
|
if ((strlen (name) >= len && STOP_SET (name[len], MAP_DOT|MAP_NUL))
|
|
|
|
|
&& strncasecmp (name, *s, len) == 0)
|
2010-07-12 13:23:19 +08:00
|
|
|
|
#else
|
2013-07-22 05:52:13 +08:00
|
|
|
|
if (strcmp (name, *s) == 0)
|
2010-07-12 13:23:19 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
return 1; /* a known unix-style shell */
|
|
|
|
|
}
|
2010-07-12 13:23:19 +08:00
|
|
|
|
|
|
|
|
|
/* if not on the list, assume it's not a Bourne-like shell */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1996-05-23 05:51:45 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Write an error message describing the exit status given in
|
|
|
|
|
EXIT_CODE, EXIT_SIG, and COREDUMP, for the target TARGET_NAME.
|
|
|
|
|
Append "(ignored)" if IGNORED is nonzero. */
|
|
|
|
|
|
|
|
|
|
static void
|
2013-09-12 16:07:52 +08:00
|
|
|
|
child_error (struct child *child,
|
2007-03-20 11:02:26 +08:00
|
|
|
|
int exit_code, int exit_sig, int coredump, int ignored)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
2010-08-30 07:05:26 +08:00
|
|
|
|
const char *pre = "*** ";
|
|
|
|
|
const char *post = "";
|
|
|
|
|
const char *dump = "";
|
2013-04-29 07:09:20 +08:00
|
|
|
|
const struct file *f = child->file;
|
2013-05-05 01:10:56 +08:00
|
|
|
|
const gmk_floc *flocp = &f->cmds->fileinfo;
|
2013-04-29 07:09:20 +08:00
|
|
|
|
const char *nm;
|
2010-08-30 07:05:26 +08:00
|
|
|
|
|
1995-08-08 04:37:15 +08:00
|
|
|
|
if (ignored && silent_flag)
|
|
|
|
|
return;
|
2006-02-12 03:02:21 +08:00
|
|
|
|
|
2010-08-30 07:05:26 +08:00
|
|
|
|
if (exit_sig && coredump)
|
|
|
|
|
dump = _(" (core dumped)");
|
|
|
|
|
|
|
|
|
|
if (ignored)
|
|
|
|
|
{
|
|
|
|
|
pre = "";
|
|
|
|
|
post = _(" (ignored)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! flocp->filenm)
|
|
|
|
|
nm = _("<builtin>");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *a = alloca (strlen (flocp->filenm) + 1 + 11 + 1);
|
|
|
|
|
sprintf (a, "%s:%lu", flocp->filenm, flocp->lineno);
|
|
|
|
|
nm = a;
|
|
|
|
|
}
|
2013-04-29 07:09:20 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
OUTPUT_SET (&child->output);
|
2013-04-29 07:09:20 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
message (0, _("%s: recipe for target '%s' failed"), nm, f->name);
|
2010-08-30 07:05:26 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
2013-05-06 05:03:51 +08:00
|
|
|
|
if ((exit_code & 1) != 0)
|
2013-09-12 16:07:52 +08:00
|
|
|
|
{
|
|
|
|
|
OUTPUT_UNSET ();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-04-29 07:09:20 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
error (NILF, _("%s[%s] Error 0x%x%s"), pre, f->name, exit_code, post);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#else
|
1992-01-21 02:49:36 +08:00
|
|
|
|
if (exit_sig == 0)
|
2013-09-12 16:07:52 +08:00
|
|
|
|
error (NILF, _("%s[%s] Error %d%s"), pre, f->name, exit_code, post);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
else
|
2013-04-29 07:09:20 +08:00
|
|
|
|
{
|
|
|
|
|
const char *s = strsignal (exit_sig);
|
2013-09-12 16:07:52 +08:00
|
|
|
|
error (NILF, _("%s[%s] %s%s%s"), pre, f->name, s, dump, post);
|
2013-04-29 07:09:20 +08:00
|
|
|
|
}
|
1996-05-14 02:38:29 +08:00
|
|
|
|
#endif /* VMS */
|
2013-04-29 07:09:20 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
OUTPUT_UNSET ();
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
1999-08-01 14:05:17 +08:00
|
|
|
|
/* Handle a dead child. This handler may or may not ever be installed.
|
|
|
|
|
|
1999-08-13 15:36:26 +08:00
|
|
|
|
If we're using the jobserver feature, we need it. First, installing it
|
|
|
|
|
ensures the read will interrupt on SIGCHLD. Second, we close the dup'd
|
|
|
|
|
read FD to ensure we don't enter another blocking read without reaping all
|
|
|
|
|
the dead children. In this case we don't need the dead_children count.
|
1999-08-01 14:05:17 +08:00
|
|
|
|
|
|
|
|
|
If we don't have either waitpid or wait3, then make is unreliable, but we
|
1999-08-01 16:12:06 +08:00
|
|
|
|
use the dead_children count to reap children as best we can. */
|
1998-10-03 13:39:55 +08:00
|
|
|
|
|
|
|
|
|
static unsigned int dead_children = 0;
|
|
|
|
|
|
1992-06-11 13:25:28 +08:00
|
|
|
|
RETSIGTYPE
|
2004-02-24 21:50:19 +08:00
|
|
|
|
child_handler (int sig UNUSED)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
1992-05-09 10:26:35 +08:00
|
|
|
|
++dead_children;
|
|
|
|
|
|
1999-08-13 15:36:26 +08:00
|
|
|
|
if (job_rfd >= 0)
|
1999-08-01 16:12:06 +08:00
|
|
|
|
{
|
1999-08-13 15:36:26 +08:00
|
|
|
|
close (job_rfd);
|
|
|
|
|
job_rfd = -1;
|
1999-08-01 16:12:06 +08:00
|
|
|
|
}
|
1999-08-01 14:05:17 +08:00
|
|
|
|
|
2004-02-23 14:25:54 +08:00
|
|
|
|
#ifdef __EMX__
|
|
|
|
|
/* The signal handler must called only once! */
|
|
|
|
|
signal (SIGCHLD, SIG_DFL);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* This causes problems if the SIGCHLD interrupts a printf().
|
1999-11-22 14:15:35 +08:00
|
|
|
|
DB (DB_JOBS, (_("Got a SIGCHLD; %u unreaped children.\n"), dead_children));
|
2004-02-23 14:25:54 +08:00
|
|
|
|
*/
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
1998-10-03 13:39:55 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
extern int shell_function_pid, shell_function_completed;
|
|
|
|
|
|
1999-08-01 16:12:06 +08:00
|
|
|
|
/* Reap all dead children, storing the returned status and the new command
|
2012-03-04 08:24:20 +08:00
|
|
|
|
state ('cs_finished') in the 'file' member of the 'struct child' for the
|
1999-08-01 16:12:06 +08:00
|
|
|
|
dead child, and removing the child from the chain. In addition, if BLOCK
|
|
|
|
|
nonzero, we block in this function until we've reaped at least one
|
|
|
|
|
complete child, waiting for it to die if necessary. If ERR is nonzero,
|
|
|
|
|
print an error message first. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1992-04-21 15:59:32 +08:00
|
|
|
|
void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
reap_children (int block, int err)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
2005-08-08 13:08:00 +08:00
|
|
|
|
#ifndef WINDOWS32
|
1992-01-21 02:49:36 +08:00
|
|
|
|
WAIT_T status;
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#endif
|
1999-04-25 12:30:55 +08:00
|
|
|
|
/* Initially, assume we have some. */
|
|
|
|
|
int reap_more = 1;
|
1999-08-23 01:50:57 +08:00
|
|
|
|
|
|
|
|
|
#ifdef WAIT_NOHANG
|
1999-04-25 12:30:55 +08:00
|
|
|
|
# define REAP_MORE reap_more
|
|
|
|
|
#else
|
|
|
|
|
# define REAP_MORE dead_children
|
1998-10-03 13:39:55 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1999-08-23 01:50:57 +08:00
|
|
|
|
/* As long as:
|
|
|
|
|
|
|
|
|
|
We have at least one child outstanding OR a shell function in progress,
|
|
|
|
|
AND
|
|
|
|
|
We're blocking for a complete child OR there are more children to reap
|
|
|
|
|
|
|
|
|
|
we'll keep reaping children. */
|
|
|
|
|
|
2001-06-01 11:56:50 +08:00
|
|
|
|
while ((children != 0 || shell_function_pid != 0)
|
|
|
|
|
&& (block || REAP_MORE))
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
|
|
|
|
int remote = 0;
|
2004-03-22 23:11:48 +08:00
|
|
|
|
pid_t pid;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
int exit_code, exit_sig, coredump;
|
2010-08-30 07:05:26 +08:00
|
|
|
|
struct child *lastc, *c;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
int child_failed;
|
1993-08-12 03:32:02 +08:00
|
|
|
|
int any_remote, any_local;
|
2005-06-01 04:54:30 +08:00
|
|
|
|
int dontcare;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
if (err && block)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
2005-08-08 13:08:00 +08:00
|
|
|
|
static int printed = 0;
|
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* We might block for a while, so let the user know why.
|
2005-08-08 13:08:00 +08:00
|
|
|
|
Only print this message once no matter how many jobs are left. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
fflush (stdout);
|
2005-08-08 13:08:00 +08:00
|
|
|
|
if (!printed)
|
|
|
|
|
error (NILF, _("*** Waiting for unfinished jobs...."));
|
|
|
|
|
printed = 1;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
1992-04-21 15:59:32 +08:00
|
|
|
|
|
1999-04-25 12:30:55 +08:00
|
|
|
|
/* We have one less dead child to reap. As noted in
|
2013-05-17 14:29:46 +08:00
|
|
|
|
child_handler() above, this count is completely unimportant for
|
|
|
|
|
all modern, POSIX-y systems that support wait3() or waitpid().
|
|
|
|
|
The rest of this comment below applies only to early, broken
|
|
|
|
|
pre-POSIX systems. We keep the count only because... it's there...
|
|
|
|
|
|
|
|
|
|
The test and decrement are not atomic; if it is compiled into:
|
|
|
|
|
register = dead_children - 1;
|
|
|
|
|
dead_children = register;
|
|
|
|
|
a SIGCHLD could come between the two instructions.
|
|
|
|
|
child_handler increments dead_children.
|
|
|
|
|
The second instruction here would lose that increment. But the
|
|
|
|
|
only effect of dead_children being wrong is that we might wait
|
|
|
|
|
longer than necessary to reap a child, and lose some parallelism;
|
|
|
|
|
and we might print the "Waiting for unfinished jobs" message above
|
|
|
|
|
when not necessary. */
|
1992-05-09 10:26:35 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
if (dead_children > 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
--dead_children;
|
1992-05-09 10:26:35 +08:00
|
|
|
|
|
1993-08-10 06:25:00 +08:00
|
|
|
|
any_remote = 0;
|
1996-06-23 03:30:59 +08:00
|
|
|
|
any_local = shell_function_pid != 0;
|
1993-08-10 06:25:00 +08:00
|
|
|
|
for (c = children; c != 0; c = c->next)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
any_remote |= c->remote;
|
|
|
|
|
any_local |= ! c->remote;
|
|
|
|
|
DB (DB_JOBS, (_("Live child %p (%s) PID %s %s\n"),
|
2010-07-06 02:32:03 +08:00
|
|
|
|
c, c->file->name, pid2str (c->pid),
|
|
|
|
|
c->remote ? _(" (remote)") : ""));
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
2013-05-17 14:29:46 +08:00
|
|
|
|
break;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
1992-04-21 15:59:32 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* First, check for remote children. */
|
1993-08-10 06:25:00 +08:00
|
|
|
|
if (any_remote)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
pid = remote_status (&exit_code, &exit_sig, &coredump, 0);
|
1993-08-10 06:25:00 +08:00
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
pid = 0;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
if (pid > 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* We got a remote child. */
|
|
|
|
|
remote = 1;
|
1998-10-03 13:39:55 +08:00
|
|
|
|
else if (pid < 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
1998-10-03 13:39:55 +08:00
|
|
|
|
/* A remote status command failed miserably. Punt. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
remote_status_lose:
|
|
|
|
|
pfatal_with_name ("remote_status");
|
|
|
|
|
}
|
1998-10-03 13:39:55 +08:00
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* No remote children. Check for local children. */
|
1998-10-03 13:39:55 +08:00
|
|
|
|
#if !defined(__MSDOS__) && !defined(_AMIGA) && !defined(WINDOWS32)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (any_local)
|
|
|
|
|
{
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
2013-05-17 14:29:46 +08:00
|
|
|
|
vmsWaitForChildren (&status);
|
|
|
|
|
pid = c->pid;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#else
|
|
|
|
|
#ifdef WAIT_NOHANG
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (!block)
|
|
|
|
|
pid = WAIT_NOHANG (&status);
|
|
|
|
|
else
|
1992-04-21 15:59:32 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
EINTRLOOP(pid, wait (&status));
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif /* !VMS */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
pid = 0;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (pid < 0)
|
|
|
|
|
{
|
1999-08-23 01:50:57 +08:00
|
|
|
|
/* The wait*() failed miserably. Punt. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
pfatal_with_name ("wait");
|
|
|
|
|
}
|
|
|
|
|
else if (pid > 0)
|
|
|
|
|
{
|
|
|
|
|
/* We got a child exit; chop the status word up. */
|
|
|
|
|
exit_code = WEXITSTATUS (status);
|
|
|
|
|
exit_sig = WIFSIGNALED (status) ? WTERMSIG (status) : 0;
|
|
|
|
|
coredump = WCOREDUMP (status);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
2004-01-21 14:32:59 +08:00
|
|
|
|
/* If we have started jobs in this second, remove one. */
|
|
|
|
|
if (job_counter)
|
|
|
|
|
--job_counter;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* No local children are dead. */
|
1999-04-25 12:30:55 +08:00
|
|
|
|
reap_more = 0;
|
1999-08-23 01:50:57 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (!block || !any_remote)
|
1999-08-23 01:50:57 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Now try a blocking wait for a remote child. */
|
|
|
|
|
pid = remote_status (&exit_code, &exit_sig, &coredump, 1);
|
|
|
|
|
if (pid < 0)
|
|
|
|
|
goto remote_status_lose;
|
|
|
|
|
else if (pid == 0)
|
|
|
|
|
/* No remote children either. Finally give up. */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* We got a remote child. */
|
|
|
|
|
remote = 1;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
1998-10-03 13:39:55 +08:00
|
|
|
|
#endif /* !__MSDOS__, !Amiga, !WINDOWS32. */
|
1999-08-23 01:50:57 +08:00
|
|
|
|
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
#ifdef __MSDOS__
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Life is very different on MSDOS. */
|
|
|
|
|
pid = dos_pid - 1;
|
|
|
|
|
status = dos_status;
|
|
|
|
|
exit_code = WEXITSTATUS (status);
|
|
|
|
|
if (exit_code == 0xff)
|
|
|
|
|
exit_code = -1;
|
|
|
|
|
exit_sig = WIFSIGNALED (status) ? WTERMSIG (status) : 0;
|
|
|
|
|
coredump = 0;
|
1996-05-23 05:51:45 +08:00
|
|
|
|
#endif /* __MSDOS__ */
|
|
|
|
|
#ifdef _AMIGA
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Same on Amiga */
|
|
|
|
|
pid = amiga_pid - 1;
|
|
|
|
|
status = amiga_status;
|
|
|
|
|
exit_code = amiga_status;
|
|
|
|
|
exit_sig = 0;
|
|
|
|
|
coredump = 0;
|
1996-05-23 05:51:45 +08:00
|
|
|
|
#endif /* _AMIGA */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1998-10-03 13:39:55 +08:00
|
|
|
|
{
|
|
|
|
|
HANDLE hPID;
|
2005-08-08 13:08:00 +08:00
|
|
|
|
HANDLE hcTID, hcPID;
|
2011-11-14 08:42:49 +08:00
|
|
|
|
DWORD dwWaitStatus = 0;
|
2004-03-22 23:11:48 +08:00
|
|
|
|
exit_code = 0;
|
|
|
|
|
exit_sig = 0;
|
|
|
|
|
coredump = 0;
|
1996-06-23 05:42:10 +08:00
|
|
|
|
|
2005-08-08 13:08:00 +08:00
|
|
|
|
/* Record the thread ID of the main process, so that we
|
|
|
|
|
could suspend it in the signal handler. */
|
|
|
|
|
if (!main_thread)
|
|
|
|
|
{
|
|
|
|
|
hcTID = GetCurrentThread ();
|
|
|
|
|
hcPID = GetCurrentProcess ();
|
|
|
|
|
if (!DuplicateHandle (hcPID, hcTID, hcPID, &main_thread, 0,
|
|
|
|
|
FALSE, DUPLICATE_SAME_ACCESS))
|
|
|
|
|
{
|
|
|
|
|
DWORD e = GetLastError ();
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
"Determine main thread ID (Error %ld: %s)\n",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
e, map_windows32_error_to_string (e));
|
2005-08-08 13:08:00 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
2010-07-06 02:32:03 +08:00
|
|
|
|
DB (DB_VERBOSE, ("Main thread handle = %p\n", main_thread));
|
2005-08-08 13:08:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
1998-10-03 13:39:55 +08:00
|
|
|
|
/* wait for anything to finish */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
hPID = process_wait_for_any (block, &dwWaitStatus);
|
2004-03-22 23:11:48 +08:00
|
|
|
|
if (hPID)
|
|
|
|
|
{
|
|
|
|
|
/* was an error found on this process? */
|
2013-07-22 05:52:13 +08:00
|
|
|
|
int werr = process_last_err (hPID);
|
1996-06-23 05:42:10 +08:00
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
/* get exit data */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
exit_code = process_exit_code (hPID);
|
1996-06-23 05:42:10 +08:00
|
|
|
|
|
2005-08-08 13:08:00 +08:00
|
|
|
|
if (werr)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
fprintf (stderr, "make (e=%d): %s", exit_code,
|
|
|
|
|
map_windows32_error_to_string (exit_code));
|
1996-06-23 05:42:10 +08:00
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
/* signal */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
exit_sig = process_signal (hPID);
|
1996-06-23 05:42:10 +08:00
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
/* cleanup process */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
process_cleanup (hPID);
|
1996-06-23 05:42:10 +08:00
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
coredump = 0;
|
|
|
|
|
}
|
2011-11-14 08:42:49 +08:00
|
|
|
|
else if (dwWaitStatus == WAIT_FAILED)
|
|
|
|
|
{
|
|
|
|
|
/* The WaitForMultipleObjects() failed miserably. Punt. */
|
|
|
|
|
pfatal_with_name ("WaitForMultipleObjects");
|
|
|
|
|
}
|
|
|
|
|
else if (dwWaitStatus == WAIT_TIMEOUT)
|
|
|
|
|
{
|
|
|
|
|
/* No child processes are finished. Give up waiting. */
|
|
|
|
|
reap_more = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
pid = (pid_t) hPID;
|
1998-10-03 13:39:55 +08:00
|
|
|
|
}
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
/* Check if this is the child of the 'shell' function. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
if (!remote && pid == shell_function_pid)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* It is. Leave an indicator for the 'shell' function. */
|
|
|
|
|
if (exit_sig == 0 && exit_code == 127)
|
|
|
|
|
shell_function_completed = -1;
|
|
|
|
|
else
|
|
|
|
|
shell_function_completed = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
child_failed = exit_sig != 0 || exit_code != 0;
|
|
|
|
|
|
|
|
|
|
/* Search for a child matching the deceased one. */
|
|
|
|
|
lastc = 0;
|
|
|
|
|
for (c = children; c != 0; lastc = c, c = c->next)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (c->pid == pid && c->remote == remote)
|
|
|
|
|
break;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
if (c == 0)
|
1999-07-24 12:55:08 +08:00
|
|
|
|
/* An unknown child died.
|
|
|
|
|
Ignore it; it was inherited from our invoker. */
|
|
|
|
|
continue;
|
|
|
|
|
|
1999-11-22 14:15:35 +08:00
|
|
|
|
DB (DB_JOBS, (child_failed
|
2010-07-06 02:32:03 +08:00
|
|
|
|
? _("Reaping losing child %p PID %s %s\n")
|
|
|
|
|
: _("Reaping winning child %p PID %s %s\n"),
|
|
|
|
|
c, pid2str (c->pid), c->remote ? _(" (remote)") : ""));
|
1999-07-24 12:55:08 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (c->sh_batch_file)
|
|
|
|
|
{
|
|
|
|
|
int rm_status;
|
2012-12-07 22:11:15 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
DB (DB_JOBS, (_("Cleaning up temp batch file %s\n"),
|
|
|
|
|
c->sh_batch_file));
|
1999-07-24 12:55:08 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
errno = 0;
|
|
|
|
|
rm_status = remove (c->sh_batch_file);
|
|
|
|
|
if (rm_status)
|
|
|
|
|
DB (DB_JOBS, (_("Cleaning up temp batch file %s failed (%d)\n"),
|
|
|
|
|
c->sh_batch_file, errno));
|
1999-07-24 12:55:08 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* all done with memory */
|
|
|
|
|
free (c->sh_batch_file);
|
|
|
|
|
c->sh_batch_file = NULL;
|
|
|
|
|
}
|
1999-07-24 12:55:08 +08:00
|
|
|
|
|
|
|
|
|
/* If this child had the good stdin, say it is now free. */
|
|
|
|
|
if (c->good_stdin)
|
|
|
|
|
good_stdin_used = 0;
|
|
|
|
|
|
2006-03-20 11:03:04 +08:00
|
|
|
|
dontcare = c->dontcare;
|
2005-06-01 04:54:30 +08:00
|
|
|
|
|
1999-07-24 12:55:08 +08:00
|
|
|
|
if (child_failed && !c->noerror && !ignore_errors_flag)
|
|
|
|
|
{
|
|
|
|
|
/* The commands failed. Write an error message,
|
|
|
|
|
delete non-precious targets, and abort. */
|
|
|
|
|
static int delete_on_error = -1;
|
2005-06-01 04:54:30 +08:00
|
|
|
|
|
|
|
|
|
if (!dontcare)
|
2013-04-29 07:09:20 +08:00
|
|
|
|
child_error (c, exit_code, exit_sig, coredump, 0);
|
2005-06-01 04:54:30 +08:00
|
|
|
|
|
2013-07-15 07:18:21 +08:00
|
|
|
|
c->file->update_status = us_failed;
|
1999-07-24 12:55:08 +08:00
|
|
|
|
if (delete_on_error == -1)
|
|
|
|
|
{
|
|
|
|
|
struct file *f = lookup_file (".DELETE_ON_ERROR");
|
|
|
|
|
delete_on_error = f != 0 && f->is_target;
|
|
|
|
|
}
|
|
|
|
|
if (exit_sig != 0 || delete_on_error)
|
|
|
|
|
delete_child_targets (c);
|
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
else
|
1999-07-24 12:55:08 +08:00
|
|
|
|
{
|
|
|
|
|
if (child_failed)
|
|
|
|
|
{
|
|
|
|
|
/* The commands failed, but we don't care. */
|
2013-04-29 07:09:20 +08:00
|
|
|
|
child_error (c, exit_code, exit_sig, coredump, 1);
|
1999-07-24 12:55:08 +08:00
|
|
|
|
child_failed = 0;
|
|
|
|
|
}
|
1996-06-23 03:30:59 +08:00
|
|
|
|
|
1999-07-24 12:55:08 +08:00
|
|
|
|
/* If there are more commands to run, try to start them. */
|
|
|
|
|
if (job_next_command (c))
|
|
|
|
|
{
|
|
|
|
|
if (handling_fatal_signal)
|
|
|
|
|
{
|
|
|
|
|
/* Never start new commands while we are dying.
|
|
|
|
|
Since there are more commands that wanted to be run,
|
|
|
|
|
the target was not completely remade. So we treat
|
|
|
|
|
this as if a command had failed. */
|
2013-07-15 07:18:21 +08:00
|
|
|
|
c->file->update_status = us_failed;
|
1999-07-24 12:55:08 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-04-29 07:09:20 +08:00
|
|
|
|
#ifdef OUTPUT_SYNC
|
2013-05-05 01:10:56 +08:00
|
|
|
|
/* If we're sync'ing per line, write the previous line's
|
|
|
|
|
output before starting the next one. */
|
2013-05-06 08:19:00 +08:00
|
|
|
|
if (output_sync == OUTPUT_SYNC_LINE)
|
2013-09-12 16:07:52 +08:00
|
|
|
|
output_dump (&c->output);
|
2013-04-29 07:09:20 +08:00
|
|
|
|
#endif
|
1999-07-24 12:55:08 +08:00
|
|
|
|
/* Check again whether to start remotely.
|
|
|
|
|
Whether or not we want to changes over time.
|
|
|
|
|
Also, start_remote_job may need state set up
|
|
|
|
|
by start_remote_job_p. */
|
|
|
|
|
c->remote = start_remote_job_p (0);
|
|
|
|
|
start_job_command (c);
|
|
|
|
|
/* Fatal signals are left blocked in case we were
|
|
|
|
|
about to put that child on the chain. But it is
|
|
|
|
|
already there, so it is safe for a fatal signal to
|
|
|
|
|
arrive now; it will clean up this child's targets. */
|
|
|
|
|
unblock_sigs ();
|
|
|
|
|
if (c->file->command_state == cs_running)
|
|
|
|
|
/* We successfully started the new command.
|
|
|
|
|
Loop to reap more children. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-15 07:18:21 +08:00
|
|
|
|
if (c->file->update_status != us_success)
|
1999-07-24 12:55:08 +08:00
|
|
|
|
/* We failed to start the commands. */
|
|
|
|
|
delete_child_targets (c);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* There are no more commands. We got through them all
|
|
|
|
|
without an unignored error. Now the target has been
|
|
|
|
|
successfully updated. */
|
2013-07-15 07:18:21 +08:00
|
|
|
|
c->file->update_status = us_success;
|
1999-07-24 12:55:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 07:17:19 +08:00
|
|
|
|
/* When we get here, all the commands for c->file are finished. */
|
|
|
|
|
|
|
|
|
|
#ifdef OUTPUT_SYNC
|
2013-05-05 01:10:56 +08:00
|
|
|
|
/* Synchronize any remaining parallel output. */
|
2013-09-12 16:07:52 +08:00
|
|
|
|
output_dump (&c->output);
|
2013-04-16 07:17:19 +08:00
|
|
|
|
#endif /* OUTPUT_SYNC */
|
|
|
|
|
|
2013-07-15 07:18:21 +08:00
|
|
|
|
/* At this point c->file->update_status is success or failed. But
|
2013-04-16 07:17:19 +08:00
|
|
|
|
c->file->command_state is still cs_running if all the commands
|
1999-07-24 12:55:08 +08:00
|
|
|
|
ran; notice_finish_file looks for cs_running to tell it that
|
|
|
|
|
it's interesting to check the file's modtime again now. */
|
|
|
|
|
|
|
|
|
|
if (! handling_fatal_signal)
|
|
|
|
|
/* Notice if the target of the commands has been changed.
|
|
|
|
|
This also propagates its values for command_state and
|
|
|
|
|
update_status to its also_make files. */
|
|
|
|
|
notice_finished_file (c->file);
|
|
|
|
|
|
2010-07-06 02:32:03 +08:00
|
|
|
|
DB (DB_JOBS, (_("Removing child %p PID %s%s from chain.\n"),
|
|
|
|
|
c, pid2str (c->pid), c->remote ? _(" (remote)") : ""));
|
1999-07-24 12:55:08 +08:00
|
|
|
|
|
|
|
|
|
/* Block fatal signals while frobnicating the list, so that
|
|
|
|
|
children and job_slots_used are always consistent. Otherwise
|
|
|
|
|
a fatal signal arriving after the child is off the chain and
|
|
|
|
|
before job_slots_used is decremented would believe a child was
|
|
|
|
|
live and call reap_children again. */
|
|
|
|
|
block_sigs ();
|
|
|
|
|
|
|
|
|
|
/* There is now another slot open. */
|
|
|
|
|
if (job_slots_used > 0)
|
|
|
|
|
--job_slots_used;
|
|
|
|
|
|
|
|
|
|
/* Remove the child from the chain and free it. */
|
|
|
|
|
if (lastc == 0)
|
|
|
|
|
children = c->next;
|
|
|
|
|
else
|
|
|
|
|
lastc->next = c->next;
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
|
|
|
|
free_child (c);
|
1999-07-24 06:46:47 +08:00
|
|
|
|
|
1999-07-24 12:55:08 +08:00
|
|
|
|
unblock_sigs ();
|
1999-04-25 12:30:55 +08:00
|
|
|
|
|
1999-07-24 12:55:08 +08:00
|
|
|
|
/* If the job failed, and the -k flag was not given, die,
|
|
|
|
|
unless we are already in the process of dying. */
|
2005-06-01 04:54:30 +08:00
|
|
|
|
if (!err && child_failed && !dontcare && !keep_going_flag &&
|
1999-07-24 12:55:08 +08:00
|
|
|
|
/* fatal_error_signal will die with the right signal. */
|
|
|
|
|
!handling_fatal_signal)
|
|
|
|
|
die (2);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1992-04-21 15:59:32 +08:00
|
|
|
|
/* Only block for one child. */
|
|
|
|
|
block = 0;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
1999-07-24 12:55:08 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
return;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free the storage allocated for CHILD. */
|
|
|
|
|
|
|
|
|
|
static void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
free_child (struct child *child)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
2013-09-12 16:07:52 +08:00
|
|
|
|
output_close (&child->output);
|
2013-04-28 13:19:19 +08:00
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
if (!jobserver_tokens)
|
2010-07-06 02:32:03 +08:00
|
|
|
|
fatal (NILF, "INTERNAL: Freeing child %p (%s) but no tokens left!\n",
|
|
|
|
|
child, child->file->name);
|
2005-05-03 21:57:20 +08:00
|
|
|
|
|
|
|
|
|
/* If we're using the jobserver and this child is not the only outstanding
|
|
|
|
|
job, put a token back into the pipe for it. */
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#ifdef WINDOWS32
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (has_jobserver_semaphore () && jobserver_tokens > 1)
|
2011-11-14 08:42:49 +08:00
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (! release_jobserver_semaphore ())
|
2011-11-14 08:42:49 +08:00
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
DWORD err = GetLastError ();
|
2011-11-16 05:12:53 +08:00
|
|
|
|
fatal (NILF, _("release jobserver semaphore: (Error %ld: %s)"),
|
2013-05-17 14:29:46 +08:00
|
|
|
|
err, map_windows32_error_to_string (err));
|
2011-11-14 08:42:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB (DB_JOBS, (_("Released token for child %p (%s).\n"), child, child->file->name));
|
|
|
|
|
}
|
|
|
|
|
#else
|
2005-05-03 21:57:20 +08:00
|
|
|
|
if (job_fds[1] >= 0 && jobserver_tokens > 1)
|
1999-08-23 13:35:14 +08:00
|
|
|
|
{
|
1999-08-24 06:15:17 +08:00
|
|
|
|
char token = '+';
|
2003-03-25 07:14:15 +08:00
|
|
|
|
int r;
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
|
|
|
|
/* Write a job token back to the pipe. */
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
EINTRLOOP (r, write (job_fds[1], &token, 1));
|
|
|
|
|
if (r != 1)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
pfatal_with_name (_("write jobserver"));
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
2010-07-06 02:32:03 +08:00
|
|
|
|
DB (DB_JOBS, (_("Released token for child %p (%s).\n"),
|
|
|
|
|
child, child->file->name));
|
1999-08-23 13:35:14 +08:00
|
|
|
|
}
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#endif
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
--jobserver_tokens;
|
|
|
|
|
|
1999-08-23 13:35:14 +08:00
|
|
|
|
if (handling_fatal_signal) /* Don't bother free'ing if about to die. */
|
|
|
|
|
return;
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
if (child->command_lines != 0)
|
|
|
|
|
{
|
|
|
|
|
register unsigned int i;
|
|
|
|
|
for (i = 0; i < child->file->cmds->ncommand_lines; ++i)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
free (child->command_lines[i]);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (child->command_lines);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (child->environment != 0)
|
|
|
|
|
{
|
|
|
|
|
register char **ep = child->environment;
|
|
|
|
|
while (*ep != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
free (*ep++);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (child->environment);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (child);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
1996-06-23 05:42:10 +08:00
|
|
|
|
#ifdef POSIX
|
|
|
|
|
extern sigset_t fatal_signal_set;
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-06-23 03:30:59 +08:00
|
|
|
|
void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
block_sigs (void)
|
1996-06-23 03:30:59 +08:00
|
|
|
|
{
|
1998-10-03 13:39:55 +08:00
|
|
|
|
#ifdef POSIX
|
1996-06-23 03:30:59 +08:00
|
|
|
|
(void) sigprocmask (SIG_BLOCK, &fatal_signal_set, (sigset_t *) 0);
|
|
|
|
|
#else
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# ifdef HAVE_SIGSETMASK
|
1996-06-23 03:30:59 +08:00
|
|
|
|
(void) sigblock (fatal_signal_mask);
|
1998-10-03 13:39:55 +08:00
|
|
|
|
# endif
|
1996-06-23 03:30:59 +08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
#ifdef POSIX
|
1993-02-02 05:02:40 +08:00
|
|
|
|
void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
unblock_sigs (void)
|
1992-05-01 05:50:23 +08:00
|
|
|
|
{
|
|
|
|
|
sigset_t empty;
|
|
|
|
|
sigemptyset (&empty);
|
|
|
|
|
sigprocmask (SIG_SETMASK, &empty, (sigset_t *) 0);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#if defined(MAKE_JOBSERVER) && !defined(WINDOWS32)
|
2005-05-09 00:50:58 +08:00
|
|
|
|
RETSIGTYPE
|
|
|
|
|
job_noop (int sig UNUSED)
|
|
|
|
|
{
|
|
|
|
|
}
|
2001-06-01 11:56:50 +08:00
|
|
|
|
/* Set the child handler action flags to FLAGS. */
|
|
|
|
|
static void
|
2005-05-09 00:50:58 +08:00
|
|
|
|
set_child_handler_action_flags (int set_handler, int set_alarm)
|
2001-06-01 11:56:50 +08:00
|
|
|
|
{
|
|
|
|
|
struct sigaction sa;
|
2005-05-09 00:50:58 +08:00
|
|
|
|
|
|
|
|
|
#ifdef __EMX__
|
|
|
|
|
/* The child handler must be turned off here. */
|
|
|
|
|
signal (SIGCHLD, SIG_DFL);
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
memset (&sa, '\0', sizeof sa);
|
2001-06-01 11:56:50 +08:00
|
|
|
|
sa.sa_handler = child_handler;
|
2005-05-09 00:50:58 +08:00
|
|
|
|
sa.sa_flags = set_handler ? 0 : SA_RESTART;
|
2001-06-01 11:56:50 +08:00
|
|
|
|
#if defined SIGCHLD
|
|
|
|
|
sigaction (SIGCHLD, &sa, NULL);
|
|
|
|
|
#endif
|
|
|
|
|
#if defined SIGCLD && SIGCLD != SIGCHLD
|
|
|
|
|
sigaction (SIGCLD, &sa, NULL);
|
|
|
|
|
#endif
|
2005-05-09 00:50:58 +08:00
|
|
|
|
#if defined SIGALRM
|
|
|
|
|
if (set_alarm)
|
|
|
|
|
{
|
|
|
|
|
/* If we're about to enter the read(), set an alarm to wake up in a
|
|
|
|
|
second so we can check if the load has dropped and we can start more
|
|
|
|
|
work. On the way out, turn off the alarm and set SIG_DFL. */
|
|
|
|
|
alarm (set_handler ? 1 : 0);
|
|
|
|
|
sa.sa_handler = set_handler ? job_noop : SIG_DFL;
|
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
sigaction (SIGALRM, &sa, NULL);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-06-01 11:56:50 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Start a job to run the commands specified in CHILD.
|
1995-12-14 19:21:20 +08:00
|
|
|
|
CHILD is updated to reflect the commands and ID of the child process.
|
|
|
|
|
|
|
|
|
|
NOTE: On return fatal signals are blocked! The caller is responsible
|
2012-03-04 08:24:20 +08:00
|
|
|
|
for calling 'unblock_sigs', once the new child is safely on the chain so
|
1995-12-14 19:21:20 +08:00
|
|
|
|
it can be cleaned up in the event of a fatal signal. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
start_job_command (struct child *child)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
2005-08-08 13:08:00 +08:00
|
|
|
|
#if !defined(_AMIGA) && !defined(WINDOWS32)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
static int bad_stdin = -1;
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
#endif
|
2013-05-06 12:22:27 +08:00
|
|
|
|
int flags;
|
2009-09-24 10:41:44 +08:00
|
|
|
|
char *p;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
char *argv;
|
|
|
|
|
#else
|
1992-01-21 02:49:36 +08:00
|
|
|
|
char **argv;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1999-07-21 06:34:41 +08:00
|
|
|
|
/* If we have a completely empty commandset, stop now. */
|
|
|
|
|
if (!child->command_ptr)
|
|
|
|
|
goto next_command;
|
|
|
|
|
|
1994-10-25 06:50:01 +08:00
|
|
|
|
/* Combine the flags parsed for the line itself with
|
|
|
|
|
the flags specified globally for this target. */
|
|
|
|
|
flags = (child->file->command_flags
|
2013-05-17 14:29:46 +08:00
|
|
|
|
| child->file->cmds->lines_flags[child->command_line - 1]);
|
1994-10-25 06:50:01 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
p = child->command_ptr;
|
2005-09-26 13:16:31 +08:00
|
|
|
|
child->noerror = ((flags & COMMANDS_NOERROR) != 0);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
while (*p != '\0')
|
|
|
|
|
{
|
|
|
|
|
if (*p == '@')
|
2013-05-17 14:29:46 +08:00
|
|
|
|
flags |= COMMANDS_SILENT;
|
1993-09-17 12:37:54 +08:00
|
|
|
|
else if (*p == '+')
|
2013-05-17 14:29:46 +08:00
|
|
|
|
flags |= COMMANDS_RECURSE;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
else if (*p == '-')
|
2013-05-17 14:29:46 +08:00
|
|
|
|
child->noerror = 1;
|
2000-06-07 13:43:37 +08:00
|
|
|
|
else if (!isblank ((unsigned char)*p))
|
2013-05-17 14:29:46 +08:00
|
|
|
|
break;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
++p;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-21 14:16:00 +08:00
|
|
|
|
/* Update the file's command flags with any new ones we found. We only
|
|
|
|
|
keep the COMMANDS_RECURSE setting. Even this isn't 100% correct; we are
|
|
|
|
|
now marking more commands recursive than should be in the case of
|
|
|
|
|
multiline define/endef scripts where only one line is marked "+". In
|
|
|
|
|
order to really fix this, we'll have to keep a lines_flags for every
|
|
|
|
|
actual line, after expansion. */
|
|
|
|
|
child->file->cmds->lines_flags[child->command_line - 1]
|
|
|
|
|
|= flags & COMMANDS_RECURSE;
|
1999-10-13 15:00:23 +08:00
|
|
|
|
|
2010-11-07 05:56:23 +08:00
|
|
|
|
/* POSIX requires that a recipe prefix after a backslash-newline should
|
|
|
|
|
be ignored. Remove it now so the output is correct. */
|
|
|
|
|
{
|
|
|
|
|
char prefix = child->file->cmds->recipe_prefix;
|
|
|
|
|
char *p1, *p2;
|
|
|
|
|
p1 = p2 = p;
|
|
|
|
|
while (*p1 != '\0')
|
|
|
|
|
{
|
|
|
|
|
*(p2++) = *p1;
|
|
|
|
|
if (p1[0] == '\n' && p1[1] == prefix)
|
|
|
|
|
++p1;
|
|
|
|
|
++p1;
|
|
|
|
|
}
|
|
|
|
|
*p2 = *p1;
|
|
|
|
|
}
|
1995-11-22 08:06:28 +08:00
|
|
|
|
|
2010-11-07 05:56:23 +08:00
|
|
|
|
/* Figure out an argument list from this command line. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
1996-03-20 22:57:41 +08:00
|
|
|
|
char *end = 0;
|
|
|
|
|
#ifdef VMS
|
|
|
|
|
argv = p;
|
|
|
|
|
#else
|
2007-10-10 21:22:21 +08:00
|
|
|
|
argv = construct_command_argv (p, &end, child->file,
|
2013-05-17 14:29:46 +08:00
|
|
|
|
child->file->cmds->lines_flags[child->command_line - 1],
|
2010-11-07 05:56:23 +08:00
|
|
|
|
&child->sh_batch_file);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
if (end == NULL)
|
|
|
|
|
child->command_ptr = NULL;
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
*end++ = '\0';
|
|
|
|
|
child->command_ptr = end;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
/* If -q was given, say that updating 'failed' if there was any text on the
|
|
|
|
|
command line, or 'succeeded' otherwise. The exit status of 1 tells the
|
|
|
|
|
user that -q is saying 'something to do'; the exit status for a random
|
2000-06-23 23:55:46 +08:00
|
|
|
|
error is 2. */
|
|
|
|
|
if (argv != 0 && question_flag && !(flags & COMMANDS_RECURSE))
|
|
|
|
|
{
|
|
|
|
|
#ifndef VMS
|
|
|
|
|
free (argv[0]);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (argv);
|
2000-06-23 23:55:46 +08:00
|
|
|
|
#endif
|
2013-07-15 07:18:21 +08:00
|
|
|
|
child->file->update_status = us_question;
|
2000-06-23 23:55:46 +08:00
|
|
|
|
notice_finished_file (child->file);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1993-02-06 06:31:29 +08:00
|
|
|
|
if (touch_flag && !(flags & COMMANDS_RECURSE))
|
1992-08-21 02:20:20 +08:00
|
|
|
|
{
|
|
|
|
|
/* Go on to the next command. It might be the recursive one.
|
2013-05-17 14:29:46 +08:00
|
|
|
|
We construct ARGV only to find the end of the command line. */
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
2000-06-23 23:55:46 +08:00
|
|
|
|
if (argv)
|
|
|
|
|
{
|
|
|
|
|
free (argv[0]);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (argv);
|
2000-06-23 23:55:46 +08:00
|
|
|
|
}
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1992-08-21 02:20:20 +08:00
|
|
|
|
argv = 0;
|
|
|
|
|
}
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
if (argv == 0)
|
|
|
|
|
{
|
1995-02-11 07:44:03 +08:00
|
|
|
|
next_command:
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#ifdef __MSDOS__
|
1999-07-21 06:34:41 +08:00
|
|
|
|
execute_by_shell = 0; /* in case construct_command_argv sets it */
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* This line has no commands. Go to the next. */
|
1992-06-26 08:33:00 +08:00
|
|
|
|
if (job_next_command (child))
|
2013-05-17 14:29:46 +08:00
|
|
|
|
start_job_command (child);
|
1994-11-01 16:34:10 +08:00
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* No more commands. Make sure we're "running"; we might not be if
|
1999-07-21 06:34:41 +08:00
|
|
|
|
(e.g.) all commands were skipped due to -n. */
|
|
|
|
|
set_command_state (child->file, cs_running);
|
2013-07-15 07:18:21 +08:00
|
|
|
|
child->file->update_status = us_success;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
notice_finished_file (child->file);
|
|
|
|
|
}
|
2013-09-12 16:07:52 +08:00
|
|
|
|
|
|
|
|
|
OUTPUT_UNSET();
|
1992-01-21 02:49:36 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 05:03:51 +08:00
|
|
|
|
/* Are we going to synchronize this command's output? Do so if either we're
|
2013-09-12 16:07:52 +08:00
|
|
|
|
in SYNC_RECURSE mode or this command is not recursive. We'll also check
|
2013-05-06 05:03:51 +08:00
|
|
|
|
output_sync separately below in case it changes due to error. */
|
2013-09-12 16:07:52 +08:00
|
|
|
|
child->output.syncout = output_sync && (output_sync == OUTPUT_SYNC_RECURSE
|
|
|
|
|
|| !(flags & COMMANDS_RECURSE));
|
|
|
|
|
|
|
|
|
|
OUTPUT_SET (&child->output);
|
2013-05-06 05:03:51 +08:00
|
|
|
|
|
|
|
|
|
#ifdef OUTPUT_SYNC
|
2013-09-12 16:07:52 +08:00
|
|
|
|
if (! child->output.syncout)
|
2013-05-06 05:03:51 +08:00
|
|
|
|
/* We don't want to sync this command: to avoid misordered
|
|
|
|
|
output ensure any already-synced content is written. */
|
2013-09-12 16:07:52 +08:00
|
|
|
|
output_dump (&child->output);
|
2013-05-06 05:03:51 +08:00
|
|
|
|
#endif /* OUTPUT_SYNC */
|
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
/* Print the command if appropriate. */
|
|
|
|
|
if (just_print_flag || trace_flag
|
|
|
|
|
|| (!(flags & COMMANDS_SILENT) && !silent_flag))
|
|
|
|
|
message (0, "%s", p);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2000-06-23 23:55:46 +08:00
|
|
|
|
/* Tell update_goal_chain that a command has been started on behalf of
|
|
|
|
|
this target. It is important that this happens here and not in
|
|
|
|
|
reap_children (where we used to do it), because reap_children might be
|
|
|
|
|
reaping children from a different target. We want this increment to
|
|
|
|
|
guaranteedly indicate that a command was started for the dependency
|
|
|
|
|
chain (i.e., update_file recursion chain) we are processing. */
|
|
|
|
|
|
|
|
|
|
++commands_started;
|
|
|
|
|
|
1997-08-19 02:11:04 +08:00
|
|
|
|
/* Optimize an empty command. People use this for timestamp rules,
|
2000-06-23 23:55:46 +08:00
|
|
|
|
so avoid forking a useless shell. Do this after we increment
|
|
|
|
|
commands_started so make still treats this special case as if it
|
|
|
|
|
performed some action (makes a difference as to what messages are
|
|
|
|
|
printed, etc. */
|
1997-08-19 02:11:04 +08:00
|
|
|
|
|
1997-09-06 05:01:49 +08:00
|
|
|
|
#if !defined(VMS) && !defined(_AMIGA)
|
1997-08-28 04:30:54 +08:00
|
|
|
|
if (
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#if defined __MSDOS__ || defined (__EMX__)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
unixy_shell /* the test is complicated and we already did it */
|
1997-08-28 04:30:54 +08:00
|
|
|
|
#else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
(argv[0] && is_bourne_compatible_shell (argv[0]))
|
1997-08-28 04:30:54 +08:00
|
|
|
|
#endif
|
2010-07-12 13:23:19 +08:00
|
|
|
|
&& (argv[1] && argv[1][0] == '-'
|
2013-05-17 14:29:46 +08:00
|
|
|
|
&&
|
|
|
|
|
((argv[1][1] == 'c' && argv[1][2] == '\0')
|
|
|
|
|
||
|
|
|
|
|
(argv[1][1] == 'e' && argv[1][2] == 'c' && argv[1][3] == '\0')))
|
1999-08-19 12:43:46 +08:00
|
|
|
|
&& (argv[2] && argv[2][0] == ':' && argv[2][1] == '\0')
|
1997-08-19 02:11:04 +08:00
|
|
|
|
&& argv[3] == NULL)
|
|
|
|
|
{
|
1999-07-21 06:34:41 +08:00
|
|
|
|
free (argv[0]);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (argv);
|
1997-08-19 02:11:04 +08:00
|
|
|
|
goto next_command;
|
|
|
|
|
}
|
1997-09-06 05:01:49 +08:00
|
|
|
|
#endif /* !VMS && !_AMIGA */
|
1997-08-19 02:11:04 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* If -n was given, recurse to get the next line in the sequence. */
|
|
|
|
|
|
1993-02-06 06:31:29 +08:00
|
|
|
|
if (just_print_flag && !(flags & COMMANDS_RECURSE))
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
1992-01-21 02:49:36 +08:00
|
|
|
|
free (argv[0]);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (argv);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1995-02-11 07:44:03 +08:00
|
|
|
|
goto next_command;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
/* We're sure we're going to invoke a command: set up the output. */
|
|
|
|
|
output_start ();
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Flush the output streams so they won't have things written twice. */
|
|
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
fflush (stderr);
|
1995-11-22 08:06:28 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
1997-09-06 05:01:49 +08:00
|
|
|
|
#if !defined(WINDOWS32) && !defined(_AMIGA) && !defined(__MSDOS__)
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Set up a bad standard input that reads from a broken pipe. */
|
|
|
|
|
|
|
|
|
|
if (bad_stdin == -1)
|
|
|
|
|
{
|
|
|
|
|
/* Make a file descriptor that is the read end of a broken pipe.
|
2013-05-17 14:29:46 +08:00
|
|
|
|
This will be used for some children's standard inputs. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
int pd[2];
|
|
|
|
|
if (pipe (pd) == 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* Close the write side. */
|
|
|
|
|
(void) close (pd[1]);
|
|
|
|
|
/* Save the read side. */
|
|
|
|
|
bad_stdin = pd[0];
|
|
|
|
|
|
|
|
|
|
/* Set the descriptor to close on exec, so it does not litter any
|
|
|
|
|
child's descriptor table. When it is dup2'd onto descriptor 0,
|
|
|
|
|
that descriptor will not close on exec. */
|
|
|
|
|
CLOSE_ON_EXEC (bad_stdin);
|
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-06 05:01:49 +08:00
|
|
|
|
#endif /* !WINDOWS32 && !_AMIGA && !__MSDOS__ */
|
1996-05-14 02:38:29 +08:00
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
/* Decide whether to give this child the 'good' standard input
|
|
|
|
|
(one that points to the terminal or whatever), or the 'bad' one
|
1992-01-21 02:49:36 +08:00
|
|
|
|
that points to the read side of a broken pipe. */
|
|
|
|
|
|
|
|
|
|
child->good_stdin = !good_stdin_used;
|
|
|
|
|
if (child->good_stdin)
|
|
|
|
|
good_stdin_used = 1;
|
|
|
|
|
|
1997-09-06 05:01:49 +08:00
|
|
|
|
#endif /* !VMS */
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
child->deleted = 0;
|
|
|
|
|
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
#ifndef _AMIGA
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Set up the environment for the child. */
|
|
|
|
|
if (child->environment == 0)
|
|
|
|
|
child->environment = target_environment (child->file);
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#if !defined(__MSDOS__) && !defined(_AMIGA) && !defined(WINDOWS32)
|
1994-07-26 07:23:03 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
1992-06-26 08:33:00 +08:00
|
|
|
|
/* start_waiting_job has set CHILD->remote if we can start a remote job. */
|
|
|
|
|
if (child->remote)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
|
|
|
|
int is_remote, id, used_stdin;
|
1992-03-11 06:15:30 +08:00
|
|
|
|
if (start_remote_job (argv, child->environment,
|
2013-05-17 14:29:46 +08:00
|
|
|
|
child->good_stdin ? 0 : bad_stdin,
|
|
|
|
|
&is_remote, &id, &used_stdin))
|
1998-07-31 04:54:47 +08:00
|
|
|
|
/* Don't give up; remote execution may fail for various reasons. If
|
|
|
|
|
so, simply run the job locally. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
goto run_local;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
if (child->good_stdin && !used_stdin)
|
|
|
|
|
{
|
|
|
|
|
child->good_stdin = 0;
|
|
|
|
|
good_stdin_used = 0;
|
|
|
|
|
}
|
|
|
|
|
child->remote = is_remote;
|
|
|
|
|
child->pid = id;
|
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif /* !VMS */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
|
|
|
|
/* Fork the child process. */
|
|
|
|
|
|
1995-01-16 00:32:10 +08:00
|
|
|
|
char **parent_environ;
|
1995-01-15 23:57:48 +08:00
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
run_local:
|
1996-06-23 03:30:59 +08:00
|
|
|
|
block_sigs ();
|
1992-05-01 05:50:23 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
child->remote = 0;
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
|
|
|
|
#ifdef VMS
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (!child_execute_job (argv, child))
|
|
|
|
|
{
|
|
|
|
|
/* Fork failed! */
|
|
|
|
|
perror_with_name ("fork", "");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
1995-01-15 23:57:48 +08:00
|
|
|
|
parent_environ = environ;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
/* If we aren't running a recursive command and we have a jobserver
|
|
|
|
|
pipe, close it before exec'ing. */
|
|
|
|
|
if (!(flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
CLOSE_ON_EXEC (job_fds[0]);
|
|
|
|
|
CLOSE_ON_EXEC (job_fds[1]);
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
if (job_rfd >= 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
CLOSE_ON_EXEC (job_rfd);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
/* Never use fork()/exec() here! Use spawn() instead in exec_command() */
|
|
|
|
|
child->pid = child_execute_job (child->good_stdin ? 0 : bad_stdin, 1,
|
|
|
|
|
argv, child->environment);
|
|
|
|
|
if (child->pid < 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* spawn failed! */
|
|
|
|
|
unblock_sigs ();
|
|
|
|
|
perror_with_name ("spawn", "");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
/* undo CLOSE_ON_EXEC() after the child process has been started */
|
|
|
|
|
if (!(flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
fcntl (job_fds[0], F_SETFD, 0);
|
|
|
|
|
fcntl (job_fds[1], F_SETFD, 0);
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
if (job_rfd >= 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
fcntl (job_rfd, F_SETFD, 0);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
#else /* !__EMX__ */
|
|
|
|
|
|
2013-05-06 12:22:27 +08:00
|
|
|
|
child->pid = fork ();
|
2013-05-17 14:29:46 +08:00
|
|
|
|
environ = parent_environ; /* Restore value child may have clobbered. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
if (child->pid == 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* We are the child side. */
|
|
|
|
|
unblock_sigs ();
|
1999-07-24 06:46:47 +08:00
|
|
|
|
|
|
|
|
|
/* If we aren't running a recursive command and we have a jobserver
|
|
|
|
|
pipe, close it before exec'ing. */
|
|
|
|
|
if (!(flags & COMMANDS_RECURSE) && job_fds[0] >= 0)
|
|
|
|
|
{
|
|
|
|
|
close (job_fds[0]);
|
|
|
|
|
close (job_fds[1]);
|
|
|
|
|
}
|
1999-08-13 15:36:26 +08:00
|
|
|
|
if (job_rfd >= 0)
|
|
|
|
|
close (job_rfd);
|
1999-07-24 06:46:47 +08:00
|
|
|
|
|
2009-06-08 01:40:06 +08:00
|
|
|
|
#ifdef SET_STACK_SIZE
|
|
|
|
|
/* Reset limits, if necessary. */
|
|
|
|
|
if (stack_limit.rlim_cur)
|
|
|
|
|
setrlimit (RLIMIT_STACK, &stack_limit);
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-04-15 04:31:18 +08:00
|
|
|
|
#ifdef OUTPUT_SYNC
|
2013-05-01 19:59:24 +08:00
|
|
|
|
/* Divert child output if output_sync in use. Don't capture
|
|
|
|
|
recursive make output unless we are synchronizing "make" mode. */
|
2013-09-12 16:07:52 +08:00
|
|
|
|
if (child->output.syncout)
|
2013-04-15 04:31:18 +08:00
|
|
|
|
{
|
|
|
|
|
int outfd = fileno (stdout);
|
|
|
|
|
int errfd = fileno (stderr);
|
2013-04-15 03:38:07 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
if ((child->output.out >= 0
|
|
|
|
|
&& (close (outfd) == -1
|
|
|
|
|
|| dup2 (child->output.out, outfd) == -1))
|
|
|
|
|
|| (child->output.err >= 0
|
|
|
|
|
&& (close (errfd) == -1
|
|
|
|
|
|| dup2 (child->output.err, errfd) == -1)))
|
2013-04-16 07:17:19 +08:00
|
|
|
|
perror_with_name ("output-sync: ", "dup2()");
|
2013-04-15 04:31:18 +08:00
|
|
|
|
}
|
|
|
|
|
#endif /* OUTPUT_SYNC */
|
2013-04-15 03:38:07 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
child_execute_job (child->good_stdin ? 0 : bad_stdin, 1,
|
1999-07-17 06:28:46 +08:00
|
|
|
|
argv, child->environment);
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
else if (child->pid < 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* Fork failed! */
|
|
|
|
|
unblock_sigs ();
|
|
|
|
|
perror_with_name ("fork", "");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# endif /* !__EMX__ */
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif /* !VMS */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#else /* __MSDOS__ or Amiga or WINDOWS32 */
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
#ifdef __MSDOS__
|
1997-04-07 15:21:16 +08:00
|
|
|
|
{
|
|
|
|
|
int proc_return;
|
|
|
|
|
|
|
|
|
|
block_sigs ();
|
|
|
|
|
dos_status = 0;
|
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
/* We call 'system' to do the job of the SHELL, since stock DOS
|
|
|
|
|
shell is too dumb. Our 'system' knows how to handle long
|
1997-04-07 15:21:16 +08:00
|
|
|
|
command lines even if pipes/redirection is needed; it will only
|
|
|
|
|
call COMMAND.COM when its internal commands are used. */
|
|
|
|
|
if (execute_by_shell)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
char *cmdline = argv[0];
|
|
|
|
|
/* We don't have a way to pass environment to 'system',
|
|
|
|
|
so we need to save and restore ours, sigh... */
|
|
|
|
|
char **parent_environ = environ;
|
|
|
|
|
|
|
|
|
|
environ = child->environment;
|
|
|
|
|
|
|
|
|
|
/* If we have a *real* shell, tell 'system' to call
|
|
|
|
|
it to do everything for us. */
|
|
|
|
|
if (unixy_shell)
|
|
|
|
|
{
|
|
|
|
|
/* A *real* shell on MSDOS may not support long
|
|
|
|
|
command lines the DJGPP way, so we must use 'system'. */
|
|
|
|
|
cmdline = argv[2]; /* get past "shell -c" */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dos_command_running = 1;
|
|
|
|
|
proc_return = system (cmdline);
|
|
|
|
|
environ = parent_environ;
|
|
|
|
|
execute_by_shell = 0; /* for the next time */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
dos_command_running = 1;
|
|
|
|
|
proc_return = spawnvpe (P_WAIT, argv[0], argv, child->environment);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-06-14 13:26:28 +08:00
|
|
|
|
/* Need to unblock signals before turning off
|
|
|
|
|
dos_command_running, so that child's signals
|
|
|
|
|
will be treated as such (see fatal_error_signal). */
|
|
|
|
|
unblock_sigs ();
|
|
|
|
|
dos_command_running = 0;
|
|
|
|
|
|
|
|
|
|
/* If the child got a signal, dos_status has its
|
|
|
|
|
high 8 bits set, so be careful not to alter them. */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
if (proc_return == -1)
|
|
|
|
|
dos_status |= 0xff;
|
|
|
|
|
else
|
|
|
|
|
dos_status |= (proc_return & 0xff);
|
|
|
|
|
++dead_children;
|
|
|
|
|
child->pid = dos_pid++;
|
|
|
|
|
}
|
1996-05-23 05:51:45 +08:00
|
|
|
|
#endif /* __MSDOS__ */
|
|
|
|
|
#ifdef _AMIGA
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
amiga_status = MyExecute (argv);
|
|
|
|
|
|
|
|
|
|
++dead_children;
|
|
|
|
|
child->pid = amiga_pid++;
|
|
|
|
|
if (amiga_batch_file)
|
|
|
|
|
{
|
|
|
|
|
amiga_batch_file = 0;
|
|
|
|
|
DeleteFile (amiga_bname); /* Ignore errors. */
|
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#endif /* Amiga */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-23 05:51:45 +08:00
|
|
|
|
{
|
|
|
|
|
HANDLE hPID;
|
|
|
|
|
char* arg0;
|
|
|
|
|
|
|
|
|
|
/* make UNC paths safe for CreateProcess -- backslash format */
|
|
|
|
|
arg0 = argv[0];
|
|
|
|
|
if (arg0 && arg0[0] == '/' && arg0[1] == '/')
|
|
|
|
|
for ( ; arg0 && *arg0; arg0++)
|
|
|
|
|
if (*arg0 == '/')
|
|
|
|
|
*arg0 = '\\';
|
|
|
|
|
|
|
|
|
|
/* make sure CreateProcess() has Path it needs */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
sync_Path_environment ();
|
1996-05-23 05:51:45 +08:00
|
|
|
|
|
Support --output-sync on MS-Windows.
w32/compat/posixfcn.c: New file, with emulations of Posix
functions and Posix functionality for MS-Windows.
w32/subproc/sub_proc.c: Include io.h.
(process_noinherit): New function, forces a file descriptor to not
be inherited by child processes.
(process_easy): Accept two additional arguments, and use them to
set up the standard output and standard error handles of the child
process.
w32/include/sub_proc.h (process_easy): Adjust prototype.
(process_noinherit): Add prototype.
read.c [WINDOWS32]: Include windows.h and sub_proc.h.
makeint.h (LOCALEDIR) [WINDOWS32}: Define to NULL if not
defined. This is needed because the MS-Windows build doesn't have
a canonical place for LOCALEDIR.
(WIN32_LEAN_AND_MEAN) [WINDOWS32]: Define, to avoid getting from
windows.h header too much stuff that could conflict with the code.
main.c <sync_mutex>: New static variable.
<switches>: Add support for "--sync-mutex" switch.
(decode_output_sync_flags): Decode the --sync-mutex= switch.
(prepare_mutex_handle_string) [WINDOWS32]: New function.
(main): Add "output-sync" to .FEATURES.
job.h (CLOSE_ON_EXEC) [WINDOWS32]: Define to call
process_noinherit.
(F_GETFD, F_SETLKW, F_WRLCK, F_UNLCK, struct flock) [WINDOWS32]:
New macros.
(RECORD_SYNC_MUTEX): New macro, a no-op for Posix platforms.
(sync_handle_t): New typedef.
job.c <sync_handle>: Change type to sync_handle_t.
(FD_NOT_EMPTY): Seek to the file's end. Suggested by Frank
Heckenbach <f.heckenbach@fh-soft.de>.
(pump_from_tmp_fd) [WINDOWS32]: Switch to_fd to binary mode for
the duration of this function, and then change back before
returning.
(start_job_command) [WINDOWS32]: Support output_sync mode on
MS-Windows. Use a system-wide mutex instead of locking
stdout/stderr. Call process_easy with two additional arguments:
child->outfd and child->errfd.
(exec_command) [WINDOWS32]: Pass two additional arguments, both
-1, to process_easy, to adjust for the changed function signature.
function.c (windows32_openpipe) [WINDOWS32]: This function now
returns an int, which is -1 if it fails and zero otherwise. It
also calls 'error' instead of 'fatal', to avoid exiting
prematurely.
(func_shell_base) [WINDOWS32]: Call perror_with_name if
windows32_openpipe fails, now that it always returns. This avoids
a compiler warning that error_prefix is not used in the MS-Windows
build.
config.h.W32.template (OUTPUT_SYNC): Define.
build_w32.bat: Add w32/compat/posixfcn.c to compilation and
linking commands.
From Frank Heckenbach <f.heckenbach@fh-soft.de>:
job.c (sync_output): Don't discard the output if
acquire_semaphore fails; instead, dump the output unsynchronized.
2013-04-27 19:20:49 +08:00
|
|
|
|
#ifdef OUTPUT_SYNC
|
2013-05-01 23:15:16 +08:00
|
|
|
|
/* Divert child output if output_sync in use. Don't capture
|
|
|
|
|
recursive make output unless we are synchronizing "make" mode. */
|
2013-09-12 16:07:52 +08:00
|
|
|
|
if (child->output.syncout)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
hPID = process_easy (argv, child->environment,
|
2013-09-12 16:07:52 +08:00
|
|
|
|
child->output.out, child->output.err);
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else
|
Support --output-sync on MS-Windows.
w32/compat/posixfcn.c: New file, with emulations of Posix
functions and Posix functionality for MS-Windows.
w32/subproc/sub_proc.c: Include io.h.
(process_noinherit): New function, forces a file descriptor to not
be inherited by child processes.
(process_easy): Accept two additional arguments, and use them to
set up the standard output and standard error handles of the child
process.
w32/include/sub_proc.h (process_easy): Adjust prototype.
(process_noinherit): Add prototype.
read.c [WINDOWS32]: Include windows.h and sub_proc.h.
makeint.h (LOCALEDIR) [WINDOWS32}: Define to NULL if not
defined. This is needed because the MS-Windows build doesn't have
a canonical place for LOCALEDIR.
(WIN32_LEAN_AND_MEAN) [WINDOWS32]: Define, to avoid getting from
windows.h header too much stuff that could conflict with the code.
main.c <sync_mutex>: New static variable.
<switches>: Add support for "--sync-mutex" switch.
(decode_output_sync_flags): Decode the --sync-mutex= switch.
(prepare_mutex_handle_string) [WINDOWS32]: New function.
(main): Add "output-sync" to .FEATURES.
job.h (CLOSE_ON_EXEC) [WINDOWS32]: Define to call
process_noinherit.
(F_GETFD, F_SETLKW, F_WRLCK, F_UNLCK, struct flock) [WINDOWS32]:
New macros.
(RECORD_SYNC_MUTEX): New macro, a no-op for Posix platforms.
(sync_handle_t): New typedef.
job.c <sync_handle>: Change type to sync_handle_t.
(FD_NOT_EMPTY): Seek to the file's end. Suggested by Frank
Heckenbach <f.heckenbach@fh-soft.de>.
(pump_from_tmp_fd) [WINDOWS32]: Switch to_fd to binary mode for
the duration of this function, and then change back before
returning.
(start_job_command) [WINDOWS32]: Support output_sync mode on
MS-Windows. Use a system-wide mutex instead of locking
stdout/stderr. Call process_easy with two additional arguments:
child->outfd and child->errfd.
(exec_command) [WINDOWS32]: Pass two additional arguments, both
-1, to process_easy, to adjust for the changed function signature.
function.c (windows32_openpipe) [WINDOWS32]: This function now
returns an int, which is -1 if it fails and zero otherwise. It
also calls 'error' instead of 'fatal', to avoid exiting
prematurely.
(func_shell_base) [WINDOWS32]: Call perror_with_name if
windows32_openpipe fails, now that it always returns. This avoids
a compiler warning that error_prefix is not used in the MS-Windows
build.
config.h.W32.template (OUTPUT_SYNC): Define.
build_w32.bat: Add w32/compat/posixfcn.c to compilation and
linking commands.
From Frank Heckenbach <f.heckenbach@fh-soft.de>:
job.c (sync_output): Don't discard the output if
acquire_semaphore fails; instead, dump the output unsynchronized.
2013-04-27 19:20:49 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
hPID = process_easy (argv, child->environment, -1, -1);
|
1996-05-23 05:51:45 +08:00
|
|
|
|
|
|
|
|
|
if (hPID != INVALID_HANDLE_VALUE)
|
2010-07-09 19:10:04 +08:00
|
|
|
|
child->pid = (pid_t) hPID;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
unblock_sigs ();
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("process_easy() failed to launch process (e=%ld)\n"),
|
|
|
|
|
process_last_err (hPID));
|
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
|
fprintf (stderr, "%s ", argv[i]);
|
|
|
|
|
fprintf (stderr, _("\nCounted %d args in failed launch\n"), i);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
1996-06-23 05:42:10 +08:00
|
|
|
|
}
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#endif /* __MSDOS__ or Amiga or WINDOWS32 */
|
1994-07-26 07:23:03 +08:00
|
|
|
|
|
2004-01-21 14:32:59 +08:00
|
|
|
|
/* Bump the number of jobs started in this second. */
|
|
|
|
|
++job_counter;
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* We are the parent side. Set the state to
|
|
|
|
|
say the commands are running and return. */
|
|
|
|
|
|
1994-09-07 08:04:49 +08:00
|
|
|
|
set_command_state (child->file, cs_running);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
/* Free the storage used by the child's argument list. */
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
1992-01-21 02:49:36 +08:00
|
|
|
|
free (argv[0]);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (argv);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
OUTPUT_UNSET();
|
1992-01-21 02:49:36 +08:00
|
|
|
|
return;
|
|
|
|
|
|
1994-04-21 10:00:20 +08:00
|
|
|
|
error:
|
2013-07-15 07:18:21 +08:00
|
|
|
|
child->file->update_status = us_failed;
|
1994-09-07 15:02:23 +08:00
|
|
|
|
notice_finished_file (child->file);
|
2013-09-12 16:07:52 +08:00
|
|
|
|
OUTPUT_UNSET();
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
1993-04-08 05:10:12 +08:00
|
|
|
|
/* Try to start a child running.
|
|
|
|
|
Returns nonzero if the child was started (and maybe finished), or zero if
|
2012-03-04 08:24:20 +08:00
|
|
|
|
the load was too high and the child was put on the 'waiting_jobs' chain. */
|
1993-04-08 05:10:12 +08:00
|
|
|
|
|
|
|
|
|
static int
|
2002-10-15 05:54:04 +08:00
|
|
|
|
start_waiting_job (struct child *c)
|
1992-06-16 05:47:25 +08:00
|
|
|
|
{
|
1999-04-25 12:30:55 +08:00
|
|
|
|
struct file *f = c->file;
|
|
|
|
|
|
1992-06-26 08:33:00 +08:00
|
|
|
|
/* If we can start a job remotely, we always want to, and don't care about
|
|
|
|
|
the local load average. We record that the job should be started
|
|
|
|
|
remotely in C->remote for start_job_command to test. */
|
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
c->remote = start_remote_job_p (1);
|
1992-06-26 08:33:00 +08:00
|
|
|
|
|
1999-08-01 16:12:06 +08:00
|
|
|
|
/* If we are running at least one job already and the load average
|
|
|
|
|
is too high, make this one wait. */
|
2006-02-01 15:54:22 +08:00
|
|
|
|
if (!c->remote
|
|
|
|
|
&& ((job_slots_used > 0 && load_too_high ())
|
|
|
|
|
#ifdef WINDOWS32
|
2013-05-17 14:29:46 +08:00
|
|
|
|
|| (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
|
2006-02-01 15:54:22 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
))
|
1992-06-16 05:47:25 +08:00
|
|
|
|
{
|
1999-08-01 16:12:06 +08:00
|
|
|
|
/* Put this child on the chain of children waiting for the load average
|
|
|
|
|
to go down. */
|
|
|
|
|
set_command_state (f, cs_running);
|
|
|
|
|
c->next = waiting_jobs;
|
|
|
|
|
waiting_jobs = c;
|
|
|
|
|
return 0;
|
1992-06-26 08:33:00 +08:00
|
|
|
|
}
|
1992-06-16 05:47:25 +08:00
|
|
|
|
|
1992-06-26 08:33:00 +08:00
|
|
|
|
/* Start the first command; reap_children will run later command lines. */
|
|
|
|
|
start_job_command (c);
|
|
|
|
|
|
1999-04-25 12:30:55 +08:00
|
|
|
|
switch (f->command_state)
|
1992-06-26 08:33:00 +08:00
|
|
|
|
{
|
1992-06-16 05:47:25 +08:00
|
|
|
|
case cs_running:
|
|
|
|
|
c->next = children;
|
2010-07-06 02:32:03 +08:00
|
|
|
|
DB (DB_JOBS, (_("Putting child %p (%s) PID %s%s on the chain.\n"),
|
|
|
|
|
c, c->file->name, pid2str (c->pid),
|
|
|
|
|
c->remote ? _(" (remote)") : ""));
|
1992-06-16 05:47:25 +08:00
|
|
|
|
children = c;
|
|
|
|
|
/* One more job slot is in use. */
|
|
|
|
|
++job_slots_used;
|
|
|
|
|
unblock_sigs ();
|
|
|
|
|
break;
|
|
|
|
|
|
1994-09-27 07:02:40 +08:00
|
|
|
|
case cs_not_started:
|
|
|
|
|
/* All the command lines turned out to be empty. */
|
2013-07-15 07:18:21 +08:00
|
|
|
|
f->update_status = us_success;
|
1994-09-27 07:02:40 +08:00
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
1992-06-16 05:47:25 +08:00
|
|
|
|
case cs_finished:
|
1999-04-25 12:30:55 +08:00
|
|
|
|
notice_finished_file (f);
|
1992-07-08 07:12:46 +08:00
|
|
|
|
free_child (c);
|
1992-06-16 05:47:25 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
1999-04-25 12:30:55 +08:00
|
|
|
|
assert (f->command_state == cs_finished);
|
1992-06-16 05:47:25 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
1993-04-08 05:10:12 +08:00
|
|
|
|
|
|
|
|
|
return 1;
|
1992-06-16 05:47:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
/* Create a 'struct child' for FILE and start its commands running. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
new_job (struct file *file)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
2007-05-12 04:57:21 +08:00
|
|
|
|
struct commands *cmds = file->cmds;
|
|
|
|
|
struct child *c;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
char **lines;
|
2007-05-12 04:57:21 +08:00
|
|
|
|
unsigned int i;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1993-04-08 05:10:12 +08:00
|
|
|
|
/* Let any previously decided-upon jobs that are waiting
|
|
|
|
|
for the load to go down start before this new one. */
|
|
|
|
|
start_waiting_jobs ();
|
|
|
|
|
|
1992-04-21 15:59:32 +08:00
|
|
|
|
/* Reap any children that might have finished recently. */
|
|
|
|
|
reap_children (0, 0);
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Chop the commands up into lines if they aren't already. */
|
|
|
|
|
chop_commands (cmds);
|
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
/* Start the command sequence, record it in a new
|
|
|
|
|
'struct child', and add that to the chain. */
|
|
|
|
|
|
|
|
|
|
c = xcalloc (sizeof (struct child));
|
2013-09-14 13:04:04 +08:00
|
|
|
|
output_init (&c->output);
|
2013-09-12 16:07:52 +08:00
|
|
|
|
|
|
|
|
|
c->file = file;
|
|
|
|
|
c->sh_batch_file = NULL;
|
|
|
|
|
|
|
|
|
|
/* Cache dontcare flag because file->dontcare can be changed once we
|
|
|
|
|
return. Check dontcare inheritance mechanism for details. */
|
|
|
|
|
c->dontcare = file->dontcare;
|
|
|
|
|
|
|
|
|
|
/* Start saving output in case the expansion uses $(info ...) etc. */
|
|
|
|
|
OUTPUT_SET (&c->output);
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Expand the command lines and store the results in LINES. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
lines = xmalloc (cmds->ncommand_lines * sizeof (char *));
|
1992-01-21 02:49:36 +08:00
|
|
|
|
for (i = 0; i < cmds->ncommand_lines; ++i)
|
1993-02-04 08:58:10 +08:00
|
|
|
|
{
|
|
|
|
|
/* Collapse backslash-newline combinations that are inside variable
|
2013-05-17 14:29:46 +08:00
|
|
|
|
or function references. These are left alone by the parser so
|
|
|
|
|
that they will appear in the echoing of commands (where they look
|
|
|
|
|
nice); and collapsed by construct_command_argv when it tokenizes.
|
|
|
|
|
But letting them survive inside function invocations loses because
|
|
|
|
|
we don't want the functions to see them as part of the text. */
|
1993-02-04 08:58:10 +08:00
|
|
|
|
|
|
|
|
|
char *in, *out, *ref;
|
|
|
|
|
|
|
|
|
|
/* IN points to where in the line we are scanning.
|
2013-05-17 14:29:46 +08:00
|
|
|
|
OUT points to where in the line we are writing.
|
|
|
|
|
When we collapse a backslash-newline combination,
|
|
|
|
|
IN gets ahead of OUT. */
|
1993-02-04 08:58:10 +08:00
|
|
|
|
|
|
|
|
|
in = out = cmds->command_lines[i];
|
1999-10-15 15:00:58 +08:00
|
|
|
|
while ((ref = strchr (in, '$')) != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
++ref; /* Move past the $. */
|
|
|
|
|
|
|
|
|
|
if (out != in)
|
|
|
|
|
/* Copy the text between the end of the last chunk
|
|
|
|
|
we processed (where IN points) and the new chunk
|
|
|
|
|
we are about to process (where REF points). */
|
|
|
|
|
memmove (out, in, ref - in);
|
|
|
|
|
|
|
|
|
|
/* Move both pointers past the boring stuff. */
|
|
|
|
|
out += ref - in;
|
|
|
|
|
in = ref;
|
|
|
|
|
|
|
|
|
|
if (*ref == '(' || *ref == '{')
|
|
|
|
|
{
|
|
|
|
|
char openparen = *ref;
|
|
|
|
|
char closeparen = openparen == '(' ? ')' : '}';
|
2013-05-27 01:56:51 +08:00
|
|
|
|
char *outref;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
int count;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
*out++ = *in++; /* Copy OPENPAREN. */
|
2013-05-27 01:56:51 +08:00
|
|
|
|
outref = out;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* IN now points past the opening paren or brace.
|
|
|
|
|
Count parens or braces until it is matched. */
|
|
|
|
|
count = 0;
|
|
|
|
|
while (*in != '\0')
|
|
|
|
|
{
|
|
|
|
|
if (*in == closeparen && --count < 0)
|
|
|
|
|
break;
|
|
|
|
|
else if (*in == '\\' && in[1] == '\n')
|
|
|
|
|
{
|
|
|
|
|
/* We have found a backslash-newline inside a
|
|
|
|
|
variable or function reference. Eat it and
|
|
|
|
|
any following whitespace. */
|
|
|
|
|
|
|
|
|
|
int quoted = 0;
|
|
|
|
|
for (p = in - 1; p > ref && *p == '\\'; --p)
|
|
|
|
|
quoted = !quoted;
|
|
|
|
|
|
|
|
|
|
if (quoted)
|
|
|
|
|
/* There were two or more backslashes, so this is
|
|
|
|
|
not really a continuation line. We don't collapse
|
|
|
|
|
the quoting backslashes here as is done in
|
|
|
|
|
collapse_continuations, because the line will
|
|
|
|
|
be collapsed again after expansion. */
|
|
|
|
|
*out++ = *in++;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Skip the backslash, newline and
|
|
|
|
|
any following whitespace. */
|
|
|
|
|
in = next_token (in + 2);
|
|
|
|
|
|
|
|
|
|
/* Discard any preceding whitespace that has
|
|
|
|
|
already been written to the output. */
|
2013-05-27 01:56:51 +08:00
|
|
|
|
while (out > outref
|
2013-05-17 14:29:46 +08:00
|
|
|
|
&& isblank ((unsigned char)out[-1]))
|
|
|
|
|
--out;
|
|
|
|
|
|
|
|
|
|
/* Replace it all with a single space. */
|
|
|
|
|
*out++ = ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (*in == openparen)
|
|
|
|
|
++count;
|
|
|
|
|
|
|
|
|
|
*out++ = *in++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1993-02-04 08:58:10 +08:00
|
|
|
|
|
|
|
|
|
/* There are no more references in this line to worry about.
|
2013-05-17 14:29:46 +08:00
|
|
|
|
Copy the remaining uninteresting text to the output. */
|
1993-02-04 08:58:10 +08:00
|
|
|
|
if (out != in)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
memmove (out, in, strlen (in) + 1);
|
1993-02-04 08:58:10 +08:00
|
|
|
|
|
|
|
|
|
/* Finally, expand the line. */
|
|
|
|
|
lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i],
|
2013-05-17 14:29:46 +08:00
|
|
|
|
file);
|
1993-02-04 08:58:10 +08:00
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
c->command_lines = lines;
|
2006-02-09 01:29:07 +08:00
|
|
|
|
|
1992-06-26 08:33:00 +08:00
|
|
|
|
/* Fetch the first command line to be run. */
|
1999-07-21 06:34:41 +08:00
|
|
|
|
job_next_command (c);
|
|
|
|
|
|
1999-08-01 14:05:17 +08:00
|
|
|
|
/* Wait for a job slot to be freed up. If we allow an infinite number
|
|
|
|
|
don't bother; also job_slots will == 0 if we're using the jobserver. */
|
1999-08-24 06:15:17 +08:00
|
|
|
|
|
1999-08-01 14:05:17 +08:00
|
|
|
|
if (job_slots != 0)
|
|
|
|
|
while (job_slots_used == job_slots)
|
|
|
|
|
reap_children (1, 0);
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
1999-08-01 14:05:17 +08:00
|
|
|
|
#ifdef MAKE_JOBSERVER
|
1999-08-23 13:35:14 +08:00
|
|
|
|
/* If we are controlling multiple jobs make sure we have a token before
|
|
|
|
|
starting the child. */
|
|
|
|
|
|
1999-08-24 06:15:17 +08:00
|
|
|
|
/* This can be inefficient. There's a decent chance that this job won't
|
|
|
|
|
actually have to run any subprocesses: the command script may be empty
|
|
|
|
|
or otherwise optimized away. It would be nice if we could defer
|
|
|
|
|
obtaining a token until just before we need it, in start_job_command.
|
|
|
|
|
To do that we'd need to keep track of whether we'd already obtained a
|
|
|
|
|
token (since start_job_command is called for each line of the job, not
|
|
|
|
|
just once). Also more thought needs to go into the entire algorithm;
|
|
|
|
|
this is where the old parallel job code waits, so... */
|
|
|
|
|
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#ifdef WINDOWS32
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else if (has_jobserver_semaphore ())
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#else
|
1999-08-01 14:05:17 +08:00
|
|
|
|
else if (job_fds[0] >= 0)
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#endif
|
1999-08-24 06:15:17 +08:00
|
|
|
|
while (1)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
int got_token;
|
2011-11-16 05:12:53 +08:00
|
|
|
|
#ifndef WINDOWS32
|
|
|
|
|
char token;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
int saved_errno;
|
2011-11-16 05:12:53 +08:00
|
|
|
|
#endif
|
2001-06-01 11:56:50 +08:00
|
|
|
|
|
|
|
|
|
DB (DB_JOBS, ("Need a job token; we %shave children\n",
|
|
|
|
|
children ? "" : "don't "));
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
|
|
|
|
/* If we don't already have a job started, use our "free" token. */
|
2005-05-03 21:57:20 +08:00
|
|
|
|
if (!jobserver_tokens)
|
1999-08-24 06:15:17 +08:00
|
|
|
|
break;
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#ifndef WINDOWS32
|
1999-08-01 14:05:17 +08:00
|
|
|
|
/* Read a token. As long as there's no token available we'll block.
|
2001-06-01 11:56:50 +08:00
|
|
|
|
We enable interruptible system calls before the read(2) so that if
|
|
|
|
|
we get a SIGCHLD while we're waiting, we'll return with EINTR and
|
|
|
|
|
we can process the death(s) and return tokens to the free pool.
|
|
|
|
|
|
|
|
|
|
Once we return from the read, we immediately reinstate restartable
|
|
|
|
|
system calls. This allows us to not worry about checking for
|
|
|
|
|
EINTR on all the other system calls in the program.
|
|
|
|
|
|
|
|
|
|
There is one other twist: there is a span between the time
|
|
|
|
|
reap_children() does its last check for dead children and the time
|
|
|
|
|
the read(2) call is entered, below, where if a child dies we won't
|
|
|
|
|
notice. This is extremely serious as it could cause us to
|
|
|
|
|
deadlock, given the right set of events.
|
|
|
|
|
|
|
|
|
|
To avoid this, we do the following: before we reap_children(), we
|
|
|
|
|
dup(2) the read FD on the jobserver pipe. The read(2) call below
|
|
|
|
|
uses that new FD. In the signal handler, we close that FD. That
|
|
|
|
|
way, if a child dies during the section mentioned above, the
|
|
|
|
|
read(2) will be invoked with an invalid FD and will return
|
|
|
|
|
immediately with EBADF. */
|
|
|
|
|
|
|
|
|
|
/* Make sure we have a dup'd FD. */
|
|
|
|
|
if (job_rfd < 0)
|
|
|
|
|
{
|
|
|
|
|
DB (DB_JOBS, ("Duplicate the job FD\n"));
|
|
|
|
|
job_rfd = dup (job_fds[0]);
|
|
|
|
|
}
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#endif
|
2001-06-01 11:56:50 +08:00
|
|
|
|
|
|
|
|
|
/* Reap anything that's currently waiting. */
|
|
|
|
|
reap_children (0, 0);
|
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
/* Kick off any jobs we have waiting for an opportunity that
|
2013-04-30 21:37:03 +08:00
|
|
|
|
can run now (i.e., waiting for load). */
|
2005-05-03 21:57:20 +08:00
|
|
|
|
start_waiting_jobs ();
|
|
|
|
|
|
|
|
|
|
/* If our "free" slot has become available, use it; we don't need an
|
|
|
|
|
actual token. */
|
|
|
|
|
if (!jobserver_tokens)
|
2001-06-01 11:56:50 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
/* There must be at least one child already, or we have no business
|
|
|
|
|
waiting for a token. */
|
|
|
|
|
if (!children)
|
|
|
|
|
fatal (NILF, "INTERNAL: no children as we go to sleep on read\n");
|
|
|
|
|
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#ifdef WINDOWS32
|
|
|
|
|
/* On Windows we simply wait for the jobserver semaphore to become
|
|
|
|
|
* signalled or one of our child processes to terminate.
|
|
|
|
|
*/
|
2013-05-17 14:29:46 +08:00
|
|
|
|
got_token = wait_for_semaphore_or_child_process ();
|
2011-11-14 08:42:49 +08:00
|
|
|
|
if (got_token < 0)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
DWORD err = GetLastError ();
|
2011-11-16 05:12:53 +08:00
|
|
|
|
fatal (NILF, _("semaphore or child process wait: (Error %ld: %s)"),
|
2013-05-17 14:29:46 +08:00
|
|
|
|
err, map_windows32_error_to_string (err));
|
2011-11-14 08:42:49 +08:00
|
|
|
|
}
|
|
|
|
|
#else
|
2001-06-01 11:56:50 +08:00
|
|
|
|
/* Set interruptible system calls, and read() for a job token. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
set_child_handler_action_flags (1, waiting_jobs != NULL);
|
|
|
|
|
got_token = read (job_rfd, &token, 1);
|
|
|
|
|
saved_errno = errno;
|
|
|
|
|
set_child_handler_action_flags (0, waiting_jobs != NULL);
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#endif
|
1999-08-23 13:35:14 +08:00
|
|
|
|
|
2001-06-01 11:56:50 +08:00
|
|
|
|
/* If we got one, we're done here. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (got_token == 1)
|
1999-08-01 14:05:17 +08:00
|
|
|
|
{
|
2010-07-06 02:32:03 +08:00
|
|
|
|
DB (DB_JOBS, (_("Obtained token for child %p (%s).\n"),
|
|
|
|
|
c, c->file->name));
|
1999-08-24 06:15:17 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
1999-08-01 14:05:17 +08:00
|
|
|
|
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#ifndef WINDOWS32
|
2001-06-01 11:56:50 +08:00
|
|
|
|
/* If the error _wasn't_ expected (EINTR or EBADF), punt. Otherwise,
|
|
|
|
|
go back and reap_children(), and try again. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
errno = saved_errno;
|
1999-08-24 06:15:17 +08:00
|
|
|
|
if (errno != EINTR && errno != EBADF)
|
|
|
|
|
pfatal_with_name (_("read jobs pipe"));
|
2001-06-01 11:56:50 +08:00
|
|
|
|
if (errno == EBADF)
|
|
|
|
|
DB (DB_JOBS, ("Read returned EBADF.\n"));
|
2011-11-14 08:42:49 +08:00
|
|
|
|
#endif
|
1999-08-24 06:15:17 +08:00
|
|
|
|
}
|
1999-08-01 14:05:17 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2005-05-03 21:57:20 +08:00
|
|
|
|
++jobserver_tokens;
|
|
|
|
|
|
2010-08-30 07:05:26 +08:00
|
|
|
|
/* Trace the build.
|
|
|
|
|
Use message here so that changes to working directories are logged. */
|
2013-09-12 16:07:52 +08:00
|
|
|
|
if (trace_flag)
|
2010-08-30 07:05:26 +08:00
|
|
|
|
{
|
|
|
|
|
char *newer = allocated_variable_expand_for_file ("$?", c->file);
|
2013-04-28 13:41:47 +08:00
|
|
|
|
const char *nm;
|
2010-08-30 07:05:26 +08:00
|
|
|
|
|
|
|
|
|
if (! cmds->fileinfo.filenm)
|
|
|
|
|
nm = _("<builtin>");
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-04-28 13:41:47 +08:00
|
|
|
|
char *n = alloca (strlen (cmds->fileinfo.filenm) + 1 + 11 + 1);
|
|
|
|
|
sprintf (n, "%s:%lu", cmds->fileinfo.filenm, cmds->fileinfo.lineno);
|
|
|
|
|
nm = n;
|
2010-08-30 07:05:26 +08:00
|
|
|
|
}
|
2007-05-12 04:57:21 +08:00
|
|
|
|
|
2010-08-30 07:05:26 +08:00
|
|
|
|
if (newer[0] == '\0')
|
2012-03-04 08:24:20 +08:00
|
|
|
|
message (0, _("%s: target '%s' does not exist"), nm, c->file->name);
|
2010-08-30 07:05:26 +08:00
|
|
|
|
else
|
2012-03-04 08:24:20 +08:00
|
|
|
|
message (0, _("%s: update target '%s' due to: %s"), nm,
|
2010-08-30 07:05:26 +08:00
|
|
|
|
c->file->name, newer);
|
2007-05-12 04:57:21 +08:00
|
|
|
|
|
2010-08-30 07:05:26 +08:00
|
|
|
|
free (newer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The job is now primed. Start it running.
|
|
|
|
|
(This will notice if there is in fact no recipe.) */
|
2007-05-12 04:57:21 +08:00
|
|
|
|
start_waiting_job (c);
|
1995-04-27 05:15:25 +08:00
|
|
|
|
|
1999-11-17 15:33:47 +08:00
|
|
|
|
if (job_slots == 1 || not_parallel)
|
1995-04-27 05:15:25 +08:00
|
|
|
|
/* Since there is only one job slot, make things run linearly.
|
2012-03-04 08:24:20 +08:00
|
|
|
|
Wait for the child to die, setting the state to 'cs_finished'. */
|
1995-04-27 05:15:25 +08:00
|
|
|
|
while (file->command_state == cs_running)
|
|
|
|
|
reap_children (1, 0);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
OUTPUT_UNSET ();
|
1996-03-20 22:57:41 +08:00
|
|
|
|
return;
|
1992-06-13 07:41:40 +08:00
|
|
|
|
}
|
1992-06-16 05:47:25 +08:00
|
|
|
|
|
1992-06-26 08:33:00 +08:00
|
|
|
|
/* Move CHILD's pointers to the next command for it to execute.
|
|
|
|
|
Returns nonzero if there is another command. */
|
|
|
|
|
|
|
|
|
|
static int
|
2002-10-15 05:54:04 +08:00
|
|
|
|
job_next_command (struct child *child)
|
1992-06-26 08:33:00 +08:00
|
|
|
|
{
|
1995-04-27 05:15:25 +08:00
|
|
|
|
while (child->command_ptr == 0 || *child->command_ptr == '\0')
|
1992-06-26 08:33:00 +08:00
|
|
|
|
{
|
|
|
|
|
/* There are no more lines in the expansion of this line. */
|
|
|
|
|
if (child->command_line == child->file->cmds->ncommand_lines)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* There are no more lines to be expanded. */
|
|
|
|
|
child->command_ptr = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1992-06-26 08:33:00 +08:00
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Get the next line to run. */
|
|
|
|
|
child->command_ptr = child->command_lines[child->command_line++];
|
1992-06-26 08:33:00 +08:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-21 14:32:59 +08:00
|
|
|
|
/* Determine if the load average on the system is too high to start a new job.
|
|
|
|
|
The real system load average is only recomputed once a second. However, a
|
|
|
|
|
very parallel make can easily start tens or even hundreds of jobs in a
|
|
|
|
|
second, which brings the system to its knees for a while until that first
|
|
|
|
|
batch of jobs clears out.
|
|
|
|
|
|
|
|
|
|
To avoid this we use a weighted algorithm to try to account for jobs which
|
|
|
|
|
have been started since the last second, and guess what the load average
|
|
|
|
|
would be now if it were computed.
|
|
|
|
|
|
|
|
|
|
This algorithm was provided by Thomas Riedl <thomas.riedl@siemens.com>,
|
|
|
|
|
who writes:
|
|
|
|
|
|
|
|
|
|
! calculate something load-oid and add to the observed sys.load,
|
|
|
|
|
! so that latter can catch up:
|
|
|
|
|
! - every job started increases jobctr;
|
|
|
|
|
! - every dying job decreases a positive jobctr;
|
|
|
|
|
! - the jobctr value gets zeroed every change of seconds,
|
|
|
|
|
! after its value*weight_b is stored into the 'backlog' value last_sec
|
|
|
|
|
! - weight_a times the sum of jobctr and last_sec gets
|
|
|
|
|
! added to the observed sys.load.
|
|
|
|
|
!
|
|
|
|
|
! The two weights have been tried out on 24 and 48 proc. Sun Solaris-9
|
|
|
|
|
! machines, using a several-thousand-jobs-mix of cpp, cc, cxx and smallish
|
|
|
|
|
! sub-shelled commands (rm, echo, sed...) for tests.
|
|
|
|
|
! lowering the 'direct influence' factor weight_a (e.g. to 0.1)
|
|
|
|
|
! resulted in significant excession of the load limit, raising it
|
|
|
|
|
! (e.g. to 0.5) took bad to small, fast-executing jobs and didn't
|
|
|
|
|
! reach the limit in most test cases.
|
|
|
|
|
!
|
|
|
|
|
! lowering the 'history influence' weight_b (e.g. to 0.1) resulted in
|
|
|
|
|
! exceeding the limit for longer-running stuff (compile jobs in
|
|
|
|
|
! the .5 to 1.5 sec. range),raising it (e.g. to 0.5) overrepresented
|
|
|
|
|
! small jobs' effects.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define LOAD_WEIGHT_A 0.25
|
|
|
|
|
#define LOAD_WEIGHT_B 0.25
|
|
|
|
|
|
1992-06-13 07:41:40 +08:00
|
|
|
|
static int
|
2002-10-15 05:54:04 +08:00
|
|
|
|
load_too_high (void)
|
1992-06-13 07:41:40 +08:00
|
|
|
|
{
|
2004-05-17 03:16:52 +08:00
|
|
|
|
#if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__)
|
1994-07-26 07:23:03 +08:00
|
|
|
|
return 1;
|
|
|
|
|
#else
|
2004-01-21 14:32:59 +08:00
|
|
|
|
static double last_sec;
|
|
|
|
|
static time_t last_now;
|
|
|
|
|
double load, guess;
|
|
|
|
|
time_t now;
|
1992-06-13 07:41:40 +08:00
|
|
|
|
|
2006-02-01 15:54:22 +08:00
|
|
|
|
#ifdef WINDOWS32
|
|
|
|
|
/* sub_proc.c cannot wait for more than MAXIMUM_WAIT_OBJECTS children */
|
|
|
|
|
if (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
|
|
|
|
|
return 1;
|
|
|
|
|
#endif
|
|
|
|
|
|
1992-06-13 07:41:40 +08:00
|
|
|
|
if (max_load_average < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2004-01-21 14:32:59 +08:00
|
|
|
|
/* Find the real system load average. */
|
1992-06-13 07:41:40 +08:00
|
|
|
|
make_access ();
|
|
|
|
|
if (getloadavg (&load, 1) != 1)
|
|
|
|
|
{
|
1993-01-09 06:40:24 +08:00
|
|
|
|
static int lossage = -1;
|
1992-06-16 05:47:25 +08:00
|
|
|
|
/* Complain only once for the same error. */
|
1993-01-09 06:40:24 +08:00
|
|
|
|
if (lossage == -1 || errno != lossage)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
if (errno == 0)
|
|
|
|
|
/* An errno value of zero means getloadavg is just unsupported. */
|
|
|
|
|
error (NILF,
|
2000-02-05 15:50:47 +08:00
|
|
|
|
_("cannot enforce load limits on this operating system"));
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else
|
|
|
|
|
perror_with_name (_("cannot enforce load limit: "), "getloadavg");
|
|
|
|
|
}
|
1992-06-13 07:41:40 +08:00
|
|
|
|
lossage = errno;
|
|
|
|
|
load = 0;
|
|
|
|
|
}
|
|
|
|
|
user_access ();
|
|
|
|
|
|
2004-01-21 14:32:59 +08:00
|
|
|
|
/* If we're in a new second zero the counter and correct the backlog
|
|
|
|
|
value. Only keep the backlog for one extra second; after that it's 0. */
|
|
|
|
|
now = time (NULL);
|
|
|
|
|
if (last_now < now)
|
|
|
|
|
{
|
|
|
|
|
if (last_now == now - 1)
|
|
|
|
|
last_sec = LOAD_WEIGHT_B * job_counter;
|
|
|
|
|
else
|
|
|
|
|
last_sec = 0.0;
|
|
|
|
|
|
|
|
|
|
job_counter = 0;
|
|
|
|
|
last_now = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try to guess what the load would be right now. */
|
|
|
|
|
guess = load + (LOAD_WEIGHT_A * (job_counter + last_sec));
|
|
|
|
|
|
|
|
|
|
DB (DB_JOBS, ("Estimated system load = %f (actual = %f) (max requested = %f)\n",
|
|
|
|
|
guess, load, max_load_average));
|
|
|
|
|
|
|
|
|
|
return guess >= max_load_average;
|
1994-07-26 07:23:03 +08:00
|
|
|
|
#endif
|
1992-06-13 07:41:40 +08:00
|
|
|
|
}
|
1992-06-16 05:47:25 +08:00
|
|
|
|
|
|
|
|
|
/* Start jobs that are waiting for the load to be lower. */
|
|
|
|
|
|
1992-06-13 07:41:40 +08:00
|
|
|
|
void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
start_waiting_jobs (void)
|
1992-06-13 07:41:40 +08:00
|
|
|
|
{
|
1993-04-09 06:08:11 +08:00
|
|
|
|
struct child *job;
|
|
|
|
|
|
1993-04-08 05:10:12 +08:00
|
|
|
|
if (waiting_jobs == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
do
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
1992-06-16 05:47:25 +08:00
|
|
|
|
/* Check for recently deceased descendants. */
|
|
|
|
|
reap_children (0, 0);
|
|
|
|
|
|
1993-04-08 05:10:12 +08:00
|
|
|
|
/* Take a job off the waiting list. */
|
|
|
|
|
job = waiting_jobs;
|
|
|
|
|
waiting_jobs = job->next;
|
1992-06-13 07:41:40 +08:00
|
|
|
|
|
1993-04-08 05:10:12 +08:00
|
|
|
|
/* Try to start that job. We break out of the loop as soon
|
2013-05-17 14:29:46 +08:00
|
|
|
|
as start_waiting_job puts one back on the waiting list. */
|
1996-03-20 22:57:41 +08:00
|
|
|
|
}
|
|
|
|
|
while (start_waiting_job (job) && waiting_jobs != 0);
|
|
|
|
|
|
|
|
|
|
return;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifndef WINDOWS32
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
/* EMX: Start a child process. This function returns the new pid. */
|
2007-12-22 19:27:02 +08:00
|
|
|
|
# if defined __EMX__
|
2003-03-25 07:14:15 +08:00
|
|
|
|
int
|
|
|
|
|
child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp)
|
|
|
|
|
{
|
|
|
|
|
int pid;
|
|
|
|
|
/* stdin_fd == 0 means: nothing to do for stdin;
|
|
|
|
|
stdout_fd == 1 means: nothing to do for stdout */
|
|
|
|
|
int save_stdin = (stdin_fd != 0) ? dup (0) : 0;
|
|
|
|
|
int save_stdout = (stdout_fd != 1) ? dup (1): 1;
|
|
|
|
|
|
|
|
|
|
/* < 0 only if dup() failed */
|
|
|
|
|
if (save_stdin < 0)
|
2003-03-25 11:21:42 +08:00
|
|
|
|
fatal (NILF, _("no more file handles: could not duplicate stdin\n"));
|
2003-03-25 07:14:15 +08:00
|
|
|
|
if (save_stdout < 0)
|
2003-03-25 11:21:42 +08:00
|
|
|
|
fatal (NILF, _("no more file handles: could not duplicate stdout\n"));
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
/* Close unnecessary file handles for the child. */
|
|
|
|
|
if (save_stdin != 0)
|
|
|
|
|
CLOSE_ON_EXEC (save_stdin);
|
|
|
|
|
if (save_stdout != 1)
|
|
|
|
|
CLOSE_ON_EXEC (save_stdout);
|
|
|
|
|
|
|
|
|
|
/* Connect the pipes to the child process. */
|
|
|
|
|
if (stdin_fd != 0)
|
|
|
|
|
(void) dup2 (stdin_fd, 0);
|
|
|
|
|
if (stdout_fd != 1)
|
|
|
|
|
(void) dup2 (stdout_fd, 1);
|
|
|
|
|
|
|
|
|
|
/* stdin_fd and stdout_fd must be closed on exit because we are
|
|
|
|
|
still in the parent process */
|
|
|
|
|
if (stdin_fd != 0)
|
|
|
|
|
CLOSE_ON_EXEC (stdin_fd);
|
|
|
|
|
if (stdout_fd != 1)
|
|
|
|
|
CLOSE_ON_EXEC (stdout_fd);
|
|
|
|
|
|
|
|
|
|
/* Run the command. */
|
|
|
|
|
pid = exec_command (argv, envp);
|
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
/* Restore stdout/stdin of the parent and close temporary FDs. */
|
|
|
|
|
if (stdin_fd != 0)
|
|
|
|
|
{
|
|
|
|
|
if (dup2 (save_stdin, 0) != 0)
|
|
|
|
|
fatal (NILF, _("Could not restore stdin\n"));
|
|
|
|
|
else
|
|
|
|
|
close (save_stdin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stdout_fd != 1)
|
|
|
|
|
{
|
|
|
|
|
if (dup2 (save_stdout, 1) != 1)
|
|
|
|
|
fatal (NILF, _("Could not restore stdout\n"));
|
|
|
|
|
else
|
|
|
|
|
close (save_stdout);
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
return pid;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-11 04:16:28 +08:00
|
|
|
|
#elif !defined (_AMIGA) && !defined (__MSDOS__) && !defined (VMS)
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
/* UNIX:
|
|
|
|
|
Replace the current process with one executing the command in ARGV.
|
1992-01-21 02:49:36 +08:00
|
|
|
|
STDIN_FD and STDOUT_FD are used as the process's stdin and stdout; ENVP is
|
|
|
|
|
the environment of the new program. This function does not return. */
|
|
|
|
|
void
|
2002-10-15 05:54:04 +08:00
|
|
|
|
child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
|
|
|
|
if (stdin_fd != 0)
|
|
|
|
|
(void) dup2 (stdin_fd, 0);
|
|
|
|
|
if (stdout_fd != 1)
|
|
|
|
|
(void) dup2 (stdout_fd, 1);
|
1995-08-02 02:46:37 +08:00
|
|
|
|
if (stdin_fd != 0)
|
|
|
|
|
(void) close (stdin_fd);
|
|
|
|
|
if (stdout_fd != 1)
|
|
|
|
|
(void) close (stdout_fd);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
/* Run the command. */
|
|
|
|
|
exec_command (argv, envp);
|
|
|
|
|
}
|
2005-06-11 04:16:28 +08:00
|
|
|
|
#endif /* !AMIGA && !__MSDOS__ && !VMS */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* !WINDOWS32 */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1996-05-14 02:38:29 +08:00
|
|
|
|
#ifndef _AMIGA
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Replace the current process with one running the command in ARGV,
|
|
|
|
|
with environment ENVP. This function does not return. */
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
/* EMX: This function returns the pid of the child process. */
|
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
int
|
|
|
|
|
# else
|
2005-05-03 21:57:20 +08:00
|
|
|
|
void
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# endif
|
2002-10-15 05:54:04 +08:00
|
|
|
|
exec_command (char **argv, char **envp)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifdef VMS
|
2000-01-22 13:43:03 +08:00
|
|
|
|
/* to work around a problem with signals and execve: ignore them */
|
|
|
|
|
#ifdef SIGCHLD
|
|
|
|
|
signal (SIGCHLD,SIG_IGN);
|
|
|
|
|
#endif
|
1997-09-06 05:01:49 +08:00
|
|
|
|
/* Run the program. */
|
|
|
|
|
execve (argv[0], argv, envp);
|
|
|
|
|
perror_with_name ("execve: ", argv[0]);
|
|
|
|
|
_exit (EXIT_FAILURE);
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#else
|
1997-09-06 05:01:49 +08:00
|
|
|
|
#ifdef WINDOWS32
|
|
|
|
|
HANDLE hPID;
|
|
|
|
|
HANDLE hWaitPID;
|
|
|
|
|
int exit_code = EXIT_FAILURE;
|
|
|
|
|
|
|
|
|
|
/* make sure CreateProcess() has Path it needs */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
sync_Path_environment ();
|
1997-09-06 05:01:49 +08:00
|
|
|
|
|
|
|
|
|
/* launch command */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
hPID = process_easy (argv, envp, -1, -1);
|
1997-09-06 05:01:49 +08:00
|
|
|
|
|
|
|
|
|
/* make sure launch ok */
|
|
|
|
|
if (hPID == INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
fprintf (stderr, _("process_easy() failed to launch process (e=%ld)\n"),
|
|
|
|
|
process_last_err (hPID));
|
1997-09-06 05:01:49 +08:00
|
|
|
|
for (i = 0; argv[i]; i++)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
fprintf (stderr, "%s ", argv[i]);
|
|
|
|
|
fprintf (stderr, _("\nCounted %d args in failed launch\n"), i);
|
|
|
|
|
exit (EXIT_FAILURE);
|
1997-09-06 05:01:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wait and reap last child */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
hWaitPID = process_wait_for_any (1, 0);
|
2004-03-22 23:11:48 +08:00
|
|
|
|
while (hWaitPID)
|
1997-09-06 05:01:49 +08:00
|
|
|
|
{
|
|
|
|
|
/* was an error found on this process? */
|
2013-07-22 05:52:13 +08:00
|
|
|
|
int err = process_last_err (hWaitPID);
|
1997-09-06 05:01:49 +08:00
|
|
|
|
|
|
|
|
|
/* get exit data */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
exit_code = process_exit_code (hWaitPID);
|
1997-09-06 05:01:49 +08:00
|
|
|
|
|
|
|
|
|
if (err)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
fprintf (stderr, "make (e=%d, rc=%d): %s",
|
|
|
|
|
err, exit_code, map_windows32_error_to_string (err));
|
1997-09-06 05:01:49 +08:00
|
|
|
|
|
|
|
|
|
/* cleanup process */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
process_cleanup (hWaitPID);
|
1997-09-06 05:01:49 +08:00
|
|
|
|
|
|
|
|
|
/* expect to find only last pid, warn about other pids reaped */
|
|
|
|
|
if (hWaitPID == hPID)
|
|
|
|
|
break;
|
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
char *pidstr = xstrdup (pid2str ((pid_t)hWaitPID));
|
|
|
|
|
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
_("make reaped child pid %s, still waiting for pid %s\n"),
|
|
|
|
|
pidstr, pid2str ((pid_t)hPID));
|
|
|
|
|
free (pidstr);
|
|
|
|
|
}
|
1997-09-06 05:01:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return child's exit code as our exit code */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
exit (exit_code);
|
1997-09-06 05:01:49 +08:00
|
|
|
|
|
|
|
|
|
#else /* !WINDOWS32 */
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
int pid;
|
|
|
|
|
# endif
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* Be the user, permanently. */
|
|
|
|
|
child_access ();
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
/* Run the program. */
|
|
|
|
|
pid = spawnvpe (P_NOWAIT, argv[0], argv, envp);
|
|
|
|
|
if (pid >= 0)
|
|
|
|
|
return pid;
|
|
|
|
|
|
|
|
|
|
/* the file might have a strange shell extension */
|
|
|
|
|
if (errno == ENOENT)
|
|
|
|
|
errno = ENOEXEC;
|
|
|
|
|
|
|
|
|
|
# else
|
1995-01-15 23:57:48 +08:00
|
|
|
|
/* Run the program. */
|
|
|
|
|
environ = envp;
|
|
|
|
|
execvp (argv[0], argv);
|
1995-11-22 08:06:28 +08:00
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# endif /* !__EMX__ */
|
|
|
|
|
|
1995-01-15 23:57:48 +08:00
|
|
|
|
switch (errno)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
1995-01-15 23:57:48 +08:00
|
|
|
|
case ENOENT:
|
1999-07-28 14:23:37 +08:00
|
|
|
|
error (NILF, _("%s: Command not found"), argv[0]);
|
1995-01-15 23:57:48 +08:00
|
|
|
|
break;
|
|
|
|
|
case ENOEXEC:
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* The file is not executable. Try it as a shell script. */
|
|
|
|
|
extern char *getenv ();
|
|
|
|
|
char *shell;
|
|
|
|
|
char **new_argv;
|
|
|
|
|
int argc;
|
2004-03-22 23:11:48 +08:00
|
|
|
|
int i=1;
|
1995-01-15 23:57:48 +08:00
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
/* Do not use $SHELL from the environment */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
struct variable *p = lookup_variable ("SHELL", 5);
|
|
|
|
|
if (p)
|
|
|
|
|
shell = p->value;
|
2003-03-25 11:21:42 +08:00
|
|
|
|
else
|
|
|
|
|
shell = 0;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
shell = getenv ("SHELL");
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (shell == 0)
|
|
|
|
|
shell = default_shell;
|
1995-01-15 23:57:48 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
argc = 1;
|
|
|
|
|
while (argv[argc] != 0)
|
|
|
|
|
++argc;
|
1995-01-15 23:57:48 +08:00
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
if (!unixy_shell)
|
|
|
|
|
++argc;
|
|
|
|
|
# endif
|
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
new_argv = alloca ((1 + argc + 1) * sizeof (char *));
|
|
|
|
|
new_argv[0] = shell;
|
2004-03-22 23:11:48 +08:00
|
|
|
|
|
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
if (!unixy_shell)
|
|
|
|
|
{
|
|
|
|
|
new_argv[1] = "/c";
|
|
|
|
|
++i;
|
|
|
|
|
--argc;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
new_argv[i] = argv[0];
|
2013-05-17 14:29:46 +08:00
|
|
|
|
while (argc > 0)
|
|
|
|
|
{
|
|
|
|
|
new_argv[i + argc] = argv[argc];
|
|
|
|
|
--argc;
|
|
|
|
|
}
|
1995-01-15 23:57:48 +08:00
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__
|
2013-05-17 14:29:46 +08:00
|
|
|
|
pid = spawnvpe (P_NOWAIT, shell, new_argv, envp);
|
|
|
|
|
if (pid >= 0)
|
2003-03-25 07:14:15 +08:00
|
|
|
|
break;
|
|
|
|
|
# else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
execvp (shell, new_argv);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (errno == ENOENT)
|
|
|
|
|
error (NILF, _("%s: Shell program not found"), shell);
|
|
|
|
|
else
|
|
|
|
|
perror_with_name ("execvp: ", shell);
|
|
|
|
|
break;
|
1995-01-15 23:57:48 +08:00
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
case EINVAL:
|
|
|
|
|
/* this nasty error was driving me nuts :-( */
|
|
|
|
|
error (NILF, _("spawnvpe: environment space might be exhausted"));
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
# endif
|
|
|
|
|
|
1995-01-15 23:57:48 +08:00
|
|
|
|
default:
|
|
|
|
|
perror_with_name ("execvp: ", argv[0]);
|
|
|
|
|
break;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
return pid;
|
|
|
|
|
# else
|
1992-01-21 02:49:36 +08:00
|
|
|
|
_exit (127);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# endif
|
1997-09-06 05:01:49 +08:00
|
|
|
|
#endif /* !WINDOWS32 */
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#endif /* !VMS */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
1996-05-14 02:38:29 +08:00
|
|
|
|
#else /* On Amiga */
|
2002-10-15 05:54:04 +08:00
|
|
|
|
void exec_command (char **argv)
|
1996-05-14 02:38:29 +08:00
|
|
|
|
{
|
1997-09-06 05:01:49 +08:00
|
|
|
|
MyExecute (argv);
|
1996-05-14 02:38:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clean_tmp (void)
|
|
|
|
|
{
|
1997-09-06 05:01:49 +08:00
|
|
|
|
DeleteFile (amiga_bname);
|
1996-05-14 02:38:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* On Amiga */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
|
#ifndef VMS
|
1995-01-15 21:43:48 +08:00
|
|
|
|
/* Figure out the argument list necessary to run LINE as a command. Try to
|
|
|
|
|
avoid using a shell. This routine handles only ' quoting, and " quoting
|
2012-03-04 08:24:20 +08:00
|
|
|
|
when no backslash, $ or ' characters are seen in the quotes. Starting
|
1995-01-15 21:43:48 +08:00
|
|
|
|
quotes may be escaped with a backslash. If any of the characters in
|
|
|
|
|
sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
|
|
|
|
|
is the first word of a line, the shell is used.
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
|
|
|
|
|
If *RESTP is NULL, newlines will be ignored.
|
|
|
|
|
|
|
|
|
|
SHELL is the shell to use, or nil to use the default shell.
|
2007-10-10 21:22:21 +08:00
|
|
|
|
IFS is the value of $IFS, or nil (meaning the default).
|
|
|
|
|
|
|
|
|
|
FLAGS is the value of lines_flags for this command line. It is
|
|
|
|
|
used in the WINDOWS32 port to check whether + or $(MAKE) were found
|
|
|
|
|
in this command line, in which case the effect of just_print_flag
|
|
|
|
|
is overridden. */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
static char **
|
2002-10-15 05:54:04 +08:00
|
|
|
|
construct_command_argv_internal (char *line, char **restp, char *shell,
|
2010-07-06 14:37:42 +08:00
|
|
|
|
char *shellflags, char *ifs, int flags,
|
2011-11-14 08:58:49 +08:00
|
|
|
|
char **batch_filename UNUSED)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
1994-07-26 07:23:03 +08:00
|
|
|
|
#ifdef __MSDOS__
|
1997-04-07 15:21:16 +08:00
|
|
|
|
/* MSDOS supports both the stock DOS shell and ports of Unixy shells.
|
2012-03-04 08:24:20 +08:00
|
|
|
|
We call 'system' for anything that requires ''slow'' processing,
|
1997-04-07 15:21:16 +08:00
|
|
|
|
because DOS shells are too dumb. When $SHELL points to a real
|
2012-03-04 08:24:20 +08:00
|
|
|
|
(unix-style) shell, 'system' just calls it to do everything. When
|
|
|
|
|
$SHELL points to a DOS shell, 'system' does most of the work
|
1997-04-07 15:21:16 +08:00
|
|
|
|
internally, calling the shell only for its internal commands.
|
|
|
|
|
However, it looks on the $PATH first, so you can e.g. have an
|
2012-03-04 08:24:20 +08:00
|
|
|
|
external command named 'mkdir'.
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
Since we call 'system', certain characters and commands below are
|
1997-04-07 15:21:16 +08:00
|
|
|
|
actually not specific to COMMAND.COM, but to the DJGPP implementation
|
2012-03-04 08:24:20 +08:00
|
|
|
|
of 'system'. In particular:
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
The shell wildcard characters are in DOS_CHARS because they will
|
2012-03-04 08:24:20 +08:00
|
|
|
|
not be expanded if we call the child via 'spawnXX'.
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
The ';' is in DOS_CHARS, because our 'system' knows how to run
|
1997-04-07 15:21:16 +08:00
|
|
|
|
multiple commands on a single line.
|
|
|
|
|
|
|
|
|
|
DOS_CHARS also include characters special to 4DOS/NDOS, so we
|
|
|
|
|
won't have to tell one from another and have one more set of
|
|
|
|
|
commands and special characters. */
|
|
|
|
|
static char sh_chars_dos[] = "*?[];|<>%^&()";
|
|
|
|
|
static char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"copy", "ctty", "date", "del", "dir", "echo",
|
|
|
|
|
"erase", "exit", "for", "goto", "if", "md",
|
|
|
|
|
"mkdir", "path", "pause", "prompt", "rd",
|
|
|
|
|
"rmdir", "rem", "ren", "rename", "set",
|
|
|
|
|
"shift", "time", "type", "ver", "verify",
|
|
|
|
|
"vol", ":", 0 };
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^";
|
1999-09-11 13:10:27 +08:00
|
|
|
|
static char *sh_cmds_sh[] = { "cd", "echo", "eval", "exec", "exit", "login",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"logout", "set", "umask", "wait", "while",
|
|
|
|
|
"for", "case", "if", ":", ".", "break",
|
|
|
|
|
"continue", "export", "read", "readonly",
|
|
|
|
|
"shift", "times", "trap", "switch", "unset",
|
2009-06-08 01:40:06 +08:00
|
|
|
|
"ulimit", 0 };
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
char *sh_chars;
|
|
|
|
|
char **sh_cmds;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#elif defined (__EMX__)
|
|
|
|
|
static char sh_chars_dos[] = "*?[];|<>%^&()";
|
|
|
|
|
static char *sh_cmds_dos[] = { "break", "call", "cd", "chcp", "chdir", "cls",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"copy", "ctty", "date", "del", "dir", "echo",
|
|
|
|
|
"erase", "exit", "for", "goto", "if", "md",
|
|
|
|
|
"mkdir", "path", "pause", "prompt", "rd",
|
|
|
|
|
"rmdir", "rem", "ren", "rename", "set",
|
|
|
|
|
"shift", "time", "type", "ver", "verify",
|
|
|
|
|
"vol", ":", 0 };
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
static char sh_chars_os2[] = "*?[];|<>%^()\"'&";
|
|
|
|
|
static char *sh_cmds_os2[] = { "call", "cd", "chcp", "chdir", "cls", "copy",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"date", "del", "detach", "dir", "echo",
|
|
|
|
|
"endlocal", "erase", "exit", "for", "goto", "if",
|
|
|
|
|
"keys", "md", "mkdir", "move", "path", "pause",
|
|
|
|
|
"prompt", "rd", "rem", "ren", "rename", "rmdir",
|
|
|
|
|
"set", "setlocal", "shift", "start", "time",
|
2003-03-25 07:14:15 +08:00
|
|
|
|
"type", "ver", "verify", "vol", ":", 0 };
|
|
|
|
|
|
2003-03-25 11:21:42 +08:00
|
|
|
|
static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^~'";
|
2003-03-25 07:14:15 +08:00
|
|
|
|
static char *sh_cmds_sh[] = { "echo", "cd", "eval", "exec", "exit", "login",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"logout", "set", "umask", "wait", "while",
|
|
|
|
|
"for", "case", "if", ":", ".", "break",
|
|
|
|
|
"continue", "export", "read", "readonly",
|
|
|
|
|
"shift", "times", "trap", "switch", "unset",
|
2003-03-25 07:14:15 +08:00
|
|
|
|
0 };
|
|
|
|
|
char *sh_chars;
|
|
|
|
|
char **sh_cmds;
|
|
|
|
|
|
|
|
|
|
#elif defined (_AMIGA)
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
static char sh_chars[] = "#;\"|<>()?*$`";
|
|
|
|
|
static char *sh_cmds[] = { "cd", "eval", "if", "delete", "echo", "copy",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"rename", "set", "setenv", "date", "makedir",
|
|
|
|
|
"skip", "else", "endif", "path", "prompt",
|
|
|
|
|
"unset", "unsetenv", "version",
|
|
|
|
|
0 };
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#elif defined (WINDOWS32)
|
2012-12-07 22:23:39 +08:00
|
|
|
|
/* We used to have a double quote (") in sh_chars_dos[] below, but
|
|
|
|
|
that caused any command line with quoted file names be run
|
|
|
|
|
through a temporary batch file, which introduces command-line
|
|
|
|
|
limit of 4K charcaters imposed by cmd.exe. Since CreateProcess
|
|
|
|
|
can handle quoted file names just fine, removing the quote lifts
|
|
|
|
|
the limit from a very frequent use case, because using quoted
|
|
|
|
|
file names is commonplace on MS-Windows. */
|
|
|
|
|
static char sh_chars_dos[] = "|&<>";
|
2009-12-11 23:54:19 +08:00
|
|
|
|
static char *sh_cmds_dos[] = { "assoc", "break", "call", "cd", "chcp",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"chdir", "cls", "color", "copy", "ctty",
|
|
|
|
|
"date", "del", "dir", "echo", "echo.",
|
|
|
|
|
"endlocal", "erase", "exit", "for", "ftype",
|
2013-05-18 19:07:36 +08:00
|
|
|
|
"goto", "if", "if", "md", "mkdir", "move",
|
2013-09-14 13:04:04 +08:00
|
|
|
|
"path", "pause", "prompt", "rd", "rem", "ren",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"rename", "rmdir", "set", "setlocal",
|
|
|
|
|
"shift", "time", "title", "type", "ver",
|
|
|
|
|
"verify", "vol", ":", 0 };
|
1996-05-23 05:51:45 +08:00
|
|
|
|
static char sh_chars_sh[] = "#;\"*?[]&|<>(){}$`^";
|
|
|
|
|
static char *sh_cmds_sh[] = { "cd", "eval", "exec", "exit", "login",
|
2013-05-17 14:29:46 +08:00
|
|
|
|
"logout", "set", "umask", "wait", "while", "for",
|
|
|
|
|
"case", "if", ":", ".", "break", "continue",
|
|
|
|
|
"export", "read", "readonly", "shift", "times",
|
|
|
|
|
"trap", "switch", "test",
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#ifdef BATCH_MODE_ONLY_SHELL
|
|
|
|
|
"echo",
|
|
|
|
|
#endif
|
|
|
|
|
0 };
|
1996-05-23 05:51:45 +08:00
|
|
|
|
char* sh_chars;
|
|
|
|
|
char** sh_cmds;
|
2004-05-17 03:16:52 +08:00
|
|
|
|
#elif defined(__riscos__)
|
|
|
|
|
static char sh_chars[] = "";
|
|
|
|
|
static char *sh_cmds[] = { 0 };
|
2001-11-19 02:38:02 +08:00
|
|
|
|
#else /* must be UNIX-ish */
|
2004-01-08 11:17:08 +08:00
|
|
|
|
static char sh_chars[] = "#;\"*?[]&|<>(){}$`^~!";
|
2004-02-23 14:25:54 +08:00
|
|
|
|
static char *sh_cmds[] = { ".", ":", "break", "case", "cd", "continue",
|
|
|
|
|
"eval", "exec", "exit", "export", "for", "if",
|
|
|
|
|
"login", "logout", "read", "readonly", "set",
|
|
|
|
|
"shift", "switch", "test", "times", "trap",
|
2009-08-02 06:09:40 +08:00
|
|
|
|
"ulimit", "umask", "unset", "wait", "while", 0 };
|
2006-10-01 13:38:38 +08:00
|
|
|
|
# ifdef HAVE_DOS_PATHS
|
|
|
|
|
/* This is required if the MSYS/Cygwin ports (which do not define
|
|
|
|
|
WINDOWS32) are compiled with HAVE_DOS_PATHS defined, which uses
|
|
|
|
|
sh_chars_sh[] directly (see below). */
|
|
|
|
|
static char *sh_chars_sh = sh_chars;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
# endif /* HAVE_DOS_PATHS */
|
2004-02-23 14:25:54 +08:00
|
|
|
|
#endif
|
2006-04-10 06:09:24 +08:00
|
|
|
|
int i;
|
|
|
|
|
char *p;
|
|
|
|
|
char *ap;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
char *end;
|
1997-03-13 05:17:08 +08:00
|
|
|
|
int instring, word_has_equals, seen_nonequals, last_argument_was_empty;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
char **new_argv = 0;
|
2005-09-26 13:16:31 +08:00
|
|
|
|
char *argstr = 0;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-23 05:51:45 +08:00
|
|
|
|
int slow_flag = 0;
|
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (!unixy_shell)
|
|
|
|
|
{
|
|
|
|
|
sh_cmds = sh_cmds_dos;
|
|
|
|
|
sh_chars = sh_chars_dos;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sh_cmds = sh_cmds_sh;
|
|
|
|
|
sh_chars = sh_chars_sh;
|
|
|
|
|
}
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
if (restp != NULL)
|
|
|
|
|
*restp = NULL;
|
|
|
|
|
|
|
|
|
|
/* Make sure not to bother processing an empty line. */
|
2000-06-07 13:43:37 +08:00
|
|
|
|
while (isblank ((unsigned char)*line))
|
1992-01-21 02:49:36 +08:00
|
|
|
|
++line;
|
|
|
|
|
if (*line == '\0')
|
|
|
|
|
return 0;
|
|
|
|
|
|
2010-08-29 12:50:26 +08:00
|
|
|
|
if (shellflags == 0)
|
|
|
|
|
shellflags = posix_pedantic ? "-ec" : "-c";
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
/* See if it is safe to parse commands internally. */
|
|
|
|
|
if (shell == 0)
|
|
|
|
|
shell = default_shell;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1992-01-21 02:49:36 +08:00
|
|
|
|
else if (strcmp (shell, default_shell))
|
1996-05-23 05:51:45 +08:00
|
|
|
|
{
|
2006-04-10 06:09:24 +08:00
|
|
|
|
char *s1 = _fullpath (NULL, shell, 0);
|
|
|
|
|
char *s2 = _fullpath (NULL, default_shell, 0);
|
1996-05-23 05:51:45 +08:00
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : ""));
|
1996-05-23 05:51:45 +08:00
|
|
|
|
|
2000-03-27 14:54:37 +08:00
|
|
|
|
if (s1)
|
|
|
|
|
free (s1);
|
|
|
|
|
if (s2)
|
|
|
|
|
free (s2);
|
1996-05-23 05:51:45 +08:00
|
|
|
|
}
|
|
|
|
|
if (slow_flag)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
goto slow;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#else /* not WINDOWS32 */
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#if defined (__MSDOS__) || defined (__EMX__)
|
2007-05-09 10:01:53 +08:00
|
|
|
|
else if (strcasecmp (shell, default_shell))
|
1997-04-07 15:21:16 +08:00
|
|
|
|
{
|
|
|
|
|
extern int _is_unixy_shell (const char *_path);
|
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
|
DB (DB_BASIC, (_("$SHELL changed (was '%s', now '%s')\n"),
|
2003-03-25 11:21:42 +08:00
|
|
|
|
default_shell, shell));
|
1997-04-07 15:21:16 +08:00
|
|
|
|
unixy_shell = _is_unixy_shell (shell);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
/* we must allocate a copy of shell: construct_command_argv() will free
|
|
|
|
|
* shell after this function returns. */
|
2003-05-02 09:44:59 +08:00
|
|
|
|
default_shell = xstrdup (shell);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
if (unixy_shell)
|
|
|
|
|
{
|
|
|
|
|
sh_chars = sh_chars_sh;
|
|
|
|
|
sh_cmds = sh_cmds_sh;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sh_chars = sh_chars_dos;
|
|
|
|
|
sh_cmds = sh_cmds_dos;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__
|
|
|
|
|
if (_osmode == OS2_MODE)
|
|
|
|
|
{
|
|
|
|
|
sh_chars = sh_chars_os2;
|
|
|
|
|
sh_cmds = sh_cmds_os2;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
2003-05-02 09:44:59 +08:00
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#else /* !__MSDOS__ */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
else if (strcmp (shell, default_shell))
|
|
|
|
|
goto slow;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#endif /* !__MSDOS__ && !__EMX__ */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* not WINDOWS32 */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
if (ifs != 0)
|
|
|
|
|
for (ap = ifs; *ap != '\0'; ++ap)
|
|
|
|
|
if (*ap != ' ' && *ap != '\t' && *ap != '\n')
|
2013-05-17 14:29:46 +08:00
|
|
|
|
goto slow;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2010-07-06 14:37:42 +08:00
|
|
|
|
if (shellflags != 0)
|
|
|
|
|
if (shellflags[0] != '-'
|
|
|
|
|
|| ((shellflags[1] != 'c' || shellflags[2] != '\0')
|
|
|
|
|
&& (shellflags[1] != 'e' || shellflags[2] != 'c' || shellflags[3] != '\0')))
|
|
|
|
|
goto slow;
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
i = strlen (line) + 1;
|
|
|
|
|
|
|
|
|
|
/* More than 1 arg per character is impossible. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
new_argv = xmalloc (i * sizeof (char *));
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
/* All the args can fit in a buffer as big as LINE is. */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
ap = new_argv[0] = argstr = xmalloc (i);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
end = ap + i;
|
|
|
|
|
|
|
|
|
|
/* I is how many complete arguments have been found. */
|
|
|
|
|
i = 0;
|
1997-03-13 05:17:08 +08:00
|
|
|
|
instring = word_has_equals = seen_nonequals = last_argument_was_empty = 0;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
for (p = line; *p != '\0'; ++p)
|
|
|
|
|
{
|
2005-06-26 11:31:29 +08:00
|
|
|
|
assert (ap <= end);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
if (instring)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* Inside a string, just copy any char except a closing quote
|
|
|
|
|
or a backslash-newline combination. */
|
|
|
|
|
if (*p == instring)
|
|
|
|
|
{
|
|
|
|
|
instring = 0;
|
|
|
|
|
if (ap == new_argv[0] || *(ap-1) == '\0')
|
|
|
|
|
last_argument_was_empty = 1;
|
|
|
|
|
}
|
|
|
|
|
else if (*p == '\\' && p[1] == '\n')
|
2005-06-26 11:31:29 +08:00
|
|
|
|
{
|
|
|
|
|
/* Backslash-newline is handled differently depending on what
|
|
|
|
|
kind of string we're in: inside single-quoted strings you
|
2010-11-07 05:56:23 +08:00
|
|
|
|
keep them; in double-quoted strings they disappear. For
|
|
|
|
|
DOS/Windows/OS2, if we don't have a POSIX shell, we keep the
|
|
|
|
|
pre-POSIX behavior of removing the backslash-newline. */
|
2005-08-25 12:40:10 +08:00
|
|
|
|
if (instring == '"'
|
|
|
|
|
#if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
|| !unixy_shell
|
2005-08-25 12:40:10 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
)
|
2005-06-26 11:31:29 +08:00
|
|
|
|
++p;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*(ap++) = *(p++);
|
|
|
|
|
*(ap++) = *p;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else if (*p == '\n' && restp != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* End of the command line. */
|
|
|
|
|
*restp = p;
|
|
|
|
|
goto end_of_line;
|
|
|
|
|
}
|
|
|
|
|
/* Backslash, $, and ` are special inside double quotes.
|
|
|
|
|
If we see any of those, punt.
|
|
|
|
|
But on MSDOS, if we use COMMAND.COM, double and single
|
|
|
|
|
quotes have the same effect. */
|
|
|
|
|
else if (instring == '"' && strchr ("\\$`", *p) != 0 && unixy_shell)
|
|
|
|
|
goto slow;
|
2012-12-07 22:23:39 +08:00
|
|
|
|
#ifdef WINDOWS32
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else if (instring == '"' && strncmp (p, "\\\"", 2) == 0)
|
|
|
|
|
*ap++ = *++p;
|
2012-12-07 22:23:39 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else
|
|
|
|
|
*ap++ = *p;
|
|
|
|
|
}
|
1999-10-15 15:00:58 +08:00
|
|
|
|
else if (strchr (sh_chars, *p) != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Not inside a string, but it's a special char. */
|
|
|
|
|
goto slow;
|
2010-07-12 13:23:19 +08:00
|
|
|
|
else if (one_shell && *p == '\n')
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* In .ONESHELL mode \n is a separator like ; or && */
|
|
|
|
|
goto slow;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
else if (*p == '.' && p[1] == '.' && p[2] == '.' && p[3] != '.')
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* '...' is a wildcard in DJGPP. */
|
|
|
|
|
goto slow;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Not a special char. */
|
|
|
|
|
switch (*p)
|
|
|
|
|
{
|
|
|
|
|
case '=':
|
|
|
|
|
/* Equals is a special character in leading words before the
|
|
|
|
|
first word with no equals sign in it. This is not the case
|
|
|
|
|
with sh -k, but we never get here when using nonstandard
|
|
|
|
|
shell flags. */
|
|
|
|
|
if (! seen_nonequals && unixy_shell)
|
|
|
|
|
goto slow;
|
|
|
|
|
word_has_equals = 1;
|
|
|
|
|
*ap++ = '=';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\\':
|
|
|
|
|
/* Backslash-newline has special case handling, ref POSIX.
|
2005-06-26 11:31:29 +08:00
|
|
|
|
We're in the fastpath, so emulate what the shell would do. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (p[1] == '\n')
|
|
|
|
|
{
|
|
|
|
|
/* Throw out the backslash and newline. */
|
2005-06-26 11:31:29 +08:00
|
|
|
|
++p;
|
|
|
|
|
|
|
|
|
|
/* If there's nothing in this argument yet, skip any
|
|
|
|
|
whitespace before the start of the next word. */
|
|
|
|
|
if (ap == new_argv[i])
|
|
|
|
|
p = next_token (p + 1) - 1;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
2013-05-01 23:31:53 +08:00
|
|
|
|
#ifdef WINDOWS32
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Backslash before whitespace is not special if our shell
|
|
|
|
|
is not Unixy. */
|
|
|
|
|
else if (isspace (p[1]) && !unixy_shell)
|
|
|
|
|
{
|
|
|
|
|
*ap++ = *p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
else if (p[1] != '\0')
|
1999-03-26 12:04:42 +08:00
|
|
|
|
{
|
2002-08-10 09:27:16 +08:00
|
|
|
|
#ifdef HAVE_DOS_PATHS
|
2005-08-08 13:08:00 +08:00
|
|
|
|
/* Only remove backslashes before characters special to Unixy
|
|
|
|
|
shells. All other backslashes are copied verbatim, since
|
|
|
|
|
they are probably DOS-style directory separators. This
|
|
|
|
|
still leaves a small window for problems, but at least it
|
|
|
|
|
should work for the vast majority of naive users. */
|
1999-03-26 12:04:42 +08:00
|
|
|
|
|
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
/* A dot is only special as part of the "..."
|
|
|
|
|
wildcard. */
|
1999-07-21 13:53:23 +08:00
|
|
|
|
if (strneq (p + 1, ".\\.\\.", 5))
|
1999-03-26 12:04:42 +08:00
|
|
|
|
{
|
|
|
|
|
*ap++ = '.';
|
|
|
|
|
*ap++ = '.';
|
|
|
|
|
p += 4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
1999-10-15 15:00:58 +08:00
|
|
|
|
if (p[1] != '\\' && p[1] != '\''
|
|
|
|
|
&& !isspace ((unsigned char)p[1])
|
2005-08-08 13:08:00 +08:00
|
|
|
|
&& strchr (sh_chars_sh, p[1]) == 0)
|
1999-03-26 12:04:42 +08:00
|
|
|
|
/* back up one notch, to copy the backslash */
|
|
|
|
|
--p;
|
2002-08-10 09:27:16 +08:00
|
|
|
|
#endif /* HAVE_DOS_PATHS */
|
1999-03-26 12:04:42 +08:00
|
|
|
|
|
|
|
|
|
/* Copy and skip the following char. */
|
|
|
|
|
*ap++ = *++p;
|
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\'':
|
|
|
|
|
case '"':
|
|
|
|
|
instring = *p;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
|
if (restp != NULL)
|
|
|
|
|
{
|
|
|
|
|
/* End of the command line. */
|
|
|
|
|
*restp = p;
|
|
|
|
|
goto end_of_line;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* Newlines are not special. */
|
|
|
|
|
*ap++ = '\n';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
|
case '\t':
|
|
|
|
|
/* We have the end of an argument.
|
|
|
|
|
Terminate the text of the argument. */
|
|
|
|
|
*ap++ = '\0';
|
|
|
|
|
new_argv[++i] = ap;
|
|
|
|
|
last_argument_was_empty = 0;
|
|
|
|
|
|
|
|
|
|
/* Update SEEN_NONEQUALS, which tells us if every word
|
|
|
|
|
heretofore has contained an '='. */
|
|
|
|
|
seen_nonequals |= ! word_has_equals;
|
|
|
|
|
if (word_has_equals && ! seen_nonequals)
|
|
|
|
|
/* An '=' in a word before the first
|
|
|
|
|
word without one is magical. */
|
|
|
|
|
goto slow;
|
|
|
|
|
word_has_equals = 0; /* Prepare for the next word. */
|
|
|
|
|
|
|
|
|
|
/* If this argument is the command name,
|
|
|
|
|
see if it is a built-in shell command.
|
|
|
|
|
If so, have the shell handle it. */
|
|
|
|
|
if (i == 1)
|
|
|
|
|
{
|
|
|
|
|
register int j;
|
|
|
|
|
for (j = 0; sh_cmds[j] != 0; ++j)
|
2004-03-22 23:11:48 +08:00
|
|
|
|
{
|
|
|
|
|
if (streq (sh_cmds[j], new_argv[0]))
|
|
|
|
|
goto slow;
|
2013-06-22 21:22:25 +08:00
|
|
|
|
#if defined(__EMX__) || defined(WINDOWS32)
|
2004-03-22 23:11:48 +08:00
|
|
|
|
/* Non-Unix shells are case insensitive. */
|
|
|
|
|
if (!unixy_shell
|
|
|
|
|
&& strcasecmp (sh_cmds[j], new_argv[0]) == 0)
|
|
|
|
|
goto slow;
|
2013-06-22 21:22:25 +08:00
|
|
|
|
#endif
|
2004-03-22 23:11:48 +08:00
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Ignore multiple whitespace chars. */
|
|
|
|
|
p = next_token (p) - 1;
|
|
|
|
|
break;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
2013-05-17 14:29:46 +08:00
|
|
|
|
default:
|
|
|
|
|
*ap++ = *p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
end_of_line:
|
|
|
|
|
|
|
|
|
|
if (instring)
|
|
|
|
|
/* Let the shell deal with an unterminated quote. */
|
|
|
|
|
goto slow;
|
|
|
|
|
|
|
|
|
|
/* Terminate the last argument and the argument list. */
|
|
|
|
|
|
|
|
|
|
*ap = '\0';
|
1997-03-13 05:17:08 +08:00
|
|
|
|
if (new_argv[i][0] != '\0' || last_argument_was_empty)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
++i;
|
|
|
|
|
new_argv[i] = 0;
|
|
|
|
|
|
1992-05-13 05:32:24 +08:00
|
|
|
|
if (i == 1)
|
|
|
|
|
{
|
|
|
|
|
register int j;
|
|
|
|
|
for (j = 0; sh_cmds[j] != 0; ++j)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (streq (sh_cmds[j], new_argv[0]))
|
|
|
|
|
goto slow;
|
1992-05-13 05:32:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
if (new_argv[0] == 0)
|
2005-09-26 13:16:31 +08:00
|
|
|
|
{
|
|
|
|
|
/* Line was empty. */
|
|
|
|
|
free (argstr);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (new_argv);
|
2005-09-26 13:16:31 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2004-09-21 12:00:31 +08:00
|
|
|
|
|
|
|
|
|
return new_argv;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
slow:;
|
|
|
|
|
/* We must use the shell. */
|
|
|
|
|
|
|
|
|
|
if (new_argv != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Free the old argument list we were working on. */
|
2005-09-26 13:16:31 +08:00
|
|
|
|
free (argstr);
|
2006-04-10 06:09:24 +08:00
|
|
|
|
free (new_argv);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
#ifdef __MSDOS__
|
2013-05-17 14:29:46 +08:00
|
|
|
|
execute_by_shell = 1; /* actually, call 'system' if shell isn't unixy */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef _AMIGA
|
|
|
|
|
{
|
|
|
|
|
char *ptr;
|
|
|
|
|
char *buffer;
|
|
|
|
|
char *dptr;
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
buffer = xmalloc (strlen (line)+1);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
|
|
|
|
|
ptr = line;
|
|
|
|
|
for (dptr=buffer; *ptr; )
|
|
|
|
|
{
|
|
|
|
|
if (*ptr == '\\' && ptr[1] == '\n')
|
2013-05-17 14:29:46 +08:00
|
|
|
|
ptr += 2;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
else if (*ptr == '@') /* Kludge: multiline commands */
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
ptr += 2;
|
|
|
|
|
*dptr++ = '\n';
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
*dptr++ = *ptr++;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
*dptr = 0;
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
new_argv = xmalloc (2 * sizeof (char *));
|
1997-04-07 15:21:16 +08:00
|
|
|
|
new_argv[0] = buffer;
|
|
|
|
|
new_argv[1] = 0;
|
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#else /* Not Amiga */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-23 05:51:45 +08:00
|
|
|
|
/*
|
|
|
|
|
* Not eating this whitespace caused things like
|
|
|
|
|
*
|
|
|
|
|
* sh -c "\n"
|
|
|
|
|
*
|
|
|
|
|
* which gave the shell fits. I think we have to eat
|
|
|
|
|
* whitespace here, but this code should be considered
|
|
|
|
|
* suspicious if things start failing....
|
|
|
|
|
*/
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1996-05-23 05:51:45 +08:00
|
|
|
|
/* Make sure not to bother processing an empty line. */
|
1999-10-15 15:00:58 +08:00
|
|
|
|
while (isspace ((unsigned char)*line))
|
1996-05-23 05:51:45 +08:00
|
|
|
|
++line;
|
|
|
|
|
if (*line == '\0')
|
|
|
|
|
return 0;
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
2010-07-06 14:37:42 +08:00
|
|
|
|
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
|
|
|
|
/* SHELL may be a multi-word command. Construct a command line
|
2010-07-06 14:37:42 +08:00
|
|
|
|
"$(SHELL) $(.SHELLFLAGS) LINE", with all special chars in LINE escaped.
|
1992-01-21 02:49:36 +08:00
|
|
|
|
Then recurse, expanding this command line to get the final
|
|
|
|
|
argument list. */
|
1995-11-22 08:06:28 +08:00
|
|
|
|
|
2013-09-12 16:07:52 +08:00
|
|
|
|
char *new_line;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
unsigned int shell_len = strlen (shell);
|
|
|
|
|
unsigned int line_len = strlen (line);
|
2011-05-07 16:29:13 +08:00
|
|
|
|
unsigned int sflags_len = shellflags ? strlen (shellflags) : 0;
|
2013-09-12 16:07:52 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1999-10-15 15:00:58 +08:00
|
|
|
|
char *command_ptr = NULL; /* used for batch_mode_shell mode */
|
2013-09-12 16:07:52 +08:00
|
|
|
|
#endif
|
1995-11-22 08:06:28 +08:00
|
|
|
|
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# ifdef __EMX__ /* is this necessary? */
|
2011-05-07 16:29:13 +08:00
|
|
|
|
if (!unixy_shell && shellflags)
|
2010-07-06 14:37:42 +08:00
|
|
|
|
shellflags[0] = '/'; /* "/c" */
|
2003-03-25 07:14:15 +08:00
|
|
|
|
# endif
|
|
|
|
|
|
2010-07-12 13:23:19 +08:00
|
|
|
|
/* In .ONESHELL mode we are allowed to throw the entire current
|
2013-05-17 14:29:46 +08:00
|
|
|
|
recipe string at a single shell and trust that the user
|
|
|
|
|
has configured the shell and shell flags, and formatted
|
|
|
|
|
the string, appropriately. */
|
2010-07-12 13:23:19 +08:00
|
|
|
|
if (one_shell)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* If the shell is Bourne compatible, we must remove and ignore
|
|
|
|
|
interior special chars [@+-] because they're meaningless to
|
|
|
|
|
the shell itself. If, however, we're in .ONESHELL mode and
|
|
|
|
|
have changed SHELL to something non-standard, we should
|
|
|
|
|
leave those alone because they could be part of the
|
|
|
|
|
script. In this case we must also leave in place
|
|
|
|
|
any leading [@+-] for the same reason. */
|
|
|
|
|
|
|
|
|
|
/* Remove and ignore interior prefix chars [@+-] because they're
|
|
|
|
|
meaningless given a single shell. */
|
2010-07-12 13:23:19 +08:00
|
|
|
|
#if defined __MSDOS__ || defined (__EMX__)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (unixy_shell) /* the test is complicated and we already did it */
|
2010-07-12 13:23:19 +08:00
|
|
|
|
#else
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (is_bourne_compatible_shell (shell)
|
2013-04-28 00:12:01 +08:00
|
|
|
|
#ifdef WINDOWS32
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* If we didn't find any sh.exe, don't behave is if we did! */
|
|
|
|
|
&& !no_default_sh_exe
|
2013-04-28 00:12:01 +08:00
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
)
|
2010-07-12 13:23:19 +08:00
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
const char *f = line;
|
|
|
|
|
char *t = line;
|
|
|
|
|
|
|
|
|
|
/* Copy the recipe, removing and ignoring interior prefix chars
|
|
|
|
|
[@+-]: they're meaningless in .ONESHELL mode. */
|
|
|
|
|
while (f[0] != '\0')
|
|
|
|
|
{
|
|
|
|
|
int esc = 0;
|
|
|
|
|
|
|
|
|
|
/* This is the start of a new recipe line.
|
|
|
|
|
Skip whitespace and prefix characters. */
|
|
|
|
|
while (isblank (*f) || *f == '-' || *f == '@' || *f == '+')
|
|
|
|
|
++f;
|
|
|
|
|
|
|
|
|
|
/* Copy until we get to the next logical recipe line. */
|
|
|
|
|
while (*f != '\0')
|
|
|
|
|
{
|
|
|
|
|
*(t++) = *(f++);
|
|
|
|
|
if (f[-1] == '\\')
|
|
|
|
|
esc = !esc;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* On unescaped newline, we're done with this line. */
|
|
|
|
|
if (f[-1] == '\n' && ! esc)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Something else: reset the escape sequence. */
|
|
|
|
|
esc = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*t = '\0';
|
2013-04-28 00:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
#ifdef WINDOWS32
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else /* non-Posix shell (cmd.exe etc.) */
|
|
|
|
|
{
|
2013-04-28 00:12:01 +08:00
|
|
|
|
const char *f = line;
|
|
|
|
|
char *t = line;
|
2013-05-17 14:29:46 +08:00
|
|
|
|
char *tstart = t;
|
|
|
|
|
int temp_fd;
|
|
|
|
|
FILE* batch = NULL;
|
|
|
|
|
int id = GetCurrentProcessId ();
|
|
|
|
|
PATH_VAR(fbuf);
|
|
|
|
|
|
|
|
|
|
/* Generate a file name for the temporary batch file. */
|
|
|
|
|
sprintf (fbuf, "make%d", id);
|
|
|
|
|
*batch_filename = create_batch_file (fbuf, 0, &temp_fd);
|
|
|
|
|
DB (DB_JOBS, (_("Creating temporary batch file %s\n"),
|
|
|
|
|
*batch_filename));
|
|
|
|
|
|
|
|
|
|
/* Create a FILE object for the batch file, and write to it the
|
|
|
|
|
commands to be executed. Put the batch file in TEXT mode. */
|
|
|
|
|
_setmode (temp_fd, _O_TEXT);
|
|
|
|
|
batch = _fdopen (temp_fd, "wt");
|
|
|
|
|
fputs ("@echo off\n", batch);
|
|
|
|
|
DB (DB_JOBS, (_("Batch file contents:\n\t@echo off\n")));
|
2013-04-28 00:12:01 +08:00
|
|
|
|
|
|
|
|
|
/* Copy the recipe, removing and ignoring interior prefix chars
|
|
|
|
|
[@+-]: they're meaningless in .ONESHELL mode. */
|
|
|
|
|
while (*f != '\0')
|
|
|
|
|
{
|
|
|
|
|
/* This is the start of a new recipe line.
|
|
|
|
|
Skip whitespace and prefix characters. */
|
|
|
|
|
while (isblank (*f) || *f == '-' || *f == '@' || *f == '+')
|
|
|
|
|
++f;
|
|
|
|
|
|
|
|
|
|
/* Copy until we get to the next logical recipe line. */
|
|
|
|
|
while (*f != '\0')
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Remove the escaped newlines in the command, and
|
|
|
|
|
the whitespace that follows them. Windows
|
|
|
|
|
shells cannot handle escaped newlines. */
|
|
|
|
|
if (*f == '\\' && f[1] == '\n')
|
|
|
|
|
{
|
|
|
|
|
f += 2;
|
|
|
|
|
while (isblank (*f))
|
|
|
|
|
++f;
|
|
|
|
|
}
|
2013-04-28 00:12:01 +08:00
|
|
|
|
*(t++) = *(f++);
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* On an unescaped newline, we're done with this
|
|
|
|
|
line. */
|
|
|
|
|
if (f[-1] == '\n')
|
|
|
|
|
break;
|
2013-04-28 00:12:01 +08:00
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* Write another line into the batch file. */
|
|
|
|
|
if (t > tstart)
|
|
|
|
|
{
|
|
|
|
|
int c = *t;
|
|
|
|
|
*t = '\0';
|
|
|
|
|
fputs (tstart, batch);
|
|
|
|
|
DB (DB_JOBS, ("\t%s", tstart));
|
|
|
|
|
tstart = t;
|
|
|
|
|
*t = c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DB (DB_JOBS, ("\n"));
|
|
|
|
|
fclose (batch);
|
|
|
|
|
|
|
|
|
|
/* Create an argv list for the shell command line that
|
|
|
|
|
will run the batch file. */
|
|
|
|
|
new_argv = xmalloc (2 * sizeof (char *));
|
|
|
|
|
new_argv[0] = xstrdup (*batch_filename);
|
|
|
|
|
new_argv[1] = NULL;
|
|
|
|
|
return new_argv;
|
|
|
|
|
}
|
2013-04-30 00:17:07 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
2013-04-28 05:28:05 +08:00
|
|
|
|
/* Create an argv list for the shell command line. */
|
|
|
|
|
{
|
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
|
|
new_argv = xmalloc ((4 + sflags_len/2) * sizeof (char *));
|
|
|
|
|
new_argv[n++] = xstrdup (shell);
|
|
|
|
|
|
|
|
|
|
/* Chop up the shellflags (if any) and assign them. */
|
|
|
|
|
if (! shellflags)
|
|
|
|
|
new_argv[n++] = xstrdup ("");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const char *s = shellflags;
|
|
|
|
|
char *t;
|
|
|
|
|
unsigned int len;
|
|
|
|
|
while ((t = find_next_token (&s, &len)) != 0)
|
|
|
|
|
new_argv[n++] = xstrndup (t, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set the command to invoke. */
|
|
|
|
|
new_argv[n++] = line;
|
|
|
|
|
new_argv[n++] = NULL;
|
|
|
|
|
}
|
|
|
|
|
return new_argv;
|
2010-07-12 13:23:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 07:25:07 +08:00
|
|
|
|
new_line = xmalloc ((shell_len*2) + 1 + sflags_len + 1
|
|
|
|
|
+ (line_len*2) + 1);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
ap = new_line;
|
2011-05-07 16:29:13 +08:00
|
|
|
|
/* Copy SHELL, escaping any characters special to the shell. If
|
|
|
|
|
we don't escape them, construct_command_argv_internal will
|
|
|
|
|
recursively call itself ad nauseam, or until stack overflow,
|
|
|
|
|
whichever happens first. */
|
|
|
|
|
for (p = shell; *p != '\0'; ++p)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (strchr (sh_chars, *p) != 0)
|
|
|
|
|
*(ap++) = '\\';
|
|
|
|
|
*(ap++) = *p;
|
2011-05-07 16:29:13 +08:00
|
|
|
|
}
|
2010-07-06 14:37:42 +08:00
|
|
|
|
*(ap++) = ' ';
|
2011-05-07 16:29:13 +08:00
|
|
|
|
if (shellflags)
|
|
|
|
|
memcpy (ap, shellflags, sflags_len);
|
2010-07-06 14:37:42 +08:00
|
|
|
|
ap += sflags_len;
|
|
|
|
|
*(ap++) = ' ';
|
2013-09-12 16:07:52 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1999-10-15 15:00:58 +08:00
|
|
|
|
command_ptr = ap;
|
2013-09-12 16:07:52 +08:00
|
|
|
|
#endif
|
1992-01-21 02:49:36 +08:00
|
|
|
|
for (p = line; *p != '\0'; ++p)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (restp != NULL && *p == '\n')
|
|
|
|
|
{
|
|
|
|
|
*restp = p;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (*p == '\\' && p[1] == '\n')
|
|
|
|
|
{
|
|
|
|
|
/* POSIX says we keep the backslash-newline. If we don't have a
|
2007-11-05 05:54:00 +08:00
|
|
|
|
POSIX shell on DOS/Windows/OS2, mimic the pre-POSIX behavior
|
2005-08-25 12:40:10 +08:00
|
|
|
|
and remove the backslash/newline. */
|
|
|
|
|
#if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32)
|
|
|
|
|
# define PRESERVE_BSNL unixy_shell
|
|
|
|
|
#else
|
|
|
|
|
# define PRESERVE_BSNL 1
|
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (PRESERVE_BSNL)
|
|
|
|
|
{
|
|
|
|
|
*(ap++) = '\\';
|
|
|
|
|
/* Only non-batch execution needs another backslash,
|
|
|
|
|
because it will be passed through a recursive
|
|
|
|
|
invocation of this function. */
|
|
|
|
|
if (!batch_mode_shell)
|
|
|
|
|
*(ap++) = '\\';
|
|
|
|
|
*(ap++) = '\n';
|
|
|
|
|
}
|
|
|
|
|
++p;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
/* DOS shells don't know about backslash-escaping. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (unixy_shell && !batch_mode_shell &&
|
1997-04-07 15:21:16 +08:00
|
|
|
|
(*p == '\\' || *p == '\'' || *p == '"'
|
1999-10-15 15:00:58 +08:00
|
|
|
|
|| isspace ((unsigned char)*p)
|
|
|
|
|
|| strchr (sh_chars, *p) != 0))
|
2013-05-17 14:29:46 +08:00
|
|
|
|
*ap++ = '\\';
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef __MSDOS__
|
1999-07-21 13:53:23 +08:00
|
|
|
|
else if (unixy_shell && strneq (p, "...", 3))
|
1997-04-07 15:21:16 +08:00
|
|
|
|
{
|
2012-03-04 08:24:20 +08:00
|
|
|
|
/* The case of '...' wildcard again. */
|
1997-04-07 15:21:16 +08:00
|
|
|
|
strcpy (ap, "\\.\\.\\");
|
|
|
|
|
ap += 5;
|
|
|
|
|
p += 2;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2013-05-17 14:29:46 +08:00
|
|
|
|
*ap++ = *p;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
2010-07-06 14:37:42 +08:00
|
|
|
|
if (ap == new_line + shell_len + sflags_len + 2)
|
2012-09-10 07:25:07 +08:00
|
|
|
|
{
|
|
|
|
|
/* Line was empty. */
|
|
|
|
|
free (new_line);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1992-01-21 02:49:36 +08:00
|
|
|
|
*ap = '\0';
|
1995-11-22 08:06:28 +08:00
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1998-10-03 13:39:55 +08:00
|
|
|
|
/* Some shells do not work well when invoked as 'sh -c xxx' to run a
|
|
|
|
|
command line (e.g. Cygnus GNUWIN32 sh.exe on WIN32 systems). In these
|
|
|
|
|
cases, run commands via a script file. */
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (just_print_flag && !(flags & COMMANDS_RECURSE))
|
|
|
|
|
{
|
|
|
|
|
/* Need to allocate new_argv, although it's unused, because
|
|
|
|
|
start_job_command will want to free it and its 0'th element. */
|
|
|
|
|
new_argv = xmalloc (2 * sizeof (char *));
|
|
|
|
|
new_argv[0] = xstrdup ("");
|
1998-07-31 04:54:47 +08:00
|
|
|
|
new_argv[1] = NULL;
|
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
else if ((no_default_sh_exe || batch_mode_shell) && batch_filename)
|
|
|
|
|
{
|
|
|
|
|
int temp_fd;
|
|
|
|
|
FILE* batch = NULL;
|
|
|
|
|
int id = GetCurrentProcessId ();
|
|
|
|
|
PATH_VAR (fbuf);
|
|
|
|
|
|
|
|
|
|
/* create a file name */
|
|
|
|
|
sprintf (fbuf, "make%d", id);
|
|
|
|
|
*batch_filename = create_batch_file (fbuf, unixy_shell, &temp_fd);
|
|
|
|
|
|
|
|
|
|
DB (DB_JOBS, (_("Creating temporary batch file %s\n"),
|
|
|
|
|
*batch_filename));
|
|
|
|
|
|
|
|
|
|
/* Create a FILE object for the batch file, and write to it the
|
|
|
|
|
commands to be executed. Put the batch file in TEXT mode. */
|
|
|
|
|
_setmode (temp_fd, _O_TEXT);
|
|
|
|
|
batch = _fdopen (temp_fd, "wt");
|
|
|
|
|
if (!unixy_shell)
|
|
|
|
|
fputs ("@echo off\n", batch);
|
|
|
|
|
fputs (command_ptr, batch);
|
|
|
|
|
fputc ('\n', batch);
|
|
|
|
|
fclose (batch);
|
|
|
|
|
DB (DB_JOBS, (_("Batch file contents:%s\n\t%s\n"),
|
|
|
|
|
!unixy_shell ? "\n\t@echo off" : "", command_ptr));
|
|
|
|
|
|
|
|
|
|
/* create argv */
|
|
|
|
|
new_argv = xmalloc (3 * sizeof (char *));
|
|
|
|
|
if (unixy_shell)
|
|
|
|
|
{
|
|
|
|
|
new_argv[0] = xstrdup (shell);
|
|
|
|
|
new_argv[1] = *batch_filename; /* only argv[0] gets freed later */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
new_argv[0] = xstrdup (*batch_filename);
|
|
|
|
|
new_argv[1] = NULL;
|
|
|
|
|
}
|
|
|
|
|
new_argv[2] = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#endif /* WINDOWS32 */
|
2010-07-06 14:37:42 +08:00
|
|
|
|
|
1997-04-07 15:21:16 +08:00
|
|
|
|
if (unixy_shell)
|
2010-08-29 12:50:26 +08:00
|
|
|
|
new_argv = construct_command_argv_internal (new_line, 0, 0, 0, 0,
|
|
|
|
|
flags, 0);
|
2010-07-06 14:37:42 +08:00
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
#ifdef __EMX__
|
2003-03-25 07:14:15 +08:00
|
|
|
|
else if (!unixy_shell)
|
|
|
|
|
{
|
2013-05-17 14:29:46 +08:00
|
|
|
|
/* new_line is local, must not be freed therefore
|
2004-03-22 23:11:48 +08:00
|
|
|
|
We use line here instead of new_line because we run the shell
|
|
|
|
|
manually. */
|
|
|
|
|
size_t line_len = strlen (line);
|
2004-05-17 03:16:52 +08:00
|
|
|
|
char *p = new_line;
|
|
|
|
|
char *q = new_line;
|
2004-03-22 23:11:48 +08:00
|
|
|
|
memcpy (new_line, line, line_len + 1);
|
2009-09-29 07:08:49 +08:00
|
|
|
|
/* Replace all backslash-newline combination and also following tabs.
|
|
|
|
|
Important: stop at the first '\n' because that's what the loop above
|
|
|
|
|
did. The next line starting at restp[0] will be executed during the
|
|
|
|
|
next call of this function. */
|
|
|
|
|
while (*q != '\0' && *q != '\n')
|
2004-05-17 03:16:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (q[0] == '\\' && q[1] == '\n')
|
2007-11-05 05:54:00 +08:00
|
|
|
|
q += 2; /* remove '\\' and '\n' */
|
2004-05-17 03:16:52 +08:00
|
|
|
|
else
|
|
|
|
|
*p++ = *q++;
|
|
|
|
|
}
|
|
|
|
|
*p = '\0';
|
2004-03-22 23:11:48 +08:00
|
|
|
|
|
|
|
|
|
# ifndef NO_CMD_DEFAULT
|
|
|
|
|
if (strnicmp (new_line, "echo", 4) == 0
|
|
|
|
|
&& (new_line[4] == ' ' || new_line[4] == '\t'))
|
|
|
|
|
{
|
|
|
|
|
/* the builtin echo command: handle it separately */
|
|
|
|
|
size_t echo_len = line_len - 5;
|
|
|
|
|
char *echo_line = new_line + 5;
|
|
|
|
|
|
|
|
|
|
/* special case: echo 'x="y"'
|
|
|
|
|
cmd works this way: a string is printed as is, i.e., no quotes
|
|
|
|
|
are removed. But autoconf uses a command like echo 'x="y"' to
|
|
|
|
|
determine whether make works. autoconf expects the output x="y"
|
|
|
|
|
so we will do exactly that.
|
|
|
|
|
Note: if we do not allow cmd to be the default shell
|
|
|
|
|
we do not need this kind of voodoo */
|
|
|
|
|
if (echo_line[0] == '\''
|
|
|
|
|
&& echo_line[echo_len - 1] == '\''
|
|
|
|
|
&& strncmp (echo_line + 1, "ac_maketemp=",
|
|
|
|
|
strlen ("ac_maketemp=")) == 0)
|
|
|
|
|
{
|
|
|
|
|
/* remove the enclosing quotes */
|
|
|
|
|
memmove (echo_line, echo_line + 1, echo_len - 2);
|
|
|
|
|
echo_line[echo_len - 2] = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# endif
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
2004-03-22 23:11:48 +08:00
|
|
|
|
{
|
|
|
|
|
/* Let the shell decide what to do. Put the command line into the
|
|
|
|
|
2nd command line argument and hope for the best ;-) */
|
|
|
|
|
size_t sh_len = strlen (shell);
|
|
|
|
|
|
|
|
|
|
/* exactly 3 arguments + NULL */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
new_argv = xmalloc (4 * sizeof (char *));
|
2004-03-22 23:11:48 +08:00
|
|
|
|
/* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times
|
|
|
|
|
the trailing '\0' */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
new_argv[0] = xmalloc (sh_len + line_len + 5);
|
2004-03-22 23:11:48 +08:00
|
|
|
|
memcpy (new_argv[0], shell, sh_len + 1);
|
|
|
|
|
new_argv[1] = new_argv[0] + sh_len + 1;
|
|
|
|
|
memcpy (new_argv[1], "/c", 3);
|
|
|
|
|
new_argv[2] = new_argv[1] + 3;
|
2004-05-17 03:16:52 +08:00
|
|
|
|
memcpy (new_argv[2], new_line, line_len + 1);
|
2004-03-22 23:11:48 +08:00
|
|
|
|
new_argv[3] = NULL;
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
}
|
|
|
|
|
#elif defined(__MSDOS__)
|
1997-04-07 15:21:16 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2003-03-25 07:14:15 +08:00
|
|
|
|
/* With MSDOS shells, we must construct the command line here
|
|
|
|
|
instead of recursively calling ourselves, because we
|
|
|
|
|
cannot backslash-escape the special characters (see above). */
|
2006-04-10 06:09:24 +08:00
|
|
|
|
new_argv = xmalloc (sizeof (char *));
|
2010-07-06 14:37:42 +08:00
|
|
|
|
line_len = strlen (new_line) - shell_len - sflags_len - 2;
|
2003-03-25 07:14:15 +08:00
|
|
|
|
new_argv[0] = xmalloc (line_len + 1);
|
|
|
|
|
strncpy (new_argv[0],
|
2010-07-06 14:37:42 +08:00
|
|
|
|
new_line + shell_len + sflags_len + 2, line_len);
|
2003-03-25 07:14:15 +08:00
|
|
|
|
new_argv[0][line_len] = '\0';
|
1997-04-07 15:21:16 +08:00
|
|
|
|
}
|
1998-07-31 04:54:47 +08:00
|
|
|
|
#else
|
|
|
|
|
else
|
1999-07-28 14:23:37 +08:00
|
|
|
|
fatal (NILF, _("%s (line %d) Bad shell context (!unixy && !batch_mode_shell)\n"),
|
1998-07-31 04:54:47 +08:00
|
|
|
|
__FILE__, __LINE__);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#endif
|
2012-09-10 07:25:07 +08:00
|
|
|
|
|
|
|
|
|
free (new_line);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
}
|
2013-05-17 14:29:46 +08:00
|
|
|
|
#endif /* ! AMIGA */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
return new_argv;
|
|
|
|
|
}
|
2000-01-22 13:43:03 +08:00
|
|
|
|
#endif /* !VMS */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
1995-01-15 21:43:48 +08:00
|
|
|
|
/* Figure out the argument list necessary to run LINE as a command. Try to
|
|
|
|
|
avoid using a shell. This routine handles only ' quoting, and " quoting
|
2012-03-04 08:24:20 +08:00
|
|
|
|
when no backslash, $ or ' characters are seen in the quotes. Starting
|
1995-01-15 21:43:48 +08:00
|
|
|
|
quotes may be escaped with a backslash. If any of the characters in
|
|
|
|
|
sh_chars[] is seen, or any of the builtin commands listed in sh_cmds[]
|
|
|
|
|
is the first word of a line, the shell is used.
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
If RESTP is not NULL, *RESTP is set to point to the first newline in LINE.
|
|
|
|
|
If *RESTP is NULL, newlines will be ignored.
|
|
|
|
|
|
|
|
|
|
FILE is the target whose commands these are. It is used for
|
|
|
|
|
variable expansion for $(SHELL) and $(IFS). */
|
|
|
|
|
|
|
|
|
|
char **
|
2002-10-15 05:54:04 +08:00
|
|
|
|
construct_command_argv (char *line, char **restp, struct file *file,
|
2011-11-14 08:58:49 +08:00
|
|
|
|
int cmd_flags, char **batch_filename)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
2010-07-06 14:37:42 +08:00
|
|
|
|
char *shell, *ifs, *shellflags;
|
1992-01-21 02:49:36 +08:00
|
|
|
|
char **argv;
|
|
|
|
|
|
2000-01-22 13:43:03 +08:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
char *cptr;
|
|
|
|
|
int argc;
|
|
|
|
|
|
|
|
|
|
argc = 0;
|
|
|
|
|
cptr = line;
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
while ((*cptr != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
&& (isspace ((unsigned char)*cptr)))
|
|
|
|
|
cptr++;
|
2000-01-22 13:43:03 +08:00
|
|
|
|
if (*cptr == 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
break;
|
2000-01-22 13:43:03 +08:00
|
|
|
|
while ((*cptr != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
&& (!isspace ((unsigned char)*cptr)))
|
|
|
|
|
cptr++;
|
2000-01-22 13:43:03 +08:00
|
|
|
|
argc++;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-10 06:09:24 +08:00
|
|
|
|
argv = xmalloc (argc * sizeof (char *));
|
2000-01-22 13:43:03 +08:00
|
|
|
|
if (argv == 0)
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
cptr = line;
|
|
|
|
|
argc = 0;
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
while ((*cptr != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
&& (isspace ((unsigned char)*cptr)))
|
|
|
|
|
cptr++;
|
2000-01-22 13:43:03 +08:00
|
|
|
|
if (*cptr == 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
break;
|
2000-02-05 15:50:47 +08:00
|
|
|
|
DB (DB_JOBS, ("argv[%d] = [%s]\n", argc, cptr));
|
2000-01-22 13:43:03 +08:00
|
|
|
|
argv[argc++] = cptr;
|
|
|
|
|
while ((*cptr != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
&& (!isspace ((unsigned char)*cptr)))
|
|
|
|
|
cptr++;
|
2000-01-22 13:43:03 +08:00
|
|
|
|
if (*cptr != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
*cptr++ = 0;
|
2000-01-22 13:43:03 +08:00
|
|
|
|
}
|
|
|
|
|
#else
|
1993-06-26 04:03:56 +08:00
|
|
|
|
{
|
|
|
|
|
/* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
|
|
|
|
|
int save = warn_undefined_variables_flag;
|
|
|
|
|
warn_undefined_variables_flag = 0;
|
|
|
|
|
|
|
|
|
|
shell = allocated_variable_expand_for_file ("$(SHELL)", file);
|
1997-04-07 15:21:16 +08:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-23 05:51:45 +08:00
|
|
|
|
/*
|
|
|
|
|
* Convert to forward slashes so that construct_command_argv_internal()
|
|
|
|
|
* is not confused.
|
|
|
|
|
*/
|
2013-05-17 14:29:46 +08:00
|
|
|
|
if (shell)
|
|
|
|
|
{
|
|
|
|
|
char *p = w32ify (shell, 0);
|
|
|
|
|
strcpy (shell, p);
|
|
|
|
|
}
|
1996-05-23 05:51:45 +08:00
|
|
|
|
#endif
|
2003-03-25 07:14:15 +08:00
|
|
|
|
#ifdef __EMX__
|
|
|
|
|
{
|
|
|
|
|
static const char *unixroot = NULL;
|
|
|
|
|
static const char *last_shell = "";
|
|
|
|
|
static int init = 0;
|
|
|
|
|
if (init == 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
unixroot = getenv ("UNIXROOT");
|
|
|
|
|
/* unixroot must be NULL or not empty */
|
|
|
|
|
if (unixroot && unixroot[0] == '\0') unixroot = NULL;
|
|
|
|
|
init = 1;
|
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
|
|
|
|
/* if we have an unixroot drive and if shell is not default_shell
|
|
|
|
|
(which means it's either cmd.exe or the test has already been
|
|
|
|
|
performed) and if shell is an absolute path without drive letter,
|
|
|
|
|
try whether it exists e.g.: if "/bin/sh" does not exist use
|
|
|
|
|
"$UNIXROOT/bin/sh" instead. */
|
|
|
|
|
if (unixroot && shell && strcmp (shell, last_shell) != 0
|
2013-05-17 14:29:46 +08:00
|
|
|
|
&& (shell[0] == '/' || shell[0] == '\\'))
|
|
|
|
|
{
|
|
|
|
|
/* trying a new shell, check whether it exists */
|
|
|
|
|
size_t size = strlen (shell);
|
|
|
|
|
char *buf = xmalloc (size + 7);
|
|
|
|
|
memcpy (buf, shell, size);
|
|
|
|
|
memcpy (buf + size, ".exe", 5); /* including the trailing '\0' */
|
2003-03-25 07:14:15 +08:00
|
|
|
|
if (access (shell, F_OK) != 0 && access (buf, F_OK) != 0)
|
2013-05-17 14:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
/* try the same for the unixroot drive */
|
|
|
|
|
memmove (buf + 2, buf, size + 5);
|
|
|
|
|
buf[0] = unixroot[0];
|
|
|
|
|
buf[1] = unixroot[1];
|
|
|
|
|
if (access (buf, F_OK) == 0)
|
|
|
|
|
/* we have found a shell! */
|
|
|
|
|
/* free(shell); */
|
|
|
|
|
shell = buf;
|
|
|
|
|
else
|
|
|
|
|
free (buf);
|
|
|
|
|
}
|
|
|
|
|
else
|
2003-03-25 07:14:15 +08:00
|
|
|
|
free (buf);
|
2013-05-17 14:29:46 +08:00
|
|
|
|
}
|
2003-03-25 07:14:15 +08:00
|
|
|
|
}
|
2003-07-19 10:46:25 +08:00
|
|
|
|
#endif /* __EMX__ */
|
2003-03-25 07:14:15 +08:00
|
|
|
|
|
2010-07-06 14:37:42 +08:00
|
|
|
|
shellflags = allocated_variable_expand_for_file ("$(.SHELLFLAGS)", file);
|
1993-06-26 04:03:56 +08:00
|
|
|
|
ifs = allocated_variable_expand_for_file ("$(IFS)", file);
|
|
|
|
|
|
|
|
|
|
warn_undefined_variables_flag = save;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-06 14:37:42 +08:00
|
|
|
|
argv = construct_command_argv_internal (line, restp, shell, shellflags, ifs,
|
2011-11-14 08:58:49 +08:00
|
|
|
|
cmd_flags, batch_filename);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
|
|
|
|
|
free (shell);
|
2010-07-06 14:37:42 +08:00
|
|
|
|
free (shellflags);
|
1992-01-21 02:49:36 +08:00
|
|
|
|
free (ifs);
|
2000-01-22 13:43:03 +08:00
|
|
|
|
#endif /* !VMS */
|
1992-01-21 02:49:36 +08:00
|
|
|
|
return argv;
|
|
|
|
|
}
|
|
|
|
|
|
Thu May 9 13:54:49 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* GNUmakefile (globfiles): Add AmigaDOS support files.
(distfiles): Add $(amigafiles).
(amigafiles): New variable.
Thu Nov 7 10:18:16 1995 Aaron Digulla <digulla@fh-konstanz.de>
* Added Amiga support in commands.c, dir.c, function.c,
job.c, main.c, make.h, read.c, remake.c
* commands.c: Amiga has neither SIGHUP nor SIGQUIT
* dir.c: Amiga has filenames with Upper- and Lowercase,
but "FileName" is the same as "filename". Added strieq()
which is use to compare filenames. This is like streq()
on all other systems. Also there is no such thing as
"." under AmigaDOS.
* function.c: On Amiga, the environment is not passed as envp,
there are no pipes and Amiga can't fork. Use my own function
to create a new child.
* job.c: default_shell is "" (The system automatically chooses
a shell for me). Have to use the same workaround as MSDOS for
running batch commands. Added HAVE_SYS_PARAM_H. NOFILE isn't
known on Amiga. Cloned code to run children from MSDOS. Own
version of sh_chars[] and sh_cmds[]. No dup2() or dup() on Amiga.
* main.c: Force stack to 20000 bytes. Read environment from ENV:
device. On Amiga, exec_command() does return, so I exit()
afterwards.
* make.h: Added strieq() to compare filenames.
* read.c: Amiga needs special extension to have passwd. Only
one include-dir. "Makefile" and "makefile" are the same.
Added "SMakefile". Added special code to handle device names (xxx:)
and "./" in rules.
* remake.c: Only one lib-dir. Amiga link-libs are named "%s.lib"
instead of "lib%s.a".
* main.c, rule.c, variable.c: Avoid floats at all costs.
* vpath.c: Get rid of as many alloca()s as possible.
1996-05-10 02:02:06 +08:00
|
|
|
|
#if !defined(HAVE_DUP2) && !defined(_AMIGA)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
int
|
2002-10-15 05:54:04 +08:00
|
|
|
|
dup2 (int old, int new)
|
1992-01-21 02:49:36 +08:00
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
(void) close (new);
|
|
|
|
|
fd = dup (old);
|
|
|
|
|
if (fd != new)
|
|
|
|
|
{
|
|
|
|
|
(void) close (fd);
|
|
|
|
|
errno = EMFILE;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
|
}
|
2010-07-12 13:23:19 +08:00
|
|
|
|
#endif /* !HAVE_DUP2 && !_AMIGA */
|
2005-05-03 21:57:20 +08:00
|
|
|
|
|
|
|
|
|
/* On VMS systems, include special VMS functions. */
|
|
|
|
|
|
|
|
|
|
#ifdef VMS
|
|
|
|
|
#include "vmsjobs.c"
|
|
|
|
|
#endif
|