diff options
author | gstein <gstein@13f79535-47bb-0310-9956-ffa450edef68> | 2002-01-28 21:58:16 +0000 |
---|---|---|
committer | gstein <gstein@13f79535-47bb-0310-9956-ffa450edef68> | 2002-01-28 21:58:16 +0000 |
commit | b58d2a6bc3e4ca15d0afae4e31a22f9593810e89 (patch) | |
tree | 27008844acf42b08f87ebd8cf5ecc714c68b1340 | |
parent | 40a247ea0d81ad1ed349e1d044ef454c9608aa0b (diff) | |
download | libapr-b58d2a6bc3e4ca15d0afae4e31a22f9593810e89.tar.gz |
Add a couple new command types to process creation:
APR_PROGRAM_ENV: start the program using the caller's environment
APR_PROGRAM_PATH: search PATH for the program, use caller's env
(the normal APR_PROGRAM isolates the env and does not use PATH)
The BeOS, OS/2, and Win32 implementations are incomplete. These two
new forms just default back to APR_PROGRAM for now. (although BeOS
doesn't even distinguish between APR_SHELLCMD and APR_PROGRAM!)
On Unix and Netware, these map into execv() and execvp() calls.
Also clarified some doc for the enums in apr_thread_proc.h a bit.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62840 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | include/apr_thread_proc.h | 33 | ||||
-rw-r--r-- | threadproc/beos/proc.c | 2 | ||||
-rw-r--r-- | threadproc/netware/proc.c | 15 | ||||
-rw-r--r-- | threadproc/os2/proc.c | 2 | ||||
-rw-r--r-- | threadproc/unix/proc.c | 15 | ||||
-rw-r--r-- | threadproc/win32/proc.c | 2 |
6 files changed, 59 insertions, 10 deletions
diff --git a/include/apr_thread_proc.h b/include/apr_thread_proc.h index 7a680971d..dcc9cec32 100644 --- a/include/apr_thread_proc.h +++ b/include/apr_thread_proc.h @@ -71,7 +71,7 @@ extern "C" { #endif /* __cplusplus */ /** * @file apr_thread_proc.h - * @brief APR Thread Library + * @brief APR Thread and Process Library */ /** * @defgroup APR_Thread Thread Library @@ -79,15 +79,28 @@ extern "C" { * @{ */ -typedef enum {APR_SHELLCMD, APR_PROGRAM} apr_cmdtype_e; -typedef enum {APR_WAIT, APR_NOWAIT} apr_wait_how_e; +typedef enum { + APR_SHELLCMD, /**< use the shell to invoke the program */ + APR_PROGRAM, /**< invoke the program directly, no copied env */ + APR_PROGRAM_ENV, /**< invoke the program, replicating our environment */ + APR_PROGRAM_PATH /**< find program on PATH, use our environment */ +} apr_cmdtype_e; + +typedef enum { + APR_WAIT, /**< wait for the specified process to finish */ + APR_NOWAIT /**< do not wait -- just see if it has finished */ +} apr_wait_how_e; + /* I am specifically calling out the values so that the macros below make * more sense. Yes, I know I don't need to, but I am hoping this makes what * I am doing more clear. If you want to add more reasons to exit, continue * to use bitmasks. */ -typedef enum {APR_PROC_EXIT = 1, APR_PROC_SIGNAL = 2, - APR_PROC_SIGNAL_CORE = 4} apr_exit_why_e; +typedef enum { + APR_PROC_EXIT = 1, /**< process exited normally */ + APR_PROC_SIGNAL = 2, /**< process exited due to a signal */ + APR_PROC_SIGNAL_CORE = 4 /**< process exited and dumped a core file */ +} apr_exit_why_e; #define APR_PROC_CHECK_EXIT(x) (x & APR_PROC_EXIT) #define APR_PROC_CHECK_SIGNALED(x) (x & APR_PROC_SIGNAL) @@ -428,8 +441,10 @@ APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, * @param attr The procattr we care about. * @param cmd The type of command. One of: * <PRE> - * APR_SHELLCMD -- Shell script - * APR_PROGRAM -- Executable program (default) + * APR_SHELLCMD -- Shell script + * APR_PROGRAM -- Executable program (default) + * APR_PROGRAM_ENV -- Executable program, copy environment + * APR_PROGRAM_PATH -- Executable program on PATH, copy env * </PRE> */ APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr, @@ -477,7 +492,9 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont); * @param const_args the arguments to pass to the new program. The first * one should be the program name. * @param env The new environment table for the new process. This - * should be a list of NULL-terminated strings. + * should be a list of NULL-terminated strings. This argument + * is ignored for APR_PROGRAM_ENV and APR_PROGRAM_PATH types + * of commands. * @param attr the procattr we should use to determine how to create the new * process * @param cont The pool to use. diff --git a/threadproc/beos/proc.c b/threadproc/beos/proc.c index 7bfa25d64..edd36de60 100644 --- a/threadproc/beos/proc.c +++ b/threadproc/beos/proc.c @@ -249,6 +249,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname, } newargs[nargs] = NULL; + /* ### we should be looking at attr->cmdtype in here... */ + newproc = load_image(nargs, (const char**)newargs, (const char**)env); /* load_image copies the data so now we can free it... */ diff --git a/threadproc/netware/proc.c b/threadproc/netware/proc.c index 7052669b6..69c1aab51 100644 --- a/threadproc/netware/proc.c +++ b/threadproc/netware/proc.c @@ -349,12 +349,25 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } execve(SHELL_PATH, (char * const *) newargs, (char * const *)env); } - else { + else if (attr->cmdtype == APR_PROGRAM) { if (attr->detached) { apr_proc_detach(); } execve(progname, (char * const *)args, (char * const *)env); } + else if (attr->cmdtype == APR_PROGRAM_ENV) { + if (attr->detached) { + apr_proc_detach(); + } + execv(progname, (char * const *)args); + } + else { + /* APR_PROGRAM_PATH */ + if (attr->detached) { + apr_proc_detach(); + } + execvp(progname, (char * const *)args); + } exit(-1); /* if we get here, there is a problem, so exit with an */ /* error code. */ } diff --git a/threadproc/os2/proc.c b/threadproc/os2/proc.c index 927fd96ec..08af08794 100644 --- a/threadproc/os2/proc.c +++ b/threadproc/os2/proc.c @@ -345,6 +345,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname if (extension == NULL || strchr(extension, '/') || strchr(extension, '\\')) extension = ""; + /* ### how to handle APR_PROGRAM_ENV and APR_PROGRAM_PATH? */ + if (attr->cmdtype == APR_SHELLCMD || strcasecmp(extension, ".cmd") == 0) { strcpy(interpreter, "#!" SHELL_PATH); extra_arg = "/C"; diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c index 4872f7508..ff80f2cfe 100644 --- a/threadproc/unix/proc.c +++ b/threadproc/unix/proc.c @@ -366,12 +366,25 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname, } execve(SHELL_PATH, (char * const *) newargs, (char * const *)env); } - else { + else if (attr->cmdtype == APR_PROGRAM) { if (attr->detached) { apr_proc_detach(); } execve(progname, (char * const *)args, (char * const *)env); } + else if (attr->cmdtype == APR_PROGRAM_ENV) { + if (attr->detached) { + apr_proc_detach(); + } + execv(progname, (char * const *)args); + } + else { + /* APR_PROGRAM_PATH */ + if (attr->detached) { + apr_proc_detach(); + } + execvp(progname, (char * const *)args); + } exit(-1); /* if we get here, there is a problem, so exit with an */ /* error code. */ } diff --git a/threadproc/win32/proc.c b/threadproc/win32/proc.c index 10ea0f850..400d7ab23 100644 --- a/threadproc/win32/proc.c +++ b/threadproc/win32/proc.c @@ -343,6 +343,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, i++; } + /* ### how to handle APR_PROGRAM_ENV and APR_PROGRAM_PATH? */ + if (attr->cmdtype == APR_SHELLCMD) { char *shellcmd = getenv("COMSPEC"); if (!shellcmd) |