summaryrefslogtreecommitdiff
path: root/threadproc
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2002-04-13 22:34:55 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2002-04-13 22:34:55 +0000
commitd064090daffd825bf5ba964901a7d0f28b7347fb (patch)
tree5e0f6eb35c5cea01242631e1688fbdf6ca1a57cc /threadproc
parent73c582bf2f871b1a7b99d3ba6eca9895e34e3517 (diff)
downloadlibapr-d064090daffd825bf5ba964901a7d0f28b7347fb.tar.gz
Significant overhaul to respect all four flavors of APR_PROCESS, _ENV,
_PATH, and APR_SHELLCMD git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63261 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r--threadproc/win32/proc.c76
1 files changed, 54 insertions, 22 deletions
diff --git a/threadproc/win32/proc.c b/threadproc/win32/proc.c
index 36f952d1c..1eb5ba9fe 100644
--- a/threadproc/win32/proc.c
+++ b/threadproc/win32/proc.c
@@ -362,19 +362,34 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
/* progname must be unquoted, in native format, as there are all sorts
* of bugs in the NT library loader code that fault when parsing '/'.
- * We do not directly manipulate cmdline, and it will become a copy,
- * so we've casted past the constness issue.
* XXX progname must be NULL if this is a 16 bit app running in WOW
*/
if (progname[0] == '\"') {
progname = apr_pstrndup(pool, progname + 1, strlen(progname) - 2);
}
- if ((rv = apr_filepath_merge(&cmdline, attr->currdir, progname,
- APR_FILEPATH_NATIVE, pool)) != APR_SUCCESS) {
- return rv;
+ if (attr->cmdtype == APR_PROGRAM || attr->cmdtype == APR_PROGRAM_ENV) {
+ char *fullpath = NULL;
+ if ((rv = apr_filepath_merge(&fullpath, attr->currdir, progname,
+ APR_FILEPATH_NATIVE, pool)) != APR_SUCCESS) {
+ return rv;
+ }
+ progname = fullpath;
+ }
+ else {
+ /* Do not fail if the path isn't parseable for APR_PROGRAM_PATH
+ * or APR_SHELLCMD. We only invoke apr_filepath_merge (with no
+ * left hand side expression) in order to correct the path slash
+ * delimiters. But the filename doesn't need to be in the CWD,
+ * nor does it need to be a filename at all (it could be a
+ * built-in shell command.)
+ */
+ char *fullpath = NULL;
+ if ((rv = apr_filepath_merge(&fullpath, "", progname,
+ APR_FILEPATH_NATIVE, pool)) == APR_SUCCESS) {
+ progname = fullpath;
+ }
}
- progname = cmdline;
if (has_space(progname)) {
argv0 = apr_pstrcat(pool, "\"", progname, "\"", NULL);
@@ -394,8 +409,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
}
}
- /* ### how to handle APR_PROGRAM_ENV and APR_PROGRAM_PATH? */
-
if (attr->cmdtype == APR_SHELLCMD) {
char *shellcmd = getenv("COMSPEC");
if (!shellcmd) {
@@ -475,13 +488,22 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
}
}
else {
- /* A simple command we are directly invoking
+ /* A simple command we are directly invoking. Do not pass
+ * the first arg to CreateProc() for APR_PROGRAM_PATH
+ * invocation, since it would need to be a literal and
+ * complete file path. That is; "c:\bin\aprtest.exe"
+ * would succeed, but "c:\bin\aprtest" or "aprtest.exe"
+ * can fail.
*/
cmdline = apr_pstrcat(pool, argv0, cmdline, NULL);
+
+ if (attr->cmdtype == APR_PROGRAM_PATH) {
+ progname = NULL;
+ }
}
}
- if (!env)
+ if (!env || attr->cmdtype == APR_PROGRAM_ENV)
pEnvBlock = NULL;
else {
apr_size_t iEnvBlockLen;
@@ -549,24 +571,34 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
IF_WIN_OS_IS_UNICODE
{
STARTUPINFOW si;
- apr_size_t nprg = strlen(progname) + 1;
- apr_size_t nwprg = nprg + 6;
- apr_wchar_t *wprg = apr_palloc(pool, nwprg * sizeof(wprg[0]));
- apr_size_t ncmd = strlen(cmdline) + 1, nwcmd = ncmd;
- apr_wchar_t *wcmd = apr_palloc(pool, nwcmd * sizeof(wcmd[0]));
- apr_size_t ncwd = 0, nwcwd = 0;
+ apr_wchar_t *wprg = NULL;
+ apr_wchar_t *wcmd = NULL;
apr_wchar_t *wcwd = NULL;
- if (((rv = apr_conv_utf8_to_ucs2(progname, &nprg, wprg, &nwprg))
- != APR_SUCCESS)
- || ((rv = apr_conv_utf8_to_ucs2(cmdline, &ncmd, wcmd, &nwcmd))
- != APR_SUCCESS)) {
- return rv;
+ if (progname) {
+ apr_size_t nprg = strlen(progname) + 1;
+ apr_size_t nwprg = nprg + 6;
+ wprg = apr_palloc(pool, nwprg * sizeof(wprg[0]));
+ if ((rv = apr_conv_utf8_to_ucs2(progname, &nprg, wprg, &nwprg))
+ != APR_SUCCESS) {
+ return rv;
+ }
+ }
+
+ if (cmdline) {
+ apr_size_t ncmd = strlen(cmdline) + 1;
+ apr_size_t nwcmd = ncmd;
+ wcmd = apr_palloc(pool, nwcmd * sizeof(wcmd[0]));
+ if ((rv = apr_conv_utf8_to_ucs2(cmdline, &ncmd, wcmd, &nwcmd))
+ != APR_SUCCESS) {
+ return rv;
+ }
}
if (attr->currdir)
{
- ncwd = nwcwd = strlen(attr->currdir) + 1;
+ apr_size_t ncwd = strlen(attr->currdir) + 1;
+ apr_size_t nwcwd = ncwd;
wcwd = apr_palloc(pool, ncwd * sizeof(wcwd[0]));
if ((rv = apr_conv_utf8_to_ucs2(attr->currdir, &ncwd,
wcwd, &nwcwd))