trawick 2004/06/23 05:20:44
Modified: . CHANGES
include apr_thread_proc.h
threadproc/os2 proc.c
threadproc/unix proc.c
threadproc/win32 proc.c
Log:
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.
Revision Changes Path
1.474 +4 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.473
retrieving revision 1.474
diff -u -r1.473 -r1.474
--- CHANGES 14 Jun 2004 22:24:56 -0000 1.473
+++ CHANGES 23 Jun 2004 12:20:44 -0000 1.474
@@ -7,6 +7,10 @@
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>]
1.111 +6 -3 apr/include/apr_thread_proc.h
Index: apr_thread_proc.h
===================================================================
RCS file: /home/cvs/apr/include/apr_thread_proc.h,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- apr_thread_proc.h 15 Jun 2004 20:51:25 -0000 1.110
+++ apr_thread_proc.h 23 Jun 2004 12:20:44 -0000 1.111
@@ -45,7 +45,10 @@
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 @@
* 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.
1.62 +3 -1 apr/threadproc/os2/proc.c
Index: proc.c
===================================================================
RCS file: /home/cvs/apr/threadproc/os2/proc.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- proc.c 14 Jun 2004 17:26:19 -0000 1.61
+++ proc.c 23 Jun 2004 12:20:44 -0000 1.62
@@ -333,7 +333,9 @@
/* ### 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) {
1.74 +8 -2 apr/threadproc/unix/proc.c
Index: proc.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/proc.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -r1.73 -r1.74
--- proc.c 14 Jun 2004 17:26:19 -0000 1.73
+++ proc.c 23 Jun 2004 12:20:44 -0000 1.74
@@ -392,7 +392,8 @@
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_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) {
1.93 +4 -2 apr/threadproc/win32/proc.c
Index: proc.c
===================================================================
RCS file: /home/cvs/apr/threadproc/win32/proc.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -r1.92 -r1.93
--- proc.c 14 Jun 2004 17:26:20 -0000 1.92
+++ proc.c 23 Jun 2004 12:20:44 -0000 1.93
@@ -349,7 +349,7 @@
}
#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 @@
}
}
- 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;
/*