You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by tr...@apache.org on 2003/04/22 00:36:56 UTC
cvs commit: apr/threadproc/unix proc.c
trawick 2003/04/21 15:36:56
Modified: . CHANGES
threadproc/unix proc.c
Log:
apr_proc_create() on Unix: Make the APR_SHELLCMD mode work
when there is more than one program argument passed in.
It worked before (and still does) if the app somehow knows to
pass in a single arg which is a string containing the program
name and all args, such as when calling system().
Now it works if the app passes the program arguments normally,
such as when using other modes of apr_proc_create().
Revision Changes Path
1.404 +4 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.403
retrieving revision 1.404
diff -u -r1.403 -r1.404
--- CHANGES 21 Apr 2003 14:21:59 -0000 1.403
+++ CHANGES 21 Apr 2003 22:36:55 -0000 1.404
@@ -1,5 +1,9 @@
Changes with APR 0.9.4
+ *) apr_proc_create() on Unix: Make the APR_SHELLCMD mode work
+ when there is more than one program argument passed in.
+ [Jeff Trawick]
+
*) Add --cc and --cpp flags to apr-config. [Jeff Trawick]
*) Don't segfault trying to close a file in error paths of flock
1.66 +36 -8 apr/threadproc/unix/proc.c
Index: proc.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/proc.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- proc.c 7 Feb 2003 21:02:31 -0000 1.65
+++ proc.c 21 Apr 2003 22:36:56 -0000 1.66
@@ -317,7 +317,6 @@
apr_pool_t *pool)
{
int i;
- const char **newargs;
new->in = attr->parent_in;
new->err = attr->parent_err;
@@ -423,22 +422,51 @@
}
if (attr->cmdtype == APR_SHELLCMD) {
- i = 0;
- while (args[i]) {
- i++;
- }
+ int onearg_len = 0;
+ const char *newargs[4];
- newargs = (const char **)apr_palloc(pool, sizeof (char *) * (i + 3));
newargs[0] = SHELL_PATH;
newargs[1] = "-c";
i = 0;
while (args[i]) {
- newargs[i + 2] = args[i];
+ onearg_len += strlen(args[i]);
+ onearg_len++; /* for space delimiter */
i++;
}
- newargs[i + 2] = NULL;
+ switch(i) {
+ case 0:
+ /* bad parameters; we're doomed */
+ break;
+ case 1:
+ /* no args, or caller already built a single string from
+ * progname and args
+ */
+ newargs[2] = args[0];
+ break;
+ default:
+ {
+ char *ch, *onearg;
+
+ ch = onearg = apr_palloc(pool, onearg_len);
+ i = 0;
+ while (args[i]) {
+ size_t len = strlen(args[i]);
+
+ memcpy(ch, args[i], len);
+ ch += len;
+ *ch = ' ';
+ ++ch;
+ ++i;
+ }
+ --ch; /* back up to trailing blank */
+ *ch = '\0';
+ newargs[2] = onearg;
+ }
+ }
+
+ newargs[3] = NULL;
if (attr->detached) {
apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);