aboutsummaryrefslogtreecommitdiff
path: root/threadproc/unix
diff options
context:
space:
mode:
authorJeff Trawick <trawick@apache.org>2003-04-21 22:36:56 +0000
committerJeff Trawick <trawick@apache.org>2003-04-21 22:36:56 +0000
commitd95d3fbaa657d086326c514b45c0a00507da564e (patch)
treec6835bab998c881da276095db1691b7c1fc8b74a /threadproc/unix
parent85549ebd5b9944ca1c391a048029ce9bfc2737ec (diff)
downloadapr-d95d3fbaa657d086326c514b45c0a00507da564e.tar.gz
apr-d95d3fbaa657d086326c514b45c0a00507da564e.zip
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: https://svn.apache.org/repos/asf/apr/apr/trunk@64490 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc/unix')
-rw-r--r--threadproc/unix/proc.c44
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);