VirtualBox

Changeset 501 in kBuild for vendor/gnumake/current/job.c


Ignore:
Timestamp:
Sep 15, 2006 2:30:32 AM (18 years ago)
Author:
bird
Message:

Load make-3.81/ into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/job.c

    r280 r501  
    11/* Job execution and handling for GNU Make.
    2 Copyright (C) 1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1999,
    3 2000,2001,2002,2003,2004,2005 Free Software Foundation, Inc.
     2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     4Foundation, Inc.
    45This file is part of GNU Make.
    56
    6 GNU Make is free software; you can redistribute it and/or modify
    7 it under the terms of the GNU General Public License as published by
    8 the Free Software Foundation; either version 2, or (at your option)
    9 any later version.
    10 
    11 GNU Make is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with GNU Make; see the file COPYING.  If not, write to
    18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    19 Boston, MA 02111-1307, USA.  */
     7GNU Make is free software; you can redistribute it and/or modify it under the
     8terms of the GNU General Public License as published by the Free Software
     9Foundation; either version 2, or (at your option) any later version.
     10
     11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
     12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     13A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     14
     15You should have received a copy of the GNU General Public License along with
     16GNU Make; see the file COPYING.  If not, write to the Free Software
     17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    2018
    2119#include "make.h"
     
    3432/* Default shell to use.  */
    3533#ifdef WINDOWS32
     34#include <windows.h>
    3635
    3736char *default_shell = "sh.exe";
    3837int no_default_sh_exe = 1;
    3938int batch_mode_shell = 1;
     39HANDLE main_thread;
    4040
    4141#elif defined (_AMIGA)
     
    9999# include <starlet.h>
    100100# include <lib$routines.h>
     101static void vmsWaitForChildren PARAMS ((int *));
    101102#endif
    102103
     
    242243}
    243244
    244 /* This function creates a temporary file name with the given extension
    245  * the unixy param controls both the extension and the path separator
    246  * return an xmalloc'ed string of a newly created temp file or die.  */
     245/* This function creates a temporary file name with an extension specified
     246 * by the unixy arg.
     247 * Return an xmalloc'ed string of a newly created temp file and its
     248 * file descriptor, or die.  */
    247249static char *
    248 create_batch_filename(char const *base, int unixy)
     250create_batch_file (char const *base, int unixy, int *fd)
    249251{
    250252  const char *const ext = unixy ? "sh" : "bat";
     
    304306          char *const path = (char *) xmalloc (final_size);
    305307          memcpy (path, temp_path, final_size);
    306           CloseHandle (h);
     308          *fd = _open_osfhandle ((long)h, 0);
    307309          if (unixy)
    308310            {
     
    317319    }
    318320
     321  *fd = -1;
    319322  if (error == NULL)
    320323    error = _("Cannot create a temporary file\n");
     
    448451reap_children (int block, int err)
    449452{
     453#ifndef WINDOWS32
    450454  WAIT_T status;
    451455  /* Initially, assume we have some.  */
    452456  int reap_more = 1;
     457#endif
    453458
    454459#ifdef WAIT_NOHANG
     
    475480      int child_failed;
    476481      int any_remote, any_local;
     482      int dontcare;
    477483
    478484      if (err && block)
    479485        {
    480           /* We might block for a while, so let the user know why.  */
     486          static int printed = 0;
     487
     488          /* We might block for a while, so let the user know why.
     489             Only print this message once no matter how many jobs are left.  */
    481490          fflush (stdout);
    482           error (NILF, _("*** Waiting for unfinished jobs...."));
     491          if (!printed)
     492            error (NILF, _("*** Waiting for unfinished jobs...."));
     493          printed = 1;
    483494        }
    484495
     
    539550            {
    540551#ifdef VMS
    541               static void vmsWaitForChildren PARAMS ((int *));
    542552              vmsWaitForChildren (&status);
    543553              pid = c->pid;
     
    612622          {
    613623            HANDLE hPID;
    614             int err;
     624            int werr;
     625            HANDLE hcTID, hcPID;
    615626            exit_code = 0;
    616627            exit_sig = 0;
    617628            coredump = 0;
     629
     630            /* Record the thread ID of the main process, so that we
     631               could suspend it in the signal handler.  */
     632            if (!main_thread)
     633              {
     634                hcTID = GetCurrentThread ();
     635                hcPID = GetCurrentProcess ();
     636                if (!DuplicateHandle (hcPID, hcTID, hcPID, &main_thread, 0,
     637                                      FALSE, DUPLICATE_SAME_ACCESS))
     638                  {
     639                    DWORD e = GetLastError ();
     640                    fprintf (stderr,
     641                             "Determine main thread ID (Error %ld: %s)\n",
     642                             e, map_windows32_error_to_string(e));
     643                  }
     644                else
     645                  DB (DB_VERBOSE, ("Main thread handle = 0x%08lx\n",
     646                                   (unsigned long)main_thread));
     647              }
    618648
    619649            /* wait for anything to finish */
     
    623653
    624654                /* was an error found on this process? */
    625                 err = process_last_err(hPID);
     655                werr = process_last_err(hPID);
    626656
    627657                /* get exit data */
    628658                exit_code = process_exit_code(hPID);
    629659
    630                 if (err)
     660                if (werr)
    631661                  fprintf(stderr, "make (e=%d): %s",
    632662                          exit_code, map_windows32_error_to_string(exit_code));
     
    691721        good_stdin_used = 0;
    692722
     723      dontcare = c->dontcare;
     724
    693725      if (child_failed && !c->noerror && !ignore_errors_flag)
    694726        {
     
    696728             delete non-precious targets, and abort.  */
    697729          static int delete_on_error = -1;
    698           child_error (c->file->name, exit_code, exit_sig, coredump, 0);
     730
     731          if (!dontcare)
     732            child_error (c->file->name, exit_code, exit_sig, coredump, 0);
     733
    699734          c->file->update_status = 2;
    700735          if (delete_on_error == -1)
     
    796831      /* If the job failed, and the -k flag was not given, die,
    797832         unless we are already in the process of dying.  */
    798       if (!err && child_failed && !keep_going_flag &&
     833      if (!err && child_failed && !dontcare && !keep_going_flag &&
    799834          /* fatal_error_signal will die with the right signal.  */
    800835          !handling_fatal_signal)
     
    938973start_job_command (struct child *child)
    939974{
    940 #ifndef _AMIGA
     975#if !defined(_AMIGA) && !defined(WINDOWS32)
    941976  static int bad_stdin = -1;
    942977#endif
     
    959994
    960995  p = child->command_ptr;
    961   child->noerror = flags & COMMANDS_NOERROR;
     996  child->noerror = ((flags & COMMANDS_NOERROR) != 0);
    962997
    963998  while (*p != '\0')
     
    13521387        unblock_sigs();
    13531388        fprintf(stderr,
    1354           _("process_easy() failed failed to launch process (e=%d)\n"),
    1355           process_last_err(hPID));
    1356                for (i = 0; argv[i]; i++)
    1357                  fprintf(stderr, "%s ", argv[i]);
    1358                fprintf(stderr, _("\nCounted %d args in failed launch\n"), i);
     1389                _("process_easy() failed to launch process (e=%ld)\n"),
     1390                process_last_err(hPID));
     1391        for (i = 0; argv[i]; i++)
     1392          fprintf(stderr, "%s ", argv[i]);
     1393        fprintf(stderr, _("\nCounted %d args in failed launch\n"), i);
     1394        goto error;
    13591395      }
    13601396  }
     
    14011437  /* If we are running at least one job already and the load average
    14021438     is too high, make this one wait.  */
    1403   if (!c->remote && job_slots_used > 0 && load_too_high ())
     1439  if (!c->remote
     1440      && ((job_slots_used > 0 && load_too_high ())
     1441#ifdef WINDOWS32
     1442          || (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
     1443#endif
     1444          ))
    14041445    {
    14051446      /* Put this child on the chain of children waiting for the load average
     
    15751616  c->command_lines = lines;
    15761617  c->sh_batch_file = NULL;
     1618
     1619  /* Cache dontcare flag because file->dontcare can be changed once we
     1620     return. Check dontcare inheritance mechanism for details.  */
     1621  c->dontcare = file->dontcare;
    15771622
    15781623  /* Fetch the first command line to be run.  */
     
    17721817  time_t now;
    17731818
     1819#ifdef WINDOWS32
     1820  /* sub_proc.c cannot wait for more than MAXIMUM_WAIT_OBJECTS children */
     1821  if (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
     1822    return 1;
     1823#endif
     1824
    17741825  if (max_load_average < 0)
    17751826    return 0;
     
    19081959}
    19091960
    1910 #elif !defined (_AMIGA) && !defined (__MSDOS__)
     1961#elif !defined (_AMIGA) && !defined (__MSDOS__) && !defined (VMS)
    19111962
    19121963/* UNIX:
     
    19291980  exec_command (argv, envp);
    19301981}
    1931 #endif /* !AMIGA && !__MSDOS__ */
     1982#endif /* !AMIGA && !__MSDOS__ && !VMS */
    19321983#endif /* !WINDOWS32 */
    19331984
     
    19722023      int i;
    19732024      fprintf(stderr,
    1974               _("process_easy() failed failed to launch process (e=%d)\n"),
     2025              _("process_easy() failed failed to launch process (e=%ld)\n"),
    19752026              process_last_err(hPID));
    19762027      for (i = 0; argv[i]; i++)
     
    20022053      else
    20032054          fprintf(stderr,
    2004                   _("make reaped child pid %d, still waiting for pid %d\n"),
    2005                   hWaitPID, hPID);
     2055                  _("make reaped child pid %ld, still waiting for pid %ld\n"),
     2056                  (DWORD)hWaitPID, (DWORD)hPID);
    20062057    }
    20072058
     
    22742325  int instring, word_has_equals, seen_nonequals, last_argument_was_empty;
    22752326  char **new_argv = 0;
     2327  char *argstr = 0;
    22762328#ifdef WINDOWS32
    22772329  int slow_flag = 0;
    22782330
    2279   if (no_default_sh_exe) {
     2331  if (!unixy_shell) {
    22802332    sh_cmds = sh_cmds_dos;
    22812333    sh_chars = sh_chars_dos;
     
    23602412
    23612413  /* All the args can fit in a buffer as big as LINE is.   */
    2362   ap = new_argv[0] = (char *) xmalloc (i);
     2414  ap = new_argv[0] = argstr = (char *) xmalloc (i);
    23632415  end = ap + i;
    23642416
     
    23682420  for (p = line; *p != '\0'; ++p)
    23692421    {
    2370       if (ap > end)
    2371         abort ();
     2422      assert (ap <= end);
    23722423
    23732424      if (instring)
    23742425        {
    2375         string_char:
    23762426          /* Inside a string, just copy any char except a closing quote
    23772427             or a backslash-newline combination.  */
     
    23832433            }
    23842434          else if (*p == '\\' && p[1] == '\n')
    2385             goto swallow_escaped_newline;
     2435            {
     2436              /* Backslash-newline is handled differently depending on what
     2437                 kind of string we're in: inside single-quoted strings you
     2438                 keep them; in double-quoted strings they disappear.
     2439                 For DOS/Windows/OS2, if we don't have a POSIX shell,
     2440                 we keep the pre-POSIX behavior of removing the
     2441                 backslash-newline.  */
     2442              if (instring == '"'
     2443#if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32)
     2444                  || !unixy_shell
     2445#endif
     2446                  )
     2447                ++p;
     2448              else
     2449                {
     2450                  *(ap++) = *(p++);
     2451                  *(ap++) = *p;
     2452                }
     2453              /* If there's a TAB here, skip it.  */
     2454              if (p[1] == '\t')
     2455                ++p;
     2456            }
    23862457          else if (*p == '\n' && restp != NULL)
    23872458            {
     
    24232494
    24242495          case '\\':
    2425             /* Backslash-newline combinations are eaten.  */
     2496            /* Backslash-newline has special case handling, ref POSIX.
     2497               We're in the fastpath, so emulate what the shell would do.  */
    24262498            if (p[1] == '\n')
    24272499              {
    2428               swallow_escaped_newline:
    2429 
    2430                 /* Eat the backslash, the newline, and following whitespace,
    2431                    replacing it all with a single space.  */
    2432                 p += 2;
    2433 
    2434                 /* If there is a tab after a backslash-newline,
    2435                    remove it from the source line which will be echoed,
    2436                    since it was most likely used to line
    2437                    up the continued line with the previous one.  */
    2438                 if (*p == '\t')
    2439                   /* Note these overlap and strcpy() is undefined for
    2440                      overlapping objects in ANSI C.  The strlen() _IS_ right,
    2441                      since we need to copy the nul byte too.  */
    2442                   bcopy (p + 1, p, strlen (p));
    2443 
    2444                 if (instring)
    2445                   goto string_char;
    2446                 else
    2447                   {
    2448                     if (ap != new_argv[i])
    2449                       /* Treat this as a space, ending the arg.
    2450                          But if it's at the beginning of the arg, it should
    2451                          just get eaten, rather than becoming an empty arg. */
    2452                       goto end_of_arg;
    2453                     else
    2454                       p = next_token (p) - 1;
    2455                   }
     2500                /* Throw out the backslash and newline.  */
     2501                ++p;
     2502
     2503                /* If there is a tab after a backslash-newline, remove it.  */
     2504                if (p[1] == '\t')
     2505                  ++p;
     2506
     2507                /* If there's nothing in this argument yet, skip any
     2508                   whitespace before the start of the next word.  */
     2509                if (ap == new_argv[i])
     2510                  p = next_token (p + 1) - 1;
    24562511              }
    24572512            else if (p[1] != '\0')
    24582513              {
    24592514#ifdef HAVE_DOS_PATHS
    2460                 /* Only remove backslashes before characters special
    2461                    to Unixy shells.  All other backslashes are copied
    2462                    verbatim, since they are probably DOS-style
    2463                    directory separators.  This still leaves a small
    2464                    window for problems, but at least it should work
    2465                    for the vast majority of naive users.  */
     2515                /* Only remove backslashes before characters special to Unixy
     2516                   shells.  All other backslashes are copied verbatim, since
     2517                   they are probably DOS-style directory separators.  This
     2518                   still leaves a small window for problems, but at least it
     2519                   should work for the vast majority of naive users.  */
    24662520
    24672521#ifdef __MSDOS__
     
    24782532                  if (p[1] != '\\' && p[1] != '\''
    24792533                      && !isspace ((unsigned char)p[1])
    2480                       && (strchr (sh_chars_sh, p[1]) == 0))
     2534                      && strchr (sh_chars_sh, p[1]) == 0)
    24812535                    /* back up one notch, to copy the backslash */
    24822536                    --p;
     
    25072561          case ' ':
    25082562          case '\t':
    2509           end_of_arg:
    25102563            /* We have the end of an argument.
    25112564               Terminate the text of the argument.  */
     
    25432596
    25442597            /* Ignore multiple whitespace chars.  */
    2545             p = next_token (p);
    2546             /* Next iteration should examine the first nonwhite char.  */
    2547             --p;
     2598            p = next_token (p) - 1;
    25482599            break;
    25492600
     
    25752626
    25762627  if (new_argv[0] == 0)
    2577     /* Line was empty.  */
    2578     return 0;
     2628    {
     2629      /* Line was empty.  */
     2630      free (argstr);
     2631      free ((char *)new_argv);
     2632      return 0;
     2633    }
    25792634
    25802635  return new_argv;
     
    25862641    {
    25872642      /* Free the old argument list we were working on.  */
    2588       free (new_argv[0]);
    2589       free ((void *)new_argv);
     2643      free (argstr);
     2644      free ((char *)new_argv);
    25902645    }
    25912646
     
    26772732        else if (*p == '\\' && p[1] == '\n')
    26782733          {
    2679             /* Eat the backslash, the newline, and following whitespace,
    2680                replacing it all with a single space (which is escaped
    2681                from the shell).  */
    2682             p += 2;
    2683 
    2684             /* If there is a tab after a backslash-newline,
    2685                remove it from the source line which will be echoed,
    2686                since it was most likely used to line
    2687                up the continued line with the previous one.  */
    2688             if (*p == '\t')
    2689               bcopy (p + 1, p, strlen (p));
    2690 
    2691             p = next_token (p);
    2692             --p;
    2693             if (unixy_shell && !batch_mode_shell)
    2694               *ap++ = '\\';
    2695             *ap++ = ' ';
     2734            /* POSIX says we keep the backslash-newline, but throw out
     2735               the next char if it's a TAB.  If we don't have a POSIX
     2736               shell on DOS/Windows/OS2, mimic the pre-POSIX behavior
     2737               and remove the backslash/newline.  */
     2738#if defined (__MSDOS__) || defined (__EMX__) || defined (WINDOWS32)
     2739# define PRESERVE_BSNL  unixy_shell
     2740#else
     2741# define PRESERVE_BSNL  1
     2742#endif
     2743            if (PRESERVE_BSNL)
     2744              {
     2745                *(ap++) = '\\';
     2746                *(ap++) = '\\';
     2747                *(ap++) = '\n';
     2748              }
     2749
     2750            ++p;
     2751            if (p[1] == '\t')
     2752              ++p;
     2753
    26962754            continue;
    26972755          }
     
    27232781       command line (e.g. Cygnus GNUWIN32 sh.exe on WIN32 systems).  In these
    27242782       cases, run commands via a script file.  */
    2725     if ((no_default_sh_exe || batch_mode_shell) && batch_filename_ptr) {
     2783    if (just_print_flag) {
     2784      /* Need to allocate new_argv, although it's unused, because
     2785        start_job_command will want to free it and its 0'th element.  */
     2786      new_argv = (char **) xmalloc(2 * sizeof (char *));
     2787      new_argv[0] = xstrdup ("");
     2788      new_argv[1] = NULL;
     2789    } else if ((no_default_sh_exe || batch_mode_shell) && batch_filename_ptr) {
     2790      int temp_fd;
    27262791      FILE* batch = NULL;
    27272792      int id = GetCurrentProcessId();
     
    27302795      /* create a file name */
    27312796      sprintf(fbuf, "make%d", id);
    2732       *batch_filename_ptr = create_batch_filename (fbuf, unixy_shell);
     2797      *batch_filename_ptr = create_batch_file (fbuf, unixy_shell, &temp_fd);
    27332798
    27342799      DB (DB_JOBS, (_("Creating temporary batch file %s\n"),
    27352800                    *batch_filename_ptr));
    27362801
    2737       /* create batch file to execute command */
    2738       batch = fopen (*batch_filename_ptr, "w");
     2802      /* Create a FILE object for the batch file, and write to it the
     2803         commands to be executed.  Put the batch file in TEXT mode.  */
     2804      _setmode (temp_fd, _O_TEXT);
     2805      batch = _fdopen (temp_fd, "wt");
    27392806      if (!unixy_shell)
    27402807        fputs ("@echo off\n", batch);
Note: See TracChangeset for help on using the changeset viewer.

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