summaryrefslogtreecommitdiff
path: root/threadproc
diff options
context:
space:
mode:
authorjerenkrantz <jerenkrantz@13f79535-47bb-0310-9956-ffa450edef68>2004-11-17 01:07:02 +0000
committerjerenkrantz <jerenkrantz@13f79535-47bb-0310-9956-ffa450edef68>2004-11-17 01:07:02 +0000
commit6c396ff5c726ad3ccba9f8454d1d41ab65513945 (patch)
tree9fe875f78a137b87968ce8d5bcf5b554f2608fab /threadproc
parent9ffc3ba97e22859b387d44eaf5d48e559c6e8874 (diff)
downloadlibapr-6c396ff5c726ad3ccba9f8454d1d41ab65513945.tar.gz
Merge in changes from trunk to 1.0.x.
Changes have been reviewed to be binary compatible with 1.0.0 by Justin to the best of his sleep-deprived ability. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.0.x@76072 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r--threadproc/beos/.cvsignore1
-rw-r--r--threadproc/win32/proc.c40
-rw-r--r--threadproc/win32/thread.c39
3 files changed, 64 insertions, 16 deletions
diff --git a/threadproc/beos/.cvsignore b/threadproc/beos/.cvsignore
index 11f54a843..f82426797 100644
--- a/threadproc/beos/.cvsignore
+++ b/threadproc/beos/.cvsignore
@@ -1,5 +1,6 @@
Makefile
apr_proc_stub
*.lo
+*.slo
.libs
.deps
diff --git a/threadproc/win32/proc.c b/threadproc/win32/proc.c
index e7c21c105..191d682d4 100644
--- a/threadproc/win32/proc.c
+++ b/threadproc/win32/proc.c
@@ -245,14 +245,14 @@ static char *apr_caret_escape_args(apr_pool_t *p, const char *str)
APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
apr_child_errfn_t *errfn)
{
- /* won't ever be called on this platform, so don't save the function pointer */
+ attr->errfn = errfn;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
apr_int32_t chk)
{
- /* won't ever be used on this platform, so don't save the flag */
+ attr->errchk = chk;
return APR_SUCCESS;
}
@@ -311,6 +311,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
char *fullpath = NULL;
if ((rv = apr_filepath_merge(&fullpath, attr->currdir, progname,
APR_FILEPATH_NATIVE, pool)) != APR_SUCCESS) {
+ if (attr->errfn) {
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool, "filepath_merge failed.",
+ " currdir: ", attr->currdir,
+ " progname: ", progname, NULL));
+ }
return rv;
}
progname = fullpath;
@@ -352,6 +358,9 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
if (attr->cmdtype == APR_SHELLCMD || attr->cmdtype == APR_SHELLCMD_ENV) {
char *shellcmd = getenv("COMSPEC");
if (!shellcmd) {
+ if (attr->errfn) {
+ attr->errfn(pool, APR_EINVAL, "COMSPEC envar is not set");
+ }
return APR_EINVAL;
}
if (shellcmd[0] == '"') {
@@ -388,6 +397,9 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
{
char *shellcmd = getenv("COMSPEC");
if (!shellcmd) {
+ if (attr->errfn) {
+ attr->errfn(pool, APR_EINVAL, "COMSPEC envar is not set");
+ }
return APR_EINVAL;
}
if (shellcmd[0] == '"') {
@@ -479,6 +491,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
if ((rv = apr_conv_utf8_to_ucs2(env[i], &in,
pNext, &iEnvBlockLen))
!= APR_SUCCESS) {
+ if (attr->errfn) {
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool,
+ "utf8 to ucs2 conversion failed"
+ " on this string: ", env[i], NULL));
+ }
return rv;
}
pNext = wcschr(pNext, L'\0') + 1;
@@ -525,6 +543,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
wprg = apr_palloc(pool, nwprg * sizeof(wprg[0]));
if ((rv = apr_conv_utf8_to_ucs2(progname, &nprg, wprg, &nwprg))
!= APR_SUCCESS) {
+ if (attr->errfn) {
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool,
+ "utf8 to ucs2 conversion failed"
+ " on progname: ", progname, NULL));
+ }
return rv;
}
}
@@ -535,6 +559,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
wcmd = apr_palloc(pool, nwcmd * sizeof(wcmd[0]));
if ((rv = apr_conv_utf8_to_ucs2(cmdline, &ncmd, wcmd, &nwcmd))
!= APR_SUCCESS) {
+ if (attr->errfn) {
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool,
+ "utf8 to ucs2 conversion failed"
+ " on cmdline: ", cmdline, NULL));
+ }
return rv;
}
}
@@ -547,6 +577,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
if ((rv = apr_conv_utf8_to_ucs2(attr->currdir, &ncwd,
wcwd, &nwcwd))
!= APR_SUCCESS) {
+ if (attr->errfn) {
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool,
+ "utf8 to ucs2 conversion failed"
+ " on currdir: ", attr->currdir, NULL));
+ }
return rv;
}
}
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c
index 364d23274..95132cb4b 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -85,6 +85,7 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
{
apr_status_t stat;
unsigned temp;
+ HANDLE handle;
(*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
@@ -95,7 +96,7 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
(*new)->pool = pool;
(*new)->data = data;
(*new)->func = func;
-
+ (*new)->td = NULL;
stat = apr_pool_create(&(*new)->pool, pool);
if (stat != APR_SUCCESS) {
return stat;
@@ -105,14 +106,14 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
* same size as the calling thread.
*/
#ifndef _WIN32_WCE
- if (((*new)->td = (HANDLE)_beginthreadex(NULL,
+ if ((handle = (HANDLE)_beginthreadex(NULL,
attr && attr->stacksize > 0 ? attr->stacksize : 0,
(unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
(*new), 0, &temp)) == 0) {
return APR_FROM_OS_ERROR(_doserrno);
}
#else
- if (((*new)->td = CreateThread(NULL,
+ if ((handle = CreateThread(NULL,
attr && attr->stacksize > 0 ? attr->stacksize : 0,
(unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
(*new), 0, &temp)) == 0) {
@@ -120,9 +121,10 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
}
#endif
if (attr && attr->detach) {
- CloseHandle((*new)->td);
- (*new)->td = NULL;
+ CloseHandle(handle);
}
+ else
+ (*new)->td = handle;
return APR_SUCCESS;
}
@@ -132,10 +134,8 @@ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
{
thd->exitval = retval;
apr_pool_destroy(thd->pool);
+ thd->pool = NULL;
#ifndef _WIN32_WCE
- if (thd->td) {
- CloseHandle(thd->td);
- }
_endthreadex(0);
#else
ExitThread(0);
@@ -146,15 +146,26 @@ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
apr_thread_t *thd)
{
- apr_status_t rv;
-
+ apr_status_t rv = APR_SUCCESS;
+
+ if (!thd->td) {
+ /* Can not join on detached threads */
+ return APR_DETACH;
+ }
rv = WaitForSingleObject(thd->td, INFINITE);
if ( rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
- *retval = thd->exitval;
- return APR_SUCCESS;
+ /* If the thread_exit has been called */
+ if (!thd->pool)
+ *retval = thd->exitval;
+ else
+ rv = APR_INCOMPLETE;
}
- /* Wait failed */
- return apr_get_os_error();;
+ else
+ rv = apr_get_os_error();
+ CloseHandle(thd->td);
+ thd->td = NULL;
+
+ return rv;
}
APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)