[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to gnats/libiberty/pexecute.c
From: |
Milan Zamazal |
Subject: |
Changes to gnats/libiberty/pexecute.c |
Date: |
Mon, 10 Dec 2001 18:04:29 -0500 |
Index: gnats/libiberty/pexecute.c
diff -c gnats/libiberty/pexecute.c:1.2 gnats/libiberty/pexecute.c:1.3
*** gnats/libiberty/pexecute.c:1.2 Tue Oct 26 03:10:16 1999
--- gnats/libiberty/pexecute.c Mon Dec 10 18:03:26 2001
***************
*** 1,6 ****
/* Utilities to execute a program in a subprocess (possibly linked by pipes
with other subprocesses), and wait for it.
! Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
--- 1,6 ----
/* Utilities to execute a program in a subprocess (possibly linked by pipes
with other subprocesses), and wait for it.
! Copyright (C) 1996-2000 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
***************
*** 29,56 ****
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
! #define ISSPACE (x) isspace(x)
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
- #ifdef vfork /* Autoconf may define this to fork for us. */
- # define VFORK_STRING "fork"
- #else
- # define VFORK_STRING "vfork"
- #endif
- #ifdef HAVE_VFORK_H
- #include <vfork.h>
- #endif
- #ifdef VMS
- #define vfork() (decc$$alloc_vfork_blocks() >= 0 ? \
- lib$get_current_invo_context(decc$$get_vfork_jmpbuf()) : -1)
- #endif /* VMS */
-
#include "libiberty.h"
/* stdin file number. */
#define STDIN_FILE_NO 0
--- 29,52 ----
#include <stdio.h>
#include <errno.h>
+ #ifdef NEED_DECLARATION_ERRNO
+ extern int errno;
+ #endif
+ #ifdef HAVE_STRING_H
+ #include <string.h>
+ #endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
! #ifdef HAVE_STDLIB_H
! #include <stdlib.h>
! #endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#include "libiberty.h"
+ #include "safe-ctype.h"
/* stdin file number. */
#define STDIN_FILE_NO 0
***************
*** 148,161 ****
if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
abort ();
! #ifdef __GO32__
/* ??? What are the possible return values from spawnv? */
! rc = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (1, program, argv);
#else
char *scmd, *rf;
FILE *argfile;
int i, el = flags & PEXECUTE_SEARCH ? 4 : 0;
scmd = (char *) xmalloc (strlen (program) + strlen (temp_base) + 6 + el);
rf = scmd + strlen(program) + 2 + el;
sprintf (scmd, "%s%s @%s.gp", program,
--- 144,159 ----
if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
abort ();
! #ifdef __DJGPP__
/* ??? What are the possible return values from spawnv? */
! rc = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_WAIT, program, argv);
#else
char *scmd, *rf;
FILE *argfile;
int i, el = flags & PEXECUTE_SEARCH ? 4 : 0;
+ if (temp_base == 0)
+ temp_base = choose_temp_base ();
scmd = (char *) xmalloc (strlen (program) + strlen (temp_base) + 6 + el);
rf = scmd + strlen(program) + 2 + el;
sprintf (scmd, "%s%s @%s.gp", program,
***************
*** 197,203 ****
if (rc == -1)
{
*errmsg_fmt = install_error_msg;
! *errmsg_arg = program;
return -1;
}
--- 195,201 ----
if (rc == -1)
{
*errmsg_fmt = install_error_msg;
! *errmsg_arg = (char *)program;
return -1;
}
***************
*** 206,211 ****
--- 204,216 ----
return last_pid;
}
+ /* Use ECHILD if available, otherwise use EINVAL. */
+ #ifdef ECHILD
+ #define PWAIT_ERROR ECHILD
+ #else
+ #define PWAIT_ERROR EINVAL
+ #endif
+
int
pwait (pid, status, flags)
int pid;
***************
*** 217,229 ****
/* Called twice for the same child? */
|| pid == last_reaped)
{
! /* ??? ECHILD would be a better choice. Can we use it here? */
! errno = EINVAL;
return -1;
}
/* ??? Here's an opportunity to canonicalize the values in STATUS.
Needed? */
*status = last_status;
last_reaped = last_pid;
return last_pid;
}
--- 222,237 ----
/* Called twice for the same child? */
|| pid == last_reaped)
{
! errno = PWAIT_ERROR;
return -1;
}
/* ??? Here's an opportunity to canonicalize the values in STATUS.
Needed? */
+ #ifdef __DJGPP__
+ *status = (last_status >> 8);
+ #else
*status = last_status;
+ #endif
last_reaped = last_pid;
return last_pid;
}
***************
*** 277,282 ****
--- 285,329 ----
argvec[i] = temp;
}
+ for (i = 0; argvec[i] != 0; i++)
+ {
+ if (strpbrk (argvec[i], " \t"))
+ {
+ int len, trailing_backslash;
+ char *temp;
+
+ len = strlen (argvec[i]);
+ trailing_backslash = 0;
+
+ /* There is an added complication when an arg with embedded white
+ space ends in a backslash (such as in the case of -iprefix arg
+ passed to cpp). The resulting quoted strings gets misinterpreted
+ by the command interpreter -- it thinks that the ending quote
+ is escaped by the trailing backslash and things get confused.
+ We handle this case by escaping the trailing backslash, provided
+ it was not escaped in the first place. */
+ if (len > 1
+ && argvec[i][len-1] == '\\'
+ && argvec[i][len-2] != '\\')
+ {
+ trailing_backslash = 1;
+ ++len; /* to escape the final backslash. */
+ }
+
+ len += 2; /* and for the enclosing quotes. */
+
+ temp = xmalloc (len + 1);
+ temp[0] = '"';
+ strcpy (temp + 1, argvec[i]);
+ if (trailing_backslash)
+ temp[len-2] = '\\';
+ temp[len-1] = '"';
+ temp[len] = '\0';
+
+ argvec[i] = temp;
+ }
+ }
+
return (const char * const *) argvec;
}
#endif /* __CYGWIN__ */
***************
*** 612,618 ****
const char *program;
char * const *argv;
const char *this_pname;
! const char *temp_base;
char **errmsg_fmt, **errmsg_arg;
int flags;
{
--- 659,665 ----
const char *program;
char * const *argv;
const char *this_pname;
! const char *temp_base ATTRIBUTE_UNUSED;
char **errmsg_fmt, **errmsg_arg;
int flags;
{
***************
*** 654,662 ****
/* Fork a subprocess; wait and retry if it fails. */
sleep_interval = 1;
for (retries = 0; retries < 4; retries++)
{
! pid = vfork ();
if (pid >= 0)
break;
sleep (sleep_interval);
--- 701,710 ----
/* Fork a subprocess; wait and retry if it fails. */
sleep_interval = 1;
+ pid = -1;
for (retries = 0; retries < 4; retries++)
{
! pid = fork ();
if (pid >= 0)
break;
sleep (sleep_interval);
***************
*** 666,676 ****
switch (pid)
{
case -1:
! {
! *errmsg_fmt = VFORK_STRING;
! *errmsg_arg = NULL;
! return -1;
! }
case 0: /* child */
/* Move the input and output pipes into place, if necessary. */
--- 714,722 ----
switch (pid)
{
case -1:
! *errmsg_fmt = "fork";
! *errmsg_arg = NULL;
! return -1;
case 0: /* child */
/* Move the input and output pipes into place, if necessary. */
***************
*** 694,700 ****
/* Exec the program. */
(*func) (program, argv);
- /* Note: Calling fprintf and exit here doesn't seem right for vfork. */
fprintf (stderr, "%s: ", this_pname);
fprintf (stderr, install_error_msg, program);
fprintf (stderr, ": %s\n", xstrerror (errno));
--- 740,745 ----
***************
*** 719,725 ****
pwait (pid, status, flags)
int pid;
int *status;
! int flags;
{
/* ??? Here's an opportunity to canonicalize the values in STATUS.
Needed? */
--- 764,770 ----
pwait (pid, status, flags)
int pid;
int *status;
! int flags ATTRIBUTE_UNUSED;
{
/* ??? Here's an opportunity to canonicalize the values in STATUS.
Needed? */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Changes to gnats/libiberty/pexecute.c,
Milan Zamazal <=