/* Job execution and handling for GNU Make.
Copyright (C) 1988-2020 Free Software Foundation, Inc.
This file is part of GNU Make.
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
Foundation; either version 3 of the License, or (at your option) any later
version.
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.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
#include "makeint.h"
#include <assert.h>
#include <string.h>
#include "job.h"
#include "debug.h"
#include "filedef.h"
#include "commands.h"
#include "variable.h"
#include "os.h"
/* Default shell to use. */
#ifdef WINDOWS32
# ifdef HAVE_STRINGS_H
# include <strings.h> /* for strcasecmp, strncasecmp */
# endif
# include <windows.h>
const char *default_shell = "sh.exe";
int no_default_sh_exe = 1;
int batch_mode_shell = 1;
HANDLE main_thread;
#elif defined (_AMIGA)
const char *default_shell = "";
extern int MyExecute (char **);
int batch_mode_shell = 0;
#elif defined (__MSDOS__)
/* 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). */
const char *default_shell = "command.com";
int batch_mode_shell = 0;
#elif defined (__EMX__)
const char *default_shell = "/bin/sh";
int batch_mode_shell = 0;
#elif defined (VMS)
# include <descrip.h>
# include <stsdef.h>
const char *default_shell = "";
int batch_mode_shell = 0;
#define strsignal vms_strsignal
char * vms_strsignal (int status);
#ifndef C_FACILITY_NO
# define C_FACILITY_NO 0x350000
#endif
#ifndef VMS_POSIX_EXIT_MASK
# define VMS_POSIX_EXIT_MASK (C_FACILITY_NO | 0xA000)
#endif
#else
const char *default_shell = "/bin/sh";
int batch_mode_shell = 0;
#endif
#ifdef __MSDOS__
# include <process.h>
static int execute_by_shell;
static int dos_pid = 123;
int dos_status;
int dos_command_running;
#endif /* __MSDOS__ */
#ifdef _AMIGA
# include <proto/dos.h>
static int amiga_pid = 123;
static int amiga_status;
static char amiga_bname[32];
static int amiga_batch_file;
#endif /* Amiga. */
#ifdef VMS
# ifndef __GNUC__
# include <processes.h>
# endif
# include <starlet.h>
# include <lib$routines.h>
static void vmsWaitForChildren (int *);
#endif
#ifdef WINDOWS32
# include <windows.h>
# include <io.h>
# include <process.h>
# include "sub_proc.h"
# include "w32err.h"
# include "pathstuff.h"
# define WAIT_NOHANG 1
#endif /* WINDOWS32 */
#ifdef __EMX__
# include <process.h>
#endif
#if defined (HAVE_SYS_WAIT_H) || defined (HAVE_UNION_WAIT)
# include <sys/wait.h>
#endif
#ifdef HAVE_WAITPID
# define WAIT_NOHANG(status) waitpid (-1, (status), WNOHANG)
#else /* Don't have waitpid. */
# ifdef HAVE_WAIT3
# ifndef wait3
extern int wait3 ();
# endif
# define WAIT_NOHANG(status) wait3 ((status), WNOHANG, (struct rusage *) 0)
# endif /* Have wait3. */
#endif /* Have waitpid. */
#ifdef USE_POSIX_SPAWN
# include <spawn.h>
# include "findprog.h"
#endif
#if !defined (wait) && !defined (POSIX)
int wait ();
#endif
#ifndef HAVE_UNION_WAIT
# 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
#else /* Have 'union wait'. */
# 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
#endif /* Don't have 'union wait'. */
#if !defined(HAVE_UNISTD_H) && !defined(WINDOWS32)
int dup2 ();
int execve ();
void _exit ();
# ifndef VMS
int geteuid ();
int getegid ();
int setgid ();
int getgid ();
# endif
#endif
/* 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];
#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. */
sprintf (pidstring, "%Id", pid);
#else
sprintf (pidstring, "%lu", (unsigned long) pid);
#endif
return pidstring;
}
#ifndef HAVE_GETLOADAVG
int getloadavg (double loadavg[], int nelem);
#endif
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 *);
/* Chain of all live (or recently deceased) children. */
struct child *children = 0;
/* Number of children currently running. */
unsigned int job_slots_used = 0;
/* Nonzero if the 'good' standard input is in use. */
static int good_stdin_used = 0;
/* Chain of children waiting to run until the load average goes down. */
static struct child *waiting_jobs = 0;
/* Non-zero if we use a *real* shell (always so on Unix). */
int unixy_shell = 1;
/* Number of jobs started in the current second. */
unsigned long job_counter = 0;
/* Number of jobserver tokens this instance is currently using. */
unsigned int jobserver_tokens = 0;
#ifdef WINDOWS32
/*
* The macro which references this function is defined in makeint.h.
*/
int
w32_kill (pid_t pid, int sig)
{
return ((process_kill ((HANDLE)pid, sig) == TRUE) ? 0 : -1);
}
/* 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. */
static char *
create_batch_file (char const *base, int unixy, int *fd)
{
const char *const ext = unixy ? "sh" : "bat";
const char *error_string = NULL;
char temp_path[MAXPATHLEN]; /* need to know its length */
unsigned path_size = GetTempPath (sizeof temp_path, temp_path);
int path_is_dot = 0;
/* 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. */
static unsigned uniq = 0;
static int second_loop = 0;
const size_t sizemax = strlen (base) + strlen (ext) + 10;
if (path_size == 0)
{
path_size = GetCurrentDirectory (sizeof temp_path, temp_path);
path_is_dot = 1;
}
++uniq;
if (uniq >= 0x10000 && !second_loop)
{
/* If we already had 64K batch files in this
process, make a second loop through the numbers,
looking for free slots, i.e. files that were
deleted in the meantime. */
second_loop = 1;
uniq = 1;
}
while (path_size > 0 &&
path_size + sizemax < sizeof temp_path &&
!(uniq >= 0x10000 && second_loop))
{
unsigned size = sprintf (temp_path + path_size,
"%s%s-%x.%s",
temp_path[path_size - 1] == '\\' ? "" : "\\",
base, uniq, ext);
HANDLE h =
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
make-4.3.tar.gz (457个子文件)
make.1 11KB
ABOUT-NLS 92KB
abspath 2KB
configure.ac 18KB
addprefix 1KB
addsuffix 737B
Makefile.am 44KB
Makefile.am 6KB
Makefile.am 900B
config.ami 10KB
README.Amiga 3KB
andor 1KB
archives 7KB
AUTHORS 3KB
automatic 3KB
basename 1KB
build_w32.bat 11KB
builddos.bat 5KB
run_make_tests.bat 813B
bs-nl 4KB
job.c 111KB
main.c 106KB
read.c 102KB
function.c 69KB
remake.c 55KB
variable.c 55KB
sub_proc.c 51KB
vmsjobs.c 42KB
dir.c 35KB
glob.c 35KB
implicit.c 35KB
file.c 33KB
getopt.c 29KB
arscan.c 27KB
getloadavg.c 26KB
default.c 21KB
vpath.c 19KB
commands.c 18KB
fcntl.c 18KB
vmsify.c 18KB
misc.c 18KB
expand.c 18KB
output.c 17KB
rule.c 16KB
alloca.c 14KB
vms_progname.c 14KB
posixfcn.c 14KB
vms_export_symbol.c 14KB
hash.c 13KB
fnmatch.c 13KB
posixos.c 12KB
error.c 10KB
strcache.c 9KB
strerror-override.c 9KB
remote-cstms.c 8KB
ar.c 8KB
pathstuff.c 8KB
findprog-in.c 8KB
getprogname.c 8KB
load.c 7KB
signame.c 7KB
vmsfunctions.c 6KB
w32os.c 6KB
dirent.c 5KB
dup2.c 5KB
getopt1.c 4KB
guile.c 4KB
msvc-inval.c 4KB
fd-hook.c 4KB
getdtablesize.c 3KB
xmalloc.c 3KB
dirname-lgpl.c 3KB
w32err.c 3KB
vms_exit.c 3KB
amiga.c 3KB
remote-stub.c 3KB
concat-filename.c 2KB
misc.c 2KB
basename-lgpl.c 2KB
strerror.c 2KB
loadapi.c 2KB
stripslash.c 2KB
close.c 1KB
malloc.c 1KB
xconcat-filename.c 1KB
stpcpy.c 1KB
msvc-nothrow.c 1KB
xalloc-die.c 1KB
version.c 1KB
access.c 979B
exitfail.c 860B
unistd.c 103B
call 3KB
ChangeLog 107KB
clean 911B
close_stdout 256B
makefile.com 5KB
config_flags_pm.com 2KB
vms_export_symbol_test.com 937B
comments 1KB
共 457 条
- 1
- 2
- 3
- 4
- 5
嘻嘻月光吸血鬼
- 粉丝: 8
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5