+2007-08-24 Kai Tietz <kai.tietz@onevision.com>
+
+ * pex-common.h: (pex_funcs): Retyped wait and exec_child to pid_t.
+ * pex-djgpp.c: Likewise.
+ * pex-msdos.c: Likewise.
+ * pex-unix.c: Likewise.
+ * pex-win32.c: Likewise.
+
2007-08-17 Michael Snyder <msnyder@access-company.com>
* make-relative-prefix.c (make_relative_prefix_1): Resource leaks.
#include "libiberty.h"
#include <stdio.h>
+/* pid_t is may defined by config.h or sys/types.h needs to be
+ included. */
+#if !defined(pid_t) && defined(HAVE_SYS_TYPES_H)
+#include <sys/types.h>
+#endif
+
#define install_error_msg "installation problem, cannot exec `%s'"
/* stdin file number. */
closed in the child process. The function should handle the
PEX_STDERR_TO_STDOUT flag. Return >= 0 on success, or -1 on
error and set *ERRMSG and *ERR. */
- long (*exec_child) (struct pex_obj *, int /* flags */,
+ pid_t (*exec_child) (struct pex_obj *, int /* flags */,
const char */* executable */, char * const * /* argv */,
char * const * /* env */,
int /* in */, int /* out */, int /* errdes */,
and time in *TIME (if it is not null). CHILD is from fork. DONE
is 1 if this is called via pex_free. ERRMSG and ERR are as in
fork. Return 0 on success, -1 on error. */
- int (*wait) (struct pex_obj *, long /* child */, int * /* status */,
+ int (*wait) (struct pex_obj *, pid_t /* child */, int * /* status */,
struct pex_time * /* time */, int /* done */,
const char ** /* errmsg */, int * /* err */);
/* Create a pipe (only called if PEX_USE_PIPES is set) storing two
static int pex_djgpp_open_read (struct pex_obj *, const char *, int);
static int pex_djgpp_open_write (struct pex_obj *, const char *, int);
-static long pex_djgpp_exec_child (struct pex_obj *, int, const char *,
+static pid_t pex_djgpp_exec_child (struct pex_obj *, int, const char *,
char * const *, char * const *,
int, int, int, int,
const char **, int *);
static int pex_djgpp_close (struct pex_obj *, int);
-static int pex_djgpp_wait (struct pex_obj *, long, int *, struct pex_time *,
+static int pex_djgpp_wait (struct pex_obj *, pid_t, int *, struct pex_time *,
int, const char **, int *);
/* The list of functions we pass to the common routines. */
/* Execute a child. */
-static long
+static pid_t
pex_djgpp_exec_child (struct pex_obj *obj, int flags, const char *executable,
char * const * argv, char * const * env,
int in, int out, int errdes,
{
*err = errno;
*errmsg = "dup";
- return -1;
+ return (pid_t) -1;
}
if (dup2 (in, STDIN_FILE_NO) < 0)
{
*err = errno;
*errmsg = "dup2";
- return -1;
+ return (pid_t) -1;
}
if (close (in) < 0)
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
{
*err = errno;
*errmsg = "dup";
- return -1;
+ return (pid_t) -1;
}
if (dup2 (out, STDOUT_FILE_NO) < 0)
{
*err = errno;
*errmsg = "dup2";
- return -1;
+ return (pid_t) -1;
}
if (close (out) < 0)
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
{
*err = errno;
*errmsg = "dup";
- return -1;
+ return (pid_t) -1;
}
if (dup2 ((flags & PEX_STDERR_TO_STDOUT) != 0 ? STDOUT_FILE_NO : errdes,
STDERR_FILE_NO) < 0)
{
*err = errno;
*errmsg = "dup2";
- return -1;
+ return (pid_t) -1;
}
if (errdes != STDERR_FILE_NO)
{
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
}
{
*err = errno;
*errmsg = "dup2";
- return -1;
+ return (pid_t) -1;
}
if (close (org_in) < 0)
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
{
*err = errno;
*errmsg = "dup2";
- return -1;
+ return (pid_t) -1;
}
if (close (org_out) < 0)
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
{
*err = errno;
*errmsg = "dup2";
- return -1;
+ return (pid_t) -1;
}
if (close (org_errdes) < 0)
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
statuses[obj->count] = status;
obj->sysdep = (void *) statuses;
- return obj->count;
+ return (pid_t) obj->count;
}
/* Wait for a child process to complete. Actually the child process
status. */
static int
-pex_djgpp_wait (struct pex_obj *obj, long pid, int *status,
+pex_djgpp_wait (struct pex_obj *obj, pid_t pid, int *status,
struct pex_time *time, int done ATTRIBUTE_UNUSED,
const char **errmsg ATTRIBUTE_UNUSED,
int *err ATTRIBUTE_UNUSED)
static int pex_msdos_open (struct pex_obj *, const char *, int);
static int pex_msdos_open (struct pex_obj *, const char *, int);
static int pex_msdos_fdindex (struct pex_msdos *, int);
-static long pex_msdos_exec_child (struct pex_obj *, int, const char *,
+static pid_t pex_msdos_exec_child (struct pex_obj *, int, const char *,
char * const *, char * const *,
int, int, int, int,
int, const char **, int *);
static int pex_msdos_close (struct pex_obj *, int);
-static int pex_msdos_wait (struct pex_obj *, long, int *, struct pex_time *,
+static int pex_msdos_wait (struct pex_obj *, pid_t, int *, struct pex_time *,
int, const char **, int *);
static void pex_msdos_cleanup (struct pex_obj *);
/* Execute a child. */
-static long
+static pid_t
pex_msdos_exec_child (struct pex_obj *obj, int flags, const char *executable,
char * const * argv, char * const * env, int in, int out,
int toclose ATTRIBUTE_UNUSED,
free (scmd);
free (rf);
*errmsg = "cannot open temporary command file";
- return -1;
+ return (pid_t) -1;
}
for (i = 1; argv[i] != NULL; ++i)
free (scmd);
free (rf);
*errmsg = "system";
- return -1;
+ return (pid_t) -1;
}
remove (rf);
ms->statuses = XRESIZEVEC(int, ms->statuses, obj->count + 1);
ms->statuses[obj->count] = status;
- return obj->count;
+ return (pid_t) obj->count;
}
/* Wait for a child process to complete. Actually the child process
status. */
static int
-pex_msdos_wait (struct pex_obj *obj, long pid, int *status,
+pex_msdos_wait (struct pex_obj *obj, pid_t pid, int *status,
struct pex_time *time, int done ATTRIBUTE_UNUSED,
const char **errmsg ATTRIBUTE_UNUSED,
int *err ATTRIBUTE_UNUSED)
ATTRIBUTE_NORETURN;
static int pex_unix_open_read (struct pex_obj *, const char *, int);
static int pex_unix_open_write (struct pex_obj *, const char *, int);
-static long pex_unix_exec_child (struct pex_obj *, int, const char *,
+static pid_t pex_unix_exec_child (struct pex_obj *, int, const char *,
char * const *, char * const *,
int, int, int, int,
const char **, int *);
static int pex_unix_close (struct pex_obj *, int);
-static int pex_unix_wait (struct pex_obj *, long, int *, struct pex_time *,
+static int pex_unix_wait (struct pex_obj *, pid_t, int *, struct pex_time *,
int, const char **, int *);
static int pex_unix_pipe (struct pex_obj *, int *, int);
static FILE *pex_unix_fdopenr (struct pex_obj *, int, int);
extern char **environ;
-static long
+static pid_t
pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
char * const * argv, char * const * env,
int in, int out, int errdes,
case -1:
*err = errno;
*errmsg = VFORK_STRING;
- return -1;
+ return (pid_t) -1;
case 0:
/* Child process. */
}
/* NOTREACHED */
- return -1;
+ return (pid_t) -1;
default:
/* Parent process. */
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
if (out != STDOUT_FILE_NO)
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
if (errdes != STDERR_FILE_NO)
{
*err = errno;
*errmsg = "close";
- return -1;
+ return (pid_t) -1;
}
}
- return (long) pid;
+ return pid;
}
}
/* Wait for a child process to complete. */
static int
-pex_unix_wait (struct pex_obj *obj, long pid, int *status,
+pex_unix_wait (struct pex_obj *obj, pid_t pid, int *status,
struct pex_time *time, int done, const char **errmsg,
int *err)
{
static int pex_win32_open_read (struct pex_obj *, const char *, int);
static int pex_win32_open_write (struct pex_obj *, const char *, int);
-static long pex_win32_exec_child (struct pex_obj *, int, const char *,
+static pid_t pex_win32_exec_child (struct pex_obj *, int, const char *,
char * const *, char * const *,
int, int, int, int,
const char **, int *);
static int pex_win32_close (struct pex_obj *, int);
-static int pex_win32_wait (struct pex_obj *, long, int *,
+static int pex_win32_wait (struct pex_obj *, pid_t, int *,
struct pex_time *, int, const char **, int *);
static int pex_win32_pipe (struct pex_obj *, int *, int);
static FILE *pex_win32_fdopenr (struct pex_obj *, int, int);
return c1 - c2;
}
-static long
+static pid_t
win32_spawn (const char *executable,
BOOL search,
char *const *argv,
free (full_executable);
- return -1;
+ return (pid_t) -1;
}
/* Clean up. */
if (env_block)
free (env_block);
- return (long) pi->hProcess;
+ return (pid_t) pi->hProcess;
error:
if (env_block)
if (full_executable)
free (full_executable);
- return -1;
+ return (pid_t) -1;
}
-static long
+static pid_t
spawn_script (const char *executable, char *const *argv,
char* const *env,
DWORD dwCreationFlags,
LPSTARTUPINFO si,
LPPROCESS_INFORMATION pi)
{
- int pid = -1;
+ pid_t pid = (pid_t) -1;
int save_errno = errno;
int fd = _open (executable, _O_RDONLY);
dwCreationFlags, si, pi);
if (executable1 != newex)
free ((char *) newex);
- if (pid < 0)
+ if ((long) pid < 0)
{
newex = msys_rootify (executable1);
if (newex != executable1)
}
}
}
- if (pid < 0)
+ if ((long) pid < 0)
errno = save_errno;
return pid;
}
/* Execute a child. */
-static long
+static pid_t
pex_win32_exec_child (struct pex_obj *obj ATTRIBUTE_UNUSED, int flags,
const char *executable, char * const * argv,
char* const* env,
const char **errmsg,
int *err)
{
- long pid;
+ pid_t pid;
HANDLE stdin_handle;
HANDLE stdout_handle;
HANDLE stderr_handle;
/* Create the child process. */
pid = win32_spawn (executable, (flags & PEX_SEARCH) != 0,
argv, env, dwCreationFlags, &si, &pi);
- if (pid == -1)
+ if (pid == (pid_t) -1)
pid = spawn_script (executable, argv, env, dwCreationFlags,
&si, &pi);
- if (pid == -1)
+ if (pid == (pid_t) -1)
{
*err = ENOENT;
*errmsg = "CreateProcess";
macros. Note that WIFSIGNALED will never be true under CRTDLL. */
static int
-pex_win32_wait (struct pex_obj *obj ATTRIBUTE_UNUSED, long pid,
+pex_win32_wait (struct pex_obj *obj ATTRIBUTE_UNUSED, pid_t pid,
int *status, struct pex_time *time, int done ATTRIBUTE_UNUSED,
const char **errmsg, int *err)
{
char const *errmsg;
int err;
argv++;
- printf ("%ld\n", pex_win32_exec_child (NULL, PEX_SEARCH, argv[0], argv, NULL, 0, 0, 1, 2, &errmsg, &err));
+ printf ("%ld\n", (long) pex_win32_exec_child (NULL, PEX_SEARCH, argv[0], argv, NULL, 0, 0, 1, 2, &errmsg, &err));
exit (0);
}
#endif