00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "pex-common.h"
00023
00024 #include <stdio.h>
00025 #include <errno.h>
00026 #ifdef NEED_DECLARATION_ERRNO
00027 extern int errno;
00028 #endif
00029 #ifdef HAVE_STDLIB_H
00030 #include <stdlib.h>
00031 #endif
00032 #include <process.h>
00033
00034
00035 #ifdef ECHILD
00036 #define PWAIT_ERROR ECHILD
00037 #else
00038 #define PWAIT_ERROR EINVAL
00039 #endif
00040
00041
00042
00043
00044
00045
00046
00047 static int last_pid = 0;
00048 static int last_status = 0;
00049 static int last_reaped = 0;
00050
00051 int
00052 pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
00053 const char *program;
00054 char * const *argv;
00055 const char *this_pname;
00056 const char *temp_base;
00057 char **errmsg_fmt, **errmsg_arg;
00058 int flags;
00059 {
00060 int rc;
00061
00062 last_pid++;
00063 if (last_pid < 0)
00064 last_pid = 1;
00065
00066 if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
00067 abort ();
00068
00069
00070 rc = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_WAIT, program, argv);
00071
00072 if (rc == -1)
00073 {
00074 *errmsg_fmt = install_error_msg;
00075 *errmsg_arg = (char *)program;
00076 return -1;
00077 }
00078
00079
00080 last_status = rc << 8;
00081 return last_pid;
00082 }
00083
00084 int
00085 pwait (pid, status, flags)
00086 int pid;
00087 int *status;
00088 int flags;
00089 {
00090
00091 if (pid != last_pid
00092
00093 || pid == last_reaped)
00094 {
00095 errno = PWAIT_ERROR;
00096 return -1;
00097 }
00098
00099
00100 *status = (last_status >> 8);
00101 last_reaped = last_pid;
00102 return last_pid;
00103 }