diff options
author | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2003-04-21 22:36:56 +0000 |
---|---|---|
committer | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2003-04-21 22:36:56 +0000 |
commit | dc96aa1b6762137af34b92f31821dc55e74bb65e (patch) | |
tree | c6835bab998c881da276095db1691b7c1fc8b74a /threadproc | |
parent | 3b4619a031def1d304efb309bb41e51a27fdfa6e (diff) | |
download | libapr-dc96aa1b6762137af34b92f31821dc55e74bb65e.tar.gz |
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().
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64490 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r-- | threadproc/unix/proc.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c index 015fe04c3..2fbcb2908 100644 --- a/threadproc/unix/proc.c +++ b/threadproc/unix/proc.c @@ -317,7 +317,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, apr_pool_t *pool) { int i; - const char **newargs; new->in = attr->parent_in; new->err = attr->parent_err; @@ -423,22 +422,51 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } 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); |