Skip to content

Commit 0b0a7ee

Browse files
author
Ivan Zhakov
committed
Refactoring in apr_proc_create() for Windows. No behavior changes expected.
* threadproc/win32/proc.c (apr_proc_create): Move progname to argv0 conversion to each case. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1929716 13f79535-47bb-0310-9956-ffa450edef68
1 parent 52bb09e commit 0b0a7ee

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

threadproc/win32/proc.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
479479
{
480480
apr_status_t rv;
481481
apr_size_t i;
482-
const char *argv0;
483482
char *cmdline;
484483
apr_wchar_t *pEnvBlock;
485484
PROCESS_INFORMATION pi;
@@ -550,15 +549,18 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
550549
}
551550
}
552551

553-
if (has_space(progname)) {
554-
argv0 = apr_pstrcat(pool, "\"", progname, "\"", NULL);
555-
}
556-
else {
557-
argv0 = progname;
558-
}
559-
560552
if (attr->cmdtype == APR_SHELLCMD || attr->cmdtype == APR_SHELLCMD_ENV) {
561-
char *shellcmd = getenv("COMSPEC");
553+
const char *argv0;
554+
char *shellcmd;
555+
556+
if (has_space(progname)) {
557+
argv0 = apr_pstrcat(pool, "\"", progname, "\"", NULL);
558+
}
559+
else {
560+
argv0 = progname;
561+
}
562+
563+
shellcmd = getenv("COMSPEC");
562564
if (!shellcmd) {
563565
if (attr->errfn) {
564566
attr->errfn(pool, APR_EINVAL, "COMSPEC envar is not set");
@@ -600,6 +602,15 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
600602
if (i >= 4 && (strcasecmp(progname + i - 4, ".bat") == 0
601603
|| strcasecmp(progname + i - 4, ".cmd") == 0))
602604
{
605+
const char *argv0;
606+
607+
if (has_space(progname)) {
608+
argv0 = apr_pstrcat(pool, "\"", progname, "\"", NULL);
609+
}
610+
else {
611+
argv0 = progname;
612+
}
613+
603614
char *shellcmd = getenv("COMSPEC");
604615
if (!shellcmd) {
605616
if (attr->errfn) {
@@ -648,6 +659,15 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
648659
}
649660
}
650661
else {
662+
const char *argv0;
663+
664+
if (has_space(progname)) {
665+
argv0 = apr_pstrcat(pool, "\"", progname, "\"", NULL);
666+
}
667+
else {
668+
argv0 = progname;
669+
}
670+
651671
/* A simple command we are directly invoking.
652672
* Handle the args, seperate from argv0 */
653673
cmdline = apr_pstrdup(pool, argv0);

0 commit comments

Comments
 (0)