diff options
author | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-23 12:20:44 +0000 |
---|---|---|
committer | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2004-06-23 12:20:44 +0000 |
commit | 30657c4f011350df7489c3d7e5ba018ecf3c9cc9 (patch) | |
tree | 343a492c412dbe3195a865b3a4be4a3ef95fa689 | |
parent | dff74a633a0eb6e9452c3fe9615f273f61082c6f (diff) | |
download | libapr-30657c4f011350df7489c3d7e5ba018ecf3c9cc9.tar.gz |
Add command type APR_SHELLCMD_ENV for creating a process
which is started by the shell and which inherits the parent's
environment variables.
The immediate use for this is with Apache httpd's piped loggers,
correcting a regression since 1.3.
In general, applications starting child processes often want
the child to run with the same environment variables, so this
plugs a hole in the API.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@65213 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | include/apr_thread_proc.h | 9 | ||||
-rw-r--r-- | threadproc/os2/proc.c | 4 | ||||
-rw-r--r-- | threadproc/unix/proc.c | 10 | ||||
-rw-r--r-- | threadproc/win32/proc.c | 6 |
5 files changed, 25 insertions, 8 deletions
@@ -7,6 +7,10 @@ Changes for APR 1.1 [Deferring these features when 1.0 is rolled out.] Changes with APR 1.0 + *) Add command type APR_SHELLCMD_ENV for creating a process + which is started by the shell and which inherits the parent's + environment variables. [Jeff Trawick] + *) Fix apr_threadattr_detach_set() on Mac OS X. PR 28472. [INOUE Seiichiro <inoue ariel-networks.com>] diff --git a/include/apr_thread_proc.h b/include/apr_thread_proc.h index 47e443c3b..68ced433b 100644 --- a/include/apr_thread_proc.h +++ b/include/apr_thread_proc.h @@ -45,7 +45,10 @@ 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_PROGRAM_PATH, /**< find program on PATH, use our environment */ + APR_SHELLCMD_ENV, /**< use the shell to invoke the program, + * replicating our environment + */ } apr_cmdtype_e; typedef enum { @@ -546,8 +549,8 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont); * 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. This argument - * is ignored for APR_PROGRAM_ENV and APR_PROGRAM_PATH types - * of commands. + * is ignored for APR_PROGRAM_ENV, APR_PROGRAM_PATH, and + * APR_SHELLCMD_ENV types of commands. * @param attr the procattr we should use to determine how to create the new * process * @param pool The pool to use. diff --git a/threadproc/os2/proc.c b/threadproc/os2/proc.c index c0ff58407..4edb45221 100644 --- a/threadproc/os2/proc.c +++ b/threadproc/os2/proc.c @@ -333,7 +333,9 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname /* ### how to handle APR_PROGRAM_ENV and APR_PROGRAM_PATH? */ - if (attr->cmdtype == APR_SHELLCMD || strcasecmp(extension, ".cmd") == 0) { + if (attr->cmdtype == APR_SHELLCMD || + attr->cmdtype == APR_SHELLCMD_ENV || + strcasecmp(extension, ".cmd") == 0) { strcpy(interpreter, "#!" SHELL_PATH); extra_arg = "/C"; } else if (stricmp(extension, ".exe") != 0) { diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c index 5c5536b22..7f01425bc 100644 --- a/threadproc/unix/proc.c +++ b/threadproc/unix/proc.c @@ -392,7 +392,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, exit(-1); /* We have big problems, the child should exit. */ } - if (attr->cmdtype == APR_SHELLCMD) { + if (attr->cmdtype == APR_SHELLCMD || + attr->cmdtype == APR_SHELLCMD_ENV) { int onearg_len = 0; const char *newargs[4]; @@ -443,7 +444,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, apr_proc_detach(APR_PROC_DETACH_DAEMONIZE); } - execve(SHELL_PATH, (char * const *) newargs, (char * const *)env); + if (attr->cmdtype == APR_SHELLCMD) { + execve(SHELL_PATH, (char * const *) newargs, (char * const *)env); + } + else { + execv(SHELL_PATH, (char * const *)newargs); + } } else if (attr->cmdtype == APR_PROGRAM) { if (attr->detached) { diff --git a/threadproc/win32/proc.c b/threadproc/win32/proc.c index 3073b1a27..e7c21c105 100644 --- a/threadproc/win32/proc.c +++ b/threadproc/win32/proc.c @@ -349,7 +349,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } #ifndef _WIN32_WCE - if (attr->cmdtype == APR_SHELLCMD) { + if (attr->cmdtype == APR_SHELLCMD || attr->cmdtype == APR_SHELLCMD_ENV) { char *shellcmd = getenv("COMSPEC"); if (!shellcmd) { return APR_EINVAL; @@ -445,8 +445,10 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } } - if (!env || attr->cmdtype == APR_PROGRAM_ENV) + if (!env || attr->cmdtype == APR_PROGRAM_ENV || + attr->cmdtype == APR_SHELLCMD_ENV) { pEnvBlock = NULL; + } else { apr_size_t iEnvBlockLen; /* |