Ignore:
Timestamp:
May 23, 2007, 7:31:19 AM (18 years ago)
Author:
bird
Message:

Merged with the 2007-05-23 CVS. Added rsort and fixed a couple of windows build issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmakenew/job.c

    r898 r903  
    103103# include <starlet.h>
    104104# include <lib$routines.h>
    105 static void vmsWaitForChildren PARAMS ((int *));
     105static void vmsWaitForChildren (int *);
    106106#endif
    107107
     
    135135
    136136#if !defined (wait) && !defined (POSIX)
    137 extern int wait ();
     137int wait ();
    138138#endif
    139139
     
    180180
    181181#ifndef HAVE_UNISTD_H
    182 # ifndef _MSC_VER
    183 extern int dup2 ();
    184 extern int execve ();
    185 extern void _exit ();
     182# ifndef _MSC_VER /* bird */
     183int dup2 ();
     184int execve ();
     185void _exit ();
     186# endif /* bird */
     187# ifndef VMS
     188int geteuid ();
     189int getegid ();
     190int setgid ();
     191int getgid ();
    186192# endif
    187 # ifndef VMS
    188 extern int geteuid ();
    189 extern int getegid ();
    190 extern int setgid ();
    191 extern int getgid ();
    192 # endif
    193 #endif
    194 
    195 extern char *allocated_variable_expand_for_file PARAMS ((char *line, struct file *file));
    196 
    197 extern int getloadavg PARAMS ((double loadavg[], int nelem));
    198 extern int start_remote_job PARAMS ((char **argv, char **envp, int stdin_fd,
    199                 int *is_remote, int *id_ptr, int *used_stdin));
    200 extern int start_remote_job_p PARAMS ((int));
    201 extern int remote_status PARAMS ((int *exit_code_ptr, int *signal_ptr,
    202                 int *coredump_ptr, int block));
    203 
    204 RETSIGTYPE child_handler PARAMS ((int));
    205 static void free_child PARAMS ((struct child *));
    206 static void start_job_command PARAMS ((struct child *child));
    207 static int load_too_high PARAMS ((void));
    208 static int job_next_command PARAMS ((struct child *));
    209 static int start_waiting_job PARAMS ((struct child *));
     193#endif
     194
     195int getloadavg (double loadavg[], int nelem);
     196int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote,
     197                      int *id_ptr, int *used_stdin);
     198int start_remote_job_p (int);
     199int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr,
     200                   int block);
     201
     202RETSIGTYPE child_handler (int);
     203static void free_child (struct child *);
     204static void start_job_command (struct child *child);
     205static int load_too_high (void);
     206static int job_next_command (struct child *);
     207static int start_waiting_job (struct child *);
    210208
    211209
     
    310308        {
    311309          const unsigned final_size = path_size + size + 1;
    312           char *const path = (char *) xmalloc (final_size);
     310          char *const path = xmalloc (final_size);
    313311          memcpy (path, temp_path, final_size);
    314312          *fd = _open_osfhandle ((long)h, 0);
     
    369367  i = 0;
    370368  while (known_os2shells[i] != NULL) {
    371     if (stricmp (name, known_os2shells[i]) == 0) /* strcasecmp() */
     369    if (strcasecmp (name, known_os2shells[i]) == 0)
    372370      return 0; /* not a unix shell */
    373371    i++;
     
    386384
    387385static void
    388 child_error (char *target_name, int exit_code, int exit_sig, int coredump,
    389              int ignored)
     386child_error (const char *target_name,
     387             int exit_code, int exit_sig, int coredump, int ignored)
    390388{
    391389  if (ignored && silent_flag)
     
    435433    }
    436434
    437 #if defined __EMX__ && !defined(__INNOTEK_LIBC__)
     435#if defined __EMX__ && !defined(__INNOTEK_LIBC__) /* bird */
    438436  /* The signal handler must called only once! */
    439437  signal (SIGCHLD, SIG_DFL);
     
    510508
    511509         The test and decrement are not atomic; if it is compiled into:
    512                 register = dead_children - 1;
     510                register = dead_children - 1;
    513511                dead_children = register;
    514512         a SIGCHLD could come between the two instructions.
     
    925923      for (i = 0; i < child->file->cmds->ncommand_lines; ++i)
    926924        free (child->command_lines[i]);
    927       free ((char *) child->command_lines);
     925      free (child->command_lines);
    928926    }
    929927
     
    933931      while (*ep != 0)
    934932        free (*ep++);
    935       free ((char *) child->environment);
    936     }
    937 
    938   free ((char *) child);
     933      free (child->environment);
     934    }
     935
     936  free (child);
    939937}
    940938
     
    977975  struct sigaction sa;
    978976
    979 #if defined(__EMX__) && !defined(__KLIBC__)
     977#if defined(__EMX__) && !defined(__KLIBC__) /* bird */
    980978  /* The child handler must be turned off here.  */
    981979  signal (SIGCHLD, SIG_DFL);
    982980#endif
    983981
    984   bzero ((char *) &sa, sizeof sa);
     982  memset (&sa, '\0', sizeof sa);
    985983  sa.sa_handler = child_handler;
    986984  sa.sa_flags = set_handler ? 0 : SA_RESTART;
     
    10981096#ifndef VMS
    10991097      free (argv[0]);
    1100       free ((char *) argv);
     1098      free (argv);
    11011099#endif
    11021100      child->file->update_status = 1;
     
    11131111        {
    11141112          free (argv[0]);
    1115           free ((char *) argv);
     1113          free (argv);
    11161114        }
    11171115#endif
     
    11841182    {
    11851183      free (argv[0]);
    1186       free ((char *) argv);
     1184      free (argv);
    11871185      goto next_command;
    11881186    }
     
    11951193#ifndef VMS
    11961194      free (argv[0]);
    1197       free ((char *) argv);
     1195      free (argv);
    11981196#endif
    11991197      goto next_command;
     
    15061504#ifndef VMS
    15071505  free (argv[0]);
    1508   free ((char *) argv);
     1506  free (argv);
    15091507#endif
    15101508
     
    16251623new_job (struct file *file)
    16261624{
    1627   register struct commands *cmds = file->cmds;
    1628   register struct child *c;
     1625  struct commands *cmds = file->cmds;
     1626  struct child *c;
    16291627  char **lines;
    1630   register unsigned int i;
     1628  unsigned int i;
    16311629
    16321630  /* Let any previously decided-upon jobs that are waiting
     
    16411639
    16421640  /* Expand the command lines and store the results in LINES.  */
    1643   lines = (char **) xmalloc (cmds->ncommand_lines * sizeof (char *));
     1641  lines = xmalloc (cmds->ncommand_lines * sizeof (char *));
    16441642  for (i = 0; i < cmds->ncommand_lines; ++i)
    16451643    {
     
    16671665               we processed (where IN points) and the new chunk
    16681666               we are about to process (where REF points).  */
    1669             bcopy (in, out, ref - in);
     1667            memmove (out, in, ref - in);
    16701668
    16711669          /* Move both pointers past the boring stuff.  */
     
    17451743     `struct child', and add that to the chain.  */
    17461744
    1747   c = (struct child *) xmalloc (sizeof (struct child));
    1748   bzero ((char *)c, sizeof (struct child));
     1745  c = xmalloc (sizeof (struct child));
     1746  memset (c, '\0', sizeof (struct child));
    17491747  c->file = file;
    17501748  c->command_lines = lines;
     
    18661864  /* The job is now primed.  Start it running.
    18671865     (This will notice if there are in fact no commands.)  */
    1868   (void) start_waiting_job (c);
     1866  if (cmds->fileinfo.filenm)
     1867    DB (DB_BASIC, (_("Invoking commands from %s:%lu to update target `%s'.\n"),
     1868                   cmds->fileinfo.filenm, cmds->fileinfo.lineno,
     1869                   c->file->name));
     1870  else
     1871    DB (DB_BASIC, (_("Invoking builtin commands to update target `%s'.\n"),
     1872                   c->file->name));
     1873
     1874
     1875  start_waiting_job (c);
    18691876
    18701877#ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
     
    22932300# endif
    22942301
    2295         new_argv = (char **) alloca ((1 + argc + 1) * sizeof (char *));
     2302        new_argv = alloca ((1 + argc + 1) * sizeof (char *));
    22962303        new_argv[0] = shell;
    22972304
     
    24862493                             "shift", "switch", "test", "times", "trap",
    24872494                             "umask", "wait", "while", 0 };
    2488 #endif
    2489   register int i;
    2490   register char *p;
    2491   register char *ap;
     2495# ifdef HAVE_DOS_PATHS
     2496  /* This is required if the MSYS/Cygwin ports (which do not define
     2497     WINDOWS32) are compiled with HAVE_DOS_PATHS defined, which uses
     2498     sh_chars_sh[] directly (see below).  */
     2499  static char *sh_chars_sh = sh_chars;
     2500# endif  /* HAVE_DOS_PATHS */
     2501#endif
     2502  int i;
     2503  char *p;
     2504  char *ap;
    24922505  char *end;
    24932506  int instring, word_has_equals, seen_nonequals, last_argument_was_empty;
     
    25212534  else if (strcmp (shell, default_shell))
    25222535  {
    2523     char *s1 = _fullpath(NULL, shell, 0);
    2524     char *s2 = _fullpath(NULL, default_shell, 0);
    2525 
    2526     slow_flag = strcmp((s1 ? s1 : ""), (s2 ? s2 : ""));
     2536    char *s1 = _fullpath (NULL, shell, 0);
     2537    char *s2 = _fullpath (NULL, default_shell, 0);
     2538
     2539    slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : ""));
    25272540
    25282541    if (s1)
     
    25352548#else  /* not WINDOWS32 */
    25362549#if defined (__MSDOS__) || defined (__EMX__)
    2537   else if (stricmp (shell, default_shell))
     2550  else if (strcasecmp (shell, default_shell))
    25382551    {
    25392552      extern int _is_unixy_shell (const char *_path);
     
    25872600
    25882601  /* More than 1 arg per character is impossible.  */
    2589   new_argv = (char **) xmalloc (i * sizeof (char *));
     2602  new_argv = xmalloc (i * sizeof (char *));
    25902603
    25912604  /* All the args can fit in a buffer as big as LINE is.   */
    2592   ap = new_argv[0] = argstr = (char *) xmalloc (i);
     2605  ap = new_argv[0] = argstr = xmalloc (i);
    25932606  end = ap + i;
    25942607
     
    26292642                  *(ap++) = *p;
    26302643                }
    2631               /* If there's a TAB here, skip it.  */
    2632               if (p[1] == '\t')
     2644              /* If there's a command prefix char here, skip it.  */
     2645              if (p[1] == cmd_prefix)
    26332646                ++p;
    26342647            }
     
    26792692                ++p;
    26802693
    2681                 /* If there is a tab after a backslash-newline, remove it.  */
    2682                 if (p[1] == '\t')
     2694                /* If there is a command prefix after a backslash-newline,
     2695                   remove it.  */
     2696                if (p[1] == cmd_prefix)
    26832697                  ++p;
    26842698
     
    28072821      /* Line was empty.  */
    28082822      free (argstr);
    2809       free ((char *)new_argv);
     2823      free (new_argv);
    28102824      return 0;
    28112825    }
     
    28202834      /* Free the old argument list we were working on.  */
    28212835      free (argstr);
    2822       free ((char *)new_argv);
     2836      free (new_argv);
    28232837    }
    28242838
     
    28332847    char *dptr;
    28342848
    2835     buffer = (char *)xmalloc (strlen (line)+1);
     2849    buffer = xmalloc (strlen (line)+1);
    28362850
    28372851    ptr = line;
     
    28502864    *dptr = 0;
    28512865
    2852     new_argv = (char **) xmalloc (2 * sizeof (char *));
     2866    new_argv = xmalloc (2 * sizeof (char *));
    28532867    new_argv[0] = buffer;
    28542868    new_argv[1] = 0;
     
    28862900    unsigned int line_len = strlen (line);
    28872901
    2888     char *new_line = (char *) alloca (shell_len + (sizeof (minus_c) - 1)
    2889                                       + (line_len * 2) + 1);
     2902    char *new_line = alloca (shell_len + (sizeof (minus_c)-1)
     2903                             + (line_len*2) + 1);
    28902904    char *command_ptr = NULL; /* used for batch_mode_shell mode */
    28912905
     
    28962910
    28972911    ap = new_line;
    2898     bcopy (shell, ap, shell_len);
     2912    memcpy (ap, shell, shell_len);
    28992913    ap += shell_len;
    2900     bcopy (minus_c, ap, sizeof (minus_c) - 1);
     2914    memcpy (ap, minus_c, sizeof (minus_c) - 1);
    29012915    ap += sizeof (minus_c) - 1;
    29022916    command_ptr = ap;
     
    29302944
    29312945            ++p;
    2932             if (p[1] == '\t')
     2946            if (p[1] == cmd_prefix)
    29332947              ++p;
    29342948
     
    29652979      /* Need to allocate new_argv, although it's unused, because
    29662980        start_job_command will want to free it and its 0'th element.  */
    2967       new_argv = (char **) xmalloc(2 * sizeof (char *));
     2981      new_argv = xmalloc(2 * sizeof (char *));
    29682982      new_argv[0] = xstrdup ("");
    29692983      new_argv[1] = NULL;
     
    29923006
    29933007      /* create argv */
    2994       new_argv = (char **) xmalloc(3 * sizeof (char *));
     3008      new_argv = xmalloc(3 * sizeof (char *));
    29953009      if (unixy_shell) {
    29963010        new_argv[0] = xstrdup (shell);
     
    30043018#endif /* WINDOWS32 */
    30053019    if (unixy_shell)
    3006       new_argv = construct_command_argv_internal (new_line, (char **) NULL,
    3007                                                   (char *) 0, (char *) 0,
    3008                                                   (char **) 0);
     3020      new_argv = construct_command_argv_internal (new_line, 0, 0, 0, 0);
    30093021#ifdef __EMX__
    30103022    else if (!unixy_shell)
     
    30233035              {
    30243036                q += 2; /* remove '\\' and '\n' */
    3025                 if (q[0] == '\t')
    3026                   q++; /* remove 1st tab in the next line */
     3037                /* Remove any command prefix in the next line */
     3038                if (q[0] == cmd_prefix)
     3039                  q++;
    30273040              }
    30283041            else
     
    30643077
    30653078          /* exactly 3 arguments + NULL */
    3066           new_argv = (char **) xmalloc (4 * sizeof (char *));
     3079          new_argv = xmalloc (4 * sizeof (char *));
    30673080          /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times
    30683081             the trailing '\0' */
    3069           new_argv[0] = (char *) malloc (sh_len + line_len + 5);
     3082          new_argv[0] = xmalloc (sh_len + line_len + 5);
    30703083          memcpy (new_argv[0], shell, sh_len + 1);
    30713084          new_argv[1] = new_argv[0] + sh_len + 1;
     
    30823095           instead of recursively calling ourselves, because we
    30833096           cannot backslash-escape the special characters (see above).  */
    3084         new_argv = (char **) xmalloc (sizeof (char *));
     3097        new_argv = xmalloc (sizeof (char *));
    30853098        line_len = strlen (new_line) - shell_len - sizeof (minus_c) + 1;
    30863099        new_argv[0] = xmalloc (line_len + 1);
     
    31403153    }
    31413154
    3142   argv = (char **)malloc (argc * sizeof (char *));
     3155  argv = xmalloc (argc * sizeof (char *));
    31433156  if (argv == 0)
    31443157    abort ();
Note: See TracChangeset for help on using the changeset viewer.