#ifndef CHILDPROC_MD_H #define CHILDPROC_MD_H #include #ifdef __APPLE__ #include #define environ (*_NSGetEnviron()) #endif /* This is one of the rare times it's more portable to declare an * external symbol explicitly, rather than via a system header. * The declaration is standardized as part of UNIX98, but there is * no standard (not even de-facto) header file where the * declaration is to be found. See: * http://www.opengroup.org/onlinepubs/009695399/functions/environ.html * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html * * "All identifiers in this volume of IEEE Std 1003.1-2001, except * environ, are defined in at least one of the headers" (!) */ extern char **environ; /* These numbers must be the same as the Enum in UNIXProcess.java * Must be a better way of doing this. */ #define MODE_CLONE 1 #define MODE_FORK 2 #define MODE_VFORK 3 #define MODE_SPAWN 4 typedef struct _ChildStuff { int in[2]; int out[2]; int err[2]; int fail[2]; int childenv[2]; int fds[3]; int mode; const char **argv; int argc; const char **envv; const char *pdir; int redirectErrorStream; void *clone_stack; } ChildStuff; /* following used in addition when mode is SPAWN */ typedef struct _SpawnInfo { int nargv; /* number of argv array elements */ int argvBytes; /* total number of bytes in argv array */ int nenvv; /* number of envv array elements */ int envvBytes; /* total number of bytes in envv array */ int dirlen; /* length of home directory string */ int parentPathLen; /* length of parentPath string */ int nparentPathv; /* number of elements in parentPathv array */ int parentPathvBytes; /* total number of bytes in parentPathv array */ } SpawnInfo; extern const char *parentPath; extern const char * const *parentPathv; ssize_t restartableWrite(int fd, const void *buf, size_t count); int restartableDup2(int fd_from, int fd_to); int restartableClose(int fd); int closeSafely(int fd); int isAsciiDigit(char c); int closeDescriptors(void); int moveDescriptor(int fd_from, int fd_to); int magicNumber(); ssize_t readFully(int fd, void *buf, size_t nbyte); void initVectorFromBlock(const char**vector, const char* block, int count); void execve_as_traditional_shell_script(const char *file, const char *argv[], const char *const envp[]); void execve_with_shell_fallback(int mode, const char *file, const char *argv[], const char *const envp[]); void JDK_execvpe(int mode, const char *file, const char *argv[], const char *const envp[]); int childProcess(void *arg); #endif