summaryrefslogtreecommitdiff
path: root/threadproc
diff options
context:
space:
mode:
Diffstat (limited to 'threadproc')
-rw-r--r--threadproc/beos/apr_proc_stub.c10
-rw-r--r--threadproc/beos/proc.c62
-rw-r--r--threadproc/beos/thread.c50
-rw-r--r--threadproc/beos/threadpriv.c200
-rw-r--r--threadproc/beos/threadproc_common.c2
-rw-r--r--threadproc/netware/proc.c72
-rw-r--r--threadproc/netware/thread.c28
-rw-r--r--threadproc/netware/threadpriv.c18
-rw-r--r--threadproc/os2/proc.c56
-rw-r--r--threadproc/os2/thread.c26
-rw-r--r--threadproc/os2/threadpriv.c8
-rw-r--r--threadproc/unix/proc.c8
-rw-r--r--threadproc/unix/signals.c10
-rw-r--r--threadproc/unix/thread.c24
-rw-r--r--threadproc/win32/proc.c205
-rw-r--r--threadproc/win32/signals.c6
-rw-r--r--threadproc/win32/thread.c34
-rw-r--r--threadproc/win32/threadpriv.c4
18 files changed, 427 insertions, 396 deletions
diff --git a/threadproc/beos/apr_proc_stub.c b/threadproc/beos/apr_proc_stub.c
index 011d793e3..482dee986 100644
--- a/threadproc/beos/apr_proc_stub.c
+++ b/threadproc/beos/apr_proc_stub.c
@@ -27,7 +27,7 @@ struct pipefd {
int main(int argc, char *argv[]) {
/* we expect the following...
- *
+ *
* argv[0] = this stub
* argv[1] = directory to run in...
* argv[2] = progname to execute
@@ -40,14 +40,14 @@ int main(int argc, char *argv[]) {
void *buffer;
char ** newargs;
int i = 0;
-
+
newargs = (char**)malloc(sizeof(char*) * (argc - 1));
-
+
buffer = (void*)malloc(sizeof(struct pipefd));
/* this will block until we get the data */
receive_data(&sender, buffer, sizeof(struct pipefd));
pfd = (struct pipefd*)buffer;
-
+
if (pfd->in > STDERR_FILENO) {
if (dup2(pfd->in, STDIN_FILENO) != STDIN_FILENO) return (-1);
close (pfd->in);
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
for (i=3;i<=argc;i++){
newargs[i-3] = argv[i];
}
-
+
/* tell the caller we're OK to start */
send_data(sender,1,NULL,0);
diff --git a/threadproc/beos/proc.c b/threadproc/beos/proc.c
index cb09c9ff9..d35123916 100644
--- a/threadproc/beos/proc.c
+++ b/threadproc/beos/proc.c
@@ -30,7 +30,7 @@ struct send_pipe {
APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new, apr_pool_t *pool)
{
- (*new) = (apr_procattr_t *)apr_palloc(pool,
+ (*new) = (apr_procattr_t *)apr_palloc(pool,
sizeof(apr_procattr_t));
if ((*new) == NULL) {
@@ -43,7 +43,7 @@ APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new, apr_pool_t *
(*new)->child_out = NULL;
(*new)->parent_err = NULL;
(*new)->child_err = NULL;
- (*new)->currdir = NULL;
+ (*new)->currdir = NULL;
(*new)->cmdtype = APR_PROGRAM;
(*new)->detached = 0;
return APR_SUCCESS;
@@ -58,7 +58,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if ((in != APR_NO_PIPE) && (in != APR_NO_FILE)) {
/* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
- * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
+ * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
* the CHILD/PARENT blocking flags for the stdin pipe.
* stdout/stderr map to the correct mode by default.
*/
@@ -99,8 +99,8 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
- const char *dir)
+APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
+ const char *dir)
{
char * cwd;
if (dir[0] != '/') {
@@ -118,13 +118,13 @@ APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
}
APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
- apr_cmdtype_e cmd)
+ apr_cmdtype_e cmd)
{
attr->cmdtype = cmd;
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t detach)
+APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t detach)
{
attr->detached = detach;
return APR_SUCCESS;
@@ -133,7 +133,7 @@ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int3
APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
{
int pid;
-
+
if ((pid = fork()) < 0) {
return errno;
}
@@ -154,7 +154,7 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
area_info ai;
int32 cookie = 0;
area_id highest = 0;
-
+
while (get_next_area_info(0, &cookie, &ai) == B_OK)
if (ai.area > highest)
highest = ai.area;
@@ -169,20 +169,20 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
ai.protection, original);
}
}
-
+
#if APR_HAS_THREAD_LOCAL
apr_thread_current_after_fork();
#endif
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
proc->err = NULL;
return APR_INCHILD;
}
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
- proc->err = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
+ proc->err = NULL;
return APR_INPARENT;
}
@@ -207,18 +207,18 @@ APR_DECLARE(apr_status_t) apr_procattr_addrspace_set(apr_procattr_t *attr,
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
+APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
const char * const *args,
- const char * const *env,
- apr_procattr_t *attr,
+ const char * const *env,
+ apr_procattr_t *attr,
apr_pool_t *pool)
{
int i=0,nargs=0;
char **newargs = NULL;
thread_id newproc, sender;
- struct send_pipe *sp;
+ struct send_pipe *sp;
char * dir = NULL;
-
+
sp = (struct send_pipe *)apr_palloc(pool, sizeof(struct send_pipe));
new->in = attr->parent_in;
@@ -261,7 +261,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
while (--nargs >= 0)
free (newargs[nargs]);
free(newargs);
-
+
if (newproc < B_NO_ERROR) {
return errno;
}
@@ -281,26 +281,26 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
send_data(newproc, 0, (void*)sp, sizeof(struct send_pipe));
new->pid = newproc;
- /* before we go charging on we need the new process to get to a
+ /* before we go charging on we need the new process to get to a
* certain point. When it gets there it'll let us know and we
* can carry on. */
receive_data(&sender, (void*)NULL,0);
-
+
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
int *exitcode,
apr_exit_why_e *exitwhy,
- apr_wait_how_e waithow,
+ apr_wait_how_e waithow,
apr_pool_t *p)
{
proc->pid = -1;
return apr_proc_wait(proc, exitcode, exitwhy, waithow);
-}
+}
APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
- int *exitcode,
+ int *exitcode,
apr_exit_why_e *exitwhy,
apr_wait_how_e waithow)
{
@@ -343,7 +343,7 @@ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
}
return errno;
-}
+}
APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr, apr_file_t *child_in,
apr_file_t *parent_in)
@@ -394,7 +394,7 @@ APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_f
rv = apr_file_inherit_set(attr->child_out);
}
}
-
+
if (parent_out != NULL && rv == APR_SUCCESS)
rv = apr_file_dup(&attr->parent_out, parent_out, attr->pool);
@@ -422,20 +422,20 @@ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_f
rv = apr_file_inherit_set(attr->child_err);
}
}
-
+
if (parent_err != NULL && rv == APR_SUCCESS)
rv = apr_file_dup(&attr->parent_err, parent_err, attr->pool);
return rv;
}
-APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32_t what,
+APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32_t what,
void *limit)
{
return APR_ENOTIMPL;
}
-APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
+APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
const char *username,
const char *password)
{
diff --git a/threadproc/beos/thread.c b/threadproc/beos/thread.c
index 968031562..bf297330f 100644
--- a/threadproc/beos/thread.c
+++ b/threadproc/beos/thread.c
@@ -19,7 +19,7 @@
APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, apr_pool_t *pool)
{
- (*new) = (apr_threadattr_t *)apr_palloc(pool,
+ (*new) = (apr_threadattr_t *)apr_palloc(pool,
sizeof(apr_threadattr_t));
if ((*new) == NULL) {
@@ -27,27 +27,27 @@ APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, apr_pool
}
(*new)->pool = pool;
- (*new)->attr = (int32)B_NORMAL_PRIORITY;
+ (*new)->attr = (int32)B_NORMAL_PRIORITY;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, apr_int32_t on)
{
- if (on == 1){
- attr->detached = 1;
- } else {
- attr->detached = 0;
- }
+ if (on == 1){
+ attr->detached = 1;
+ } else {
+ attr->detached = 0;
+ }
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr)
{
- if (attr->detached == 1){
- return APR_DETACH;
- }
- return APR_NOTDETACH;
+ if (attr->detached == 1){
+ return APR_DETACH;
+ }
+ return APR_NOTDETACH;
}
APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
@@ -62,6 +62,13 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
return APR_ENOTIMPL;
}
+APR_DECLARE(apr_status_t) apr_threadattr_max_free_set(apr_threadattr_t *attr,
+ apr_size_t size)
+{
+ attr->max_free = size;
+ return APR_SUCCESS;
+}
+
#if APR_HAS_THREAD_LOCAL
static APR_THREAD_LOCAL apr_thread_t *current_thread = NULL;
#endif
@@ -91,27 +98,22 @@ static apr_status_t alloc_thread(apr_thread_t **new,
{
apr_status_t stat;
apr_abortfunc_t abort_fn = apr_pool_abort_get(pool);
- apr_allocator_t *allocator;
apr_pool_t *p;
/* The thread can be detached anytime (from the creation or later with
* apr_thread_detach), so it needs its own pool and allocator to not
* depend on a parent pool which could be destroyed before the thread
* exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
+ * not be used nor create children pools outside the thread. Passing
+ * NULL allocator will create one like that.
*/
- stat = apr_allocator_create(&allocator);
+ stat = apr_pool_create_unmanaged_ex(&p, abort_fn, NULL);
if (stat != APR_SUCCESS) {
- if (abort_fn)
- abort_fn(stat);
return stat;
}
- stat = apr_pool_create_unmanaged_ex(&p, abort_fn, allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
+ if (attr && attr->max_free) {
+ apr_allocator_max_free_set(apr_pool_allocator_get(p), attr->max_free);
}
- apr_allocator_owner_set(allocator, p);
(*new) = (apr_thread_t *)apr_pcalloc(p, sizeof(apr_thread_t));
if ((*new) == NULL) {
@@ -147,7 +149,7 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
temp = B_NORMAL_PRIORITY;
/* First we create the new thread...*/
- (*new)->td = spawn_thread((thread_func)dummy_worker,
+ (*new)->td = spawn_thread((thread_func)dummy_worker,
"apr thread", temp, (*new));
/* Now we try to run it...*/
@@ -288,7 +290,7 @@ APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd, apr_thread
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd, apr_os_thread_t *thethd,
+APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd, apr_os_thread_t *thethd,
apr_pool_t *pool)
{
if (pool == NULL) {
@@ -330,7 +332,7 @@ APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
-APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
+APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
void (*func)(void))
{
if (!control->hit) {
diff --git a/threadproc/beos/threadpriv.c b/threadproc/beos/threadpriv.c
index 442235f7d..a19b1fe4f 100644
--- a/threadproc/beos/threadpriv.c
+++ b/threadproc/beos/threadpriv.c
@@ -29,121 +29,121 @@ APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
}
(*key)->pool = pool;
-
- acquire_sem(lock);
- for ((*key)->key=0; (*key)->key < BEOS_MAX_DATAKEYS; (*key)->key++){
- if (key_table[(*key)->key].assigned == 0){
- key_table[(*key)->key].assigned = 1;
- key_table[(*key)->key].destructor = dest;
- release_sem(lock);
- return APR_SUCCESS;
- }
- }
- release_sem(lock);
+ acquire_sem(lock);
+ for ((*key)->key=0; (*key)->key < BEOS_MAX_DATAKEYS; (*key)->key++){
+ if (key_table[(*key)->key].assigned == 0){
+ key_table[(*key)->key].assigned = 1;
+ key_table[(*key)->key].destructor = dest;
+ release_sem(lock);
+ return APR_SUCCESS;
+ }
+
+ }
+ release_sem(lock);
return APR_ENOMEM;
}
APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new, apr_threadkey_t *key)
{
- thread_id tid;
- int i, index=0;
- tid = find_thread(NULL);
- for (i=0;i<BEOS_MAX_DATAKEYS;i++){
- if (beos_data[i]->data){
- /* it's been used */
- if (beos_data[i]->td == tid){
- index = i;
- }
- }
- }
- if (index == 0){
- /* no storage for thread so we can't get anything... */
- return APR_ENOMEM;
- }
+ thread_id tid;
+ int i, index=0;
+ tid = find_thread(NULL);
+ for (i=0;i<BEOS_MAX_DATAKEYS;i++){
+ if (beos_data[i]->data){
+ /* it's been used */
+ if (beos_data[i]->td == tid){
+ index = i;
+ }
+ }
+ }
+ if (index == 0){
+ /* no storage for thread so we can't get anything... */
+ return APR_ENOMEM;
+ }
- if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
- acquire_sem(key_table[key->key].lock);
- if (key_table[key->key].count){
- (*new) = (void*)beos_data[index]->data[key->key];
- } else {
- (*new) = NULL;
- }
- release_sem(key_table[key->key].lock);
- } else {
- (*new) = NULL;
- }
- return APR_SUCCESS;
+ if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
+ acquire_sem(key_table[key->key].lock);
+ if (key_table[key->key].count){
+ (*new) = (void*)beos_data[index]->data[key->key];
+ } else {
+ (*new) = NULL;
+ }
+ release_sem(key_table[key->key].lock);
+ } else {
+ (*new) = NULL;
+ }
+ return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, apr_threadkey_t *key)
{
- thread_id tid;
- int i,index = 0, ret = 0;
+ thread_id tid;
+ int i,index = 0, ret = 0;
- tid = find_thread(NULL);
- for (i=0; i < BEOS_MAX_DATAKEYS; i++){
- if (beos_data[i]->data){
- if (beos_data[i]->td == tid){index = i;}
- }
- }
- if (index==0){
- /* not yet been allocated */
- for (i=0; i< BEOS_MAX_DATAKEYS; i++){
- if (! beos_data[i]->data){
- /* we'll take this one... */
- index = i;
- beos_data[i]->data = (const void **)malloc(sizeof(void *) * BEOS_MAX_DATAKEYS);
- memset((void *)beos_data[i]->data, 0, sizeof(void *) * BEOS_MAX_DATAKEYS);
- beos_data[i]->count = (int)malloc(sizeof(int));
- beos_data[i]->td = (thread_id)malloc(sizeof(thread_id));
- beos_data[i]->td = tid;
- }
- }
- }
- if (index == 0){
- /* we're out of luck.. */
- return APR_ENOMEM;
- }
- if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
- acquire_sem(key_table[key->key].lock);
- if (key_table[key->key].count){
- if (beos_data[index]->data[key->key] == NULL){
- if (priv != NULL){
- beos_data[index]->count++;
- key_table[key->key].count++;
- }
- } else {
- if (priv == NULL){
- beos_data[index]->count--;
- key_table[key->key].count--;
- }
- }
- beos_data[index]->data[key->key] = priv;
- ret = 1;
- } else {
- ret = 0;
- }
- release_sem(key_table[key->key].lock);
- }
- if (ret)
- return APR_SUCCESS;
- return APR_ENOMEM;
+ tid = find_thread(NULL);
+ for (i=0; i < BEOS_MAX_DATAKEYS; i++){
+ if (beos_data[i]->data){
+ if (beos_data[i]->td == tid){index = i;}
+ }
+ }
+ if (index==0){
+ /* not yet been allocated */
+ for (i=0; i< BEOS_MAX_DATAKEYS; i++){
+ if (! beos_data[i]->data){
+ /* we'll take this one... */
+ index = i;
+ beos_data[i]->data = (const void **)malloc(sizeof(void *) * BEOS_MAX_DATAKEYS);
+ memset((void *)beos_data[i]->data, 0, sizeof(void *) * BEOS_MAX_DATAKEYS);
+ beos_data[i]->count = (int)malloc(sizeof(int));
+ beos_data[i]->td = (thread_id)malloc(sizeof(thread_id));
+ beos_data[i]->td = tid;
+ }
+ }
+ }
+ if (index == 0){
+ /* we're out of luck.. */
+ return APR_ENOMEM;
+ }
+ if ((key->key < BEOS_MAX_DATAKEYS) && (key_table)){
+ acquire_sem(key_table[key->key].lock);
+ if (key_table[key->key].count){
+ if (beos_data[index]->data[key->key] == NULL){
+ if (priv != NULL){
+ beos_data[index]->count++;
+ key_table[key->key].count++;
+ }
+ } else {
+ if (priv == NULL){
+ beos_data[index]->count--;
+ key_table[key->key].count--;
+ }
+ }
+ beos_data[index]->data[key->key] = priv;
+ ret = 1;
+ } else {
+ ret = 0;
+ }
+ release_sem(key_table[key->key].lock);
+ }
+ if (ret)
+ return APR_SUCCESS;
+ return APR_ENOMEM;
}
APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key)
{
- if (key->key < BEOS_MAX_DATAKEYS){
- acquire_sem(key_table[key->key].lock);
- if (key_table[key->key].count == 1){
- key_table[key->key].destructor = NULL;
- key_table[key->key].count = 0;
- }
- release_sem(key_table[key->key].lock);
- } else {
- return APR_ENOMEM;
- }
- return APR_SUCCESS;
+ if (key->key < BEOS_MAX_DATAKEYS){
+ acquire_sem(key_table[key->key].lock);
+ if (key_table[key->key].count == 1){
+ key_table[key->key].destructor = NULL;
+ key_table[key->key].count = 0;
+ }
+ release_sem(key_table[key->key].lock);
+ } else {
+ return APR_ENOMEM;
+ }
+ return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
@@ -165,7 +165,7 @@ APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey, apr_t
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
+APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
apr_os_threadkey_t *thekey, apr_pool_t *pool)
{
if (pool == NULL) {
diff --git a/threadproc/beos/threadproc_common.c b/threadproc/beos/threadproc_common.c
index 95e162544..14d40e658 100644
--- a/threadproc/beos/threadproc_common.c
+++ b/threadproc/beos/threadproc_common.c
@@ -18,4 +18,4 @@
code duplication */
#include "../unix/signals.c"
#include "../unix/procsup.c"
-
+
diff --git a/threadproc/netware/proc.c b/threadproc/netware/proc.c
index 06baea3ad..607ac2e48 100644
--- a/threadproc/netware/proc.c
+++ b/threadproc/netware/proc.c
@@ -65,7 +65,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if ((in != APR_NO_PIPE) && (in != APR_NO_FILE)) {
/* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
- * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
+ * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
* the CHILD/PARENT blocking flags for the stdin pipe.
* stdout/stderr map to the correct mode by default.
*/
@@ -158,7 +158,7 @@ APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_f
rv = apr_file_inherit_set(attr->child_out);
}
}
-
+
if (parent_out != NULL && rv == APR_SUCCESS) {
rv = apr_file_dup(&attr->parent_out, parent_out, attr->pool);
}
@@ -188,7 +188,7 @@ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_f
rv = apr_file_inherit_set(attr->child_err);
}
}
-
+
if (parent_err != NULL && rv == APR_SUCCESS) {
rv = apr_file_dup(&attr->parent_err, parent_err, attr->pool);
}
@@ -197,21 +197,21 @@ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_f
}
-APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
- const char *dir)
+APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
+ const char *dir)
{
- return apr_filepath_merge(&attr->currdir, NULL, dir,
+ return apr_filepath_merge(&attr->currdir, NULL, dir,
APR_FILEPATH_NATIVE, attr->pool);
}
APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
- apr_cmdtype_e cmd)
+ apr_cmdtype_e cmd)
{
/* won't ever be called on this platform, so don't save the function pointer */
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t detach)
+APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t detach)
{
attr->detached = detach;
return APR_SUCCESS;
@@ -221,7 +221,7 @@ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int3
APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
{
int pid;
-
+
if ((pid = fork()) < 0) {
return errno;
}
@@ -230,15 +230,15 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
apr_thread_current_after_fork();
#endif
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
- proc->err = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
+ proc->err = NULL;
return APR_INCHILD;
}
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
- proc->err = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
+ proc->err = NULL;
return APR_INPARENT;
}
#endif
@@ -310,25 +310,25 @@ APR_DECLARE(apr_status_t) apr_procattr_addrspace_set(apr_procattr_t *attr,
}
APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *newproc,
- const char *progname,
- const char * const *args,
+ const char *progname,
+ const char * const *args,
const char * const *env,
- apr_procattr_t *attr,
+ apr_procattr_t *attr,
apr_pool_t *pool)
{
wiring_t wire;
int addr_space;
- wire.infd = attr->child_in
- ? (attr->child_in->filedes != -1 ? attr->child_in->filedes
+ wire.infd = attr->child_in
+ ? (attr->child_in->filedes != -1 ? attr->child_in->filedes
: FD_UNUSED)
: fileno(stdin);
wire.outfd = attr->child_out
- ? (attr->child_out->filedes != -1 ? attr->child_out->filedes
+ ? (attr->child_out->filedes != -1 ? attr->child_out->filedes
: FD_UNUSED)
: fileno(stdout);
wire.errfd = attr->child_err
- ? (attr->child_err->filedes != -1 ? attr->child_err->filedes
+ ? (attr->child_err->filedes != -1 ? attr->child_err->filedes
: FD_UNUSED)
: fileno(stderr);
@@ -346,30 +346,30 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *newproc,
char *fullpath = NULL;
apr_status_t rv;
- if ((rv = apr_filepath_merge(&fullpath, attr->currdir, progname,
+ if ((rv = apr_filepath_merge(&fullpath, attr->currdir, progname,
APR_FILEPATH_NATIVE, pool)) != APR_SUCCESS) {
return rv;
}
progname = fullpath;
- }
+ }
- if ((newproc->pid = procve(progname, addr_space, (const char**)env, &wire,
+ if ((newproc->pid = procve(progname, addr_space, (const char**)env, &wire,
NULL, NULL, 0, NULL, (const char **)args)) == -1) {
return errno;
}
if (attr->child_in && (attr->child_in->filedes != -1)) {
- apr_pool_cleanup_kill(apr_file_pool_get(attr->child_in),
+ apr_pool_cleanup_kill(apr_file_pool_get(attr->child_in),
attr->child_in, apr_unix_file_cleanup);
apr_file_close(attr->child_in);
}
if (attr->child_out && (attr->child_out->filedes != -1)) {
- apr_pool_cleanup_kill(apr_file_pool_get(attr->child_out),
+ apr_pool_cleanup_kill(apr_file_pool_get(attr->child_out),
attr->child_out, apr_unix_file_cleanup);
apr_file_close(attr->child_out);
}
if (attr->child_err && (attr->child_err->filedes != -1)) {
- apr_pool_cleanup_kill(apr_file_pool_get(attr->child_err),
+ apr_pool_cleanup_kill(apr_file_pool_get(attr->child_err),
attr->child_err, apr_unix_file_cleanup);
apr_file_close(attr->child_err);
}
@@ -412,13 +412,13 @@ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
waitpid_options |= WNOHANG;
}
- /* If the pid is 0 then the process was started detached. There
- is no need to wait since there is nothing to wait for on a
+ /* If the pid is 0 then the process was started detached. There
+ is no need to wait since there is nothing to wait for on a
detached process. Starting a process as non-detached and
then calling wait or waitpid could cause the thread to hang.
- The reason for this is because NetWare does not have a way
- to kill or even signal a process to be killed. Starting
- all processes as detached avoids the possibility of a
+ The reason for this is because NetWare does not have a way
+ to kill or even signal a process to be killed. Starting
+ all processes as detached avoids the possibility of a
thread hanging. */
if (proc->pid == 0) {
*exitwhy = APR_PROC_EXIT;
@@ -453,7 +453,7 @@ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
#if APR_HAVE_STRUCT_RLIMIT
APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,
- apr_int32_t what,
+ apr_int32_t what,
struct rlimit *limit)
{
switch(what) {
@@ -491,10 +491,10 @@ APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,
}
return APR_SUCCESS;
-}
+}
#endif /* APR_HAVE_STRUCT_RLIMIT */
-APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
+APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
const char *username,
const char *password)
{
diff --git a/threadproc/netware/thread.c b/threadproc/netware/thread.c
index 404b42f74..822d2e24f 100644
--- a/threadproc/netware/thread.c
+++ b/threadproc/netware/thread.c
@@ -24,7 +24,7 @@ static int thread_count = 0;
apr_status_t apr_threadattr_create(apr_threadattr_t **new,
apr_pool_t *pool)
{
- (*new) = (apr_threadattr_t *)apr_palloc(pool,
+ (*new) = (apr_threadattr_t *)apr_palloc(pool,
sizeof(apr_threadattr_t));
if ((*new) == NULL) {
@@ -41,7 +41,7 @@ apr_status_t apr_threadattr_create(apr_threadattr_t **new,
apr_status_t apr_threadattr_detach_set(apr_threadattr_t *attr,apr_int32_t on)
{
attr->detach = on;
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t apr_threadattr_detach_get(apr_threadattr_t *attr)
@@ -64,6 +64,13 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
return APR_ENOTIMPL;
}
+APR_DECLARE(apr_status_t) apr_threadattr_max_free_set(apr_threadattr_t *attr,
+ apr_size_t size)
+{
+ attr->max_free = size;
+ return APR_SUCCESS;
+}
+
#if APR_HAS_THREAD_LOCAL
static APR_THREAD_LOCAL apr_thread_t *current_thread = NULL;
#endif
@@ -93,27 +100,22 @@ static apr_status_t alloc_thread(apr_thread_t **new,
{
apr_status_t stat;
apr_abortfunc_t abort_fn = apr_pool_abort_get(pool);
- apr_allocator_t *allocator;
apr_pool_t *p;
/* The thread can be detached anytime (from the creation or later with
* apr_thread_detach), so it needs its own pool and allocator to not
* depend on a parent pool which could be destroyed before the thread
* exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
+ * not be used nor create children pools outside the thread. Passing
+ * NULL allocator will create one like that.
*/
- stat = apr_allocator_create(&allocator);
+ stat = apr_pool_create_unmanaged_ex(&p, abort_fn, NULL);
if (stat != APR_SUCCESS) {
- if (abort_fn)
- abort_fn(stat);
return stat;
}
- stat = apr_pool_create_unmanaged_ex(&p, abort_fn, allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
+ if (attr && attr->max_free) {
+ apr_allocator_max_free_set(apr_pool_allocator_get(p), attr->max_free);
}
- apr_allocator_owner_set(allocator, p);
(*new) = (apr_thread_t *)apr_pcalloc(p, sizeof(apr_thread_t));
if ((*new) == NULL) {
@@ -263,7 +265,7 @@ void apr_thread_exit(apr_thread_t *thd, apr_status_t retval)
apr_status_t apr_thread_join(apr_status_t *retval,
apr_thread_t *thd)
{
- apr_status_t stat;
+ apr_status_t stat;
NXThreadId_t dthr;
if (thd->detached) {
diff --git a/threadproc/netware/threadpriv.c b/threadproc/netware/threadpriv.c
index 54680a563..3538559ec 100644
--- a/threadproc/netware/threadpriv.c
+++ b/threadproc/netware/threadpriv.c
@@ -17,13 +17,13 @@
#include "apr_portable.h"
#include "apr_arch_threadproc.h"
-apr_status_t apr_threadkey_private_create(apr_threadkey_t **key,
- void (*dest)(void *), apr_pool_t *pool)
+apr_status_t apr_threadkey_private_create(apr_threadkey_t **key,
+ void (*dest)(void *), apr_pool_t *pool)
{
apr_status_t stat;
-
+
(*key) = (apr_threadkey_t *)apr_palloc(pool, sizeof(apr_threadkey_t));
- if ((*key) == NULL) {
+ if ((*key) == NULL) {
return APR_ENOMEM;
}
@@ -38,12 +38,12 @@ apr_status_t apr_threadkey_private_create(apr_threadkey_t **key,
apr_status_t apr_threadkey_private_get(void **new, apr_threadkey_t *key)
{
apr_status_t stat;
-
+
if ((stat = NXKeyGetValue(key->key, new)) == 0) {
return APR_SUCCESS;
}
else {
- return stat;
+ return stat;
}
}
@@ -62,7 +62,7 @@ apr_status_t apr_threadkey_private_delete(apr_threadkey_t *key)
{
apr_status_t stat;
if ((stat = NXKeyDelete(key->key)) == 0) {
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
return stat;
}
@@ -86,7 +86,7 @@ apr_status_t apr_os_threadkey_get(apr_os_threadkey_t *thekey,
return APR_SUCCESS;
}
-apr_status_t apr_os_threadkey_put(apr_threadkey_t **key,
+apr_status_t apr_os_threadkey_put(apr_threadkey_t **key,
apr_os_threadkey_t *thekey, apr_pool_t *pool)
{
if (pool == NULL) {
@@ -98,5 +98,5 @@ apr_status_t apr_os_threadkey_put(apr_threadkey_t **key,
}
(*key)->key = *thekey;
return APR_SUCCESS;
-}
+}
diff --git a/threadproc/os2/proc.c b/threadproc/os2/proc.c
index 3f024f18d..ebff5dfb9 100644
--- a/threadproc/os2/proc.c
+++ b/threadproc/os2/proc.c
@@ -41,7 +41,7 @@ static apr_file_t no_file = { NULL, -1, };
APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new, apr_pool_t *pool)
{
- (*new) = (apr_procattr_t *)apr_palloc(pool,
+ (*new) = (apr_procattr_t *)apr_palloc(pool,
sizeof(apr_procattr_t));
if ((*new) == NULL) {
@@ -54,7 +54,7 @@ APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new, apr_pool_t *
(*new)->child_out = NULL;
(*new)->parent_err = NULL;
(*new)->child_err = NULL;
- (*new)->currdir = NULL;
+ (*new)->currdir = NULL;
(*new)->cmdtype = APR_PROGRAM;
(*new)->detached = FALSE;
return APR_SUCCESS;
@@ -69,7 +69,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if ((in != APR_NO_PIPE) && (in != APR_NO_FILE)) {
/* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
- * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
+ * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
* the CHILD/PARENT blocking flags for the stdin pipe.
* stdout/stderr map to the correct mode by default.
*/
@@ -160,7 +160,7 @@ APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_f
rv = apr_file_inherit_set(attr->child_out);
}
}
-
+
if (parent_out != NULL && rv == APR_SUCCESS) {
rv = apr_file_dup(&attr->parent_out, parent_out, attr->pool);
}
@@ -189,7 +189,7 @@ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_f
rv = apr_file_inherit_set(attr->child_err);
}
}
-
+
if (parent_err != NULL && rv == APR_SUCCESS) {
rv = apr_file_dup(&attr->parent_err, parent_err, attr->pool);
}
@@ -207,13 +207,13 @@ APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, const char
}
APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
- apr_cmdtype_e cmd)
+ apr_cmdtype_e cmd)
{
attr->cmdtype = cmd;
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t detach)
+APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int32_t detach)
{
attr->detached = detach;
return APR_SUCCESS;
@@ -222,7 +222,7 @@ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, apr_int3
APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
{
int pid;
-
+
if ((pid = fork()) < 0) {
return errno;
}
@@ -231,15 +231,15 @@ APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
apr_thread_current_after_fork();
#endif
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
- proc->err = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
+ proc->err = NULL;
return APR_INCHILD;
}
proc->pid = pid;
- proc->in = NULL;
- proc->out = NULL;
- proc->err = NULL;
+ proc->in = NULL;
+ proc->out = NULL;
+ proc->err = NULL;
return APR_INPARENT;
}
@@ -253,20 +253,20 @@ static char *double_quotes(apr_pool_t *pool, const char *str)
int num_quotes = 0;
int len = 0;
char *quote_doubled_str, *dest;
-
+
while (str[len]) {
num_quotes += str[len++] == '\"';
}
-
+
quote_doubled_str = apr_palloc(pool, len + num_quotes + 1);
dest = quote_doubled_str;
-
+
while (*str) {
if (*str == '\"')
*(dest++) = '\"';
*(dest++) = *(str++);
}
-
+
*dest = 0;
return quote_doubled_str;
}
@@ -336,7 +336,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname
else
DosDupHandle(attr->child_in->filedes, &dup);
}
-
+
if (attr->child_out) {
save_out = -1;
DosDupHandle(STDOUT_FILENO, &save_out);
@@ -346,7 +346,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname
else
DosDupHandle(attr->child_out->filedes, &dup);
}
-
+
if (attr->child_err) {
save_err = -1;
DosDupHandle(STDERR_FILENO, &save_err);
@@ -361,7 +361,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname
if (attr->currdir != NULL) {
_getcwd2(savedir, sizeof(savedir));
-
+
if (_chdir2(attr->currdir) < 0) {
if (criticalsection)
DosExitCritSec();
@@ -516,7 +516,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname
DosDupHandle(save_in, &dup);
DosClose(save_in);
}
-
+
if (attr->child_out) {
if (attr->child_out->filedes != -1) {
apr_file_close(attr->child_out);
@@ -526,7 +526,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname
DosDupHandle(save_out, &dup);
DosClose(save_out);
}
-
+
if (attr->child_err) {
if (attr->child_err->filedes != -1) {
apr_file_close(attr->child_err);
@@ -545,8 +545,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *proc, const char *progname
-static void proces_result_codes(RESULTCODES codes,
- int *exitcode,
+static void proces_result_codes(RESULTCODES codes,
+ int *exitcode,
apr_exit_why_e *exitwhy)
{
int result = 0;
@@ -624,7 +624,7 @@ APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
}
return APR_FROM_OS_ERROR(rc);
-}
+}
@@ -645,7 +645,7 @@ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
}
return APR_FROM_OS_ERROR(rc);
-}
+}
@@ -654,7 +654,7 @@ APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize)
return APR_ENOTIMPL;
}
-APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
+APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
const char *username,
const char *password)
{
diff --git a/threadproc/os2/thread.c b/threadproc/os2/thread.c
index 9b4eb340a..1ea7954dc 100644
--- a/threadproc/os2/thread.c
+++ b/threadproc/os2/thread.c
@@ -68,6 +68,13 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
return APR_ENOTIMPL;
}
+APR_DECLARE(apr_status_t) apr_threadattr_max_free_set(apr_threadattr_t *attr,
+ apr_size_t size)
+{
+ attr->max_free = size;
+ return APR_SUCCESS;
+}
+
#if APR_HAS_THREAD_LOCAL
static APR_THREAD_LOCAL apr_thread_t *current_thread = NULL;
#endif
@@ -95,27 +102,22 @@ static apr_status_t alloc_thread(apr_thread_t **new,
{
apr_status_t stat;
apr_abortfunc_t abort_fn = apr_pool_abort_get(pool);
- apr_allocator_t *allocator;
apr_pool_t *p;
/* The thread can be detached anytime (from the creation or later with
* apr_thread_detach), so it needs its own pool and allocator to not
* depend on a parent pool which could be destroyed before the thread
* exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
+ * not be used nor create children pools outside the thread. Passing
+ * NULL allocator will create one like that.
*/
- stat = apr_allocator_create(&allocator);
+ stat = apr_pool_create_unmanaged_ex(&p, abort_fn, NULL);
if (stat != APR_SUCCESS) {
- if (abort_fn)
- abort_fn(stat);
return stat;
}
- stat = apr_pool_create_unmanaged_ex(&p, abort_fn, allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
+ if (attr && attr->max_free) {
+ apr_allocator_max_free_set(apr_pool_allocator_get(p), attr->max_free);
}
- apr_allocator_owner_set(allocator, p);
(*new) = (apr_thread_t *)apr_pcalloc(p, sizeof(apr_thread_t));
if ((*new) == NULL) {
@@ -290,7 +292,7 @@ APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd, apr_thread
-APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd, apr_os_thread_t *thethd,
+APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd, apr_os_thread_t *thethd,
apr_pool_t *pool)
{
if ((*thd) == NULL) {
@@ -360,7 +362,7 @@ APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
-APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
+APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
void (*func)(void))
{
if (!control->hit) {
diff --git a/threadproc/os2/threadpriv.c b/threadproc/os2/threadpriv.c
index c0f709c31..36a05bc6a 100644
--- a/threadproc/os2/threadpriv.c
+++ b/threadproc/os2/threadpriv.c
@@ -23,7 +23,7 @@
#include "apr_arch_file_io.h"
APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
- void (*dest)(void *),
+ void (*dest)(void *),
apr_pool_t *pool)
{
(*key) = (apr_threadkey_t *)apr_palloc(pool, sizeof(apr_threadkey_t));
@@ -72,8 +72,8 @@ APR_DECLARE(apr_status_t) apr_os_threadkey_get(apr_os_threadkey_t *thekey, apr_t
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
- apr_os_threadkey_t *thekey,
+APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
+ apr_os_threadkey_t *thekey,
apr_pool_t *pool)
{
if (pool == NULL) {
@@ -85,4 +85,4 @@ APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
}
(*key)->key = *thekey;
return APR_SUCCESS;
-}
+}
diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c
index ee05e147d..695c621ec 100644
--- a/threadproc/unix/proc.c
+++ b/threadproc/unix/proc.c
@@ -49,7 +49,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if ((in != APR_NO_PIPE) && (in != APR_NO_FILE)) {
/* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
- * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
+ * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
* the CHILD/PARENT blocking flags for the stdin pipe.
* stdout/stderr map to the correct mode by default.
*/
@@ -220,7 +220,7 @@ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool)
{
int pid;
-
+
memset(proc, 0, sizeof(apr_proc_t));
/* Rekey PRNG(s) to clear buffer(s) and make sure that the
@@ -343,7 +343,7 @@ APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
attr->uid = -1;
return rv;
}
-
+
/* Use default user group if not already set */
if (attr->gid == -1) {
attr->gid = gid;
@@ -548,7 +548,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
default:
{
char *ch, *onearg;
-
+
ch = onearg = apr_palloc(pool, onearg_len);
i = 0;
while (args[i]) {
diff --git a/threadproc/unix/signals.c b/threadproc/unix/signals.c
index 9a83c124c..061d3dc6f 100644
--- a/threadproc/unix/signals.c
+++ b/threadproc/unix/signals.c
@@ -85,7 +85,7 @@ APR_DECLARE(apr_sigfunc_t *) apr_signal(int signo, apr_sigfunc_t * func)
/* XXX jeff thinks this should be enabled whenever SA_NOCLDWAIT is defined */
/* this is required on Tru64 to cause child processes to
- * disappear gracefully - XPG4 compatible
+ * disappear gracefully - XPG4 compatible
*/
if ((signo == SIGCHLD) && (func == SIG_IGN)) {
act.sa_flags |= SA_NOCLDWAIT;
@@ -93,7 +93,7 @@ APR_DECLARE(apr_sigfunc_t *) apr_signal(int signo, apr_sigfunc_t * func)
#endif
#if defined(__NetBSD__) || defined(DARWIN)
/* ignoring SIGCHLD or leaving the default disposition doesn't avoid zombies,
- * and there is no SA_NOCLDWAIT flag, so catch the signal and reap status in
+ * and there is no SA_NOCLDWAIT flag, so catch the signal and reap status in
* the handler to avoid zombies
*/
if ((signo == SIGCHLD) && (func == SIG_IGN)) {
@@ -321,7 +321,7 @@ APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum))
sigfillset(&sig_mask);
/* On certain platforms, sigwait() returns EINVAL if any of various
- * unblockable signals are included in the mask. This was first
+ * unblockable signals are included in the mask. This was first
* observed on AIX and Tru64.
*/
#ifdef SIGKILL
@@ -378,7 +378,7 @@ APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum))
{
/* handle sigwait() error here */
}
-
+
if (sig_func(signal_received) == 1) {
return APR_SUCCESS;
}
@@ -401,7 +401,7 @@ APR_DECLARE(apr_status_t) apr_setup_signal_thread(void)
* No thread should ever block synchronous signals.
* See the Solaris man page for pthread_sigmask() for
* some information. Solaris chooses to knock out such
- * processes when a blocked synchronous signal is
+ * processes when a blocked synchronous signal is
* delivered, skipping any registered signal handler.
* AIX doesn't call a signal handler either. At least
* one level of linux+glibc does call the handler even
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c
index 01d241751..70a7c5d30 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -78,7 +78,7 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
if ((stat = pthread_attr_setdetachstate(&attr->attr, &arg)) == 0) {
#else
- if ((stat = pthread_attr_setdetachstate(&attr->attr,
+ if ((stat = pthread_attr_setdetachstate(&attr->attr,
DETACH_ARG(on))) == 0) {
#endif
return APR_SUCCESS;
@@ -141,6 +141,13 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
#endif
}
+APR_DECLARE(apr_status_t) apr_threadattr_max_free_set(apr_threadattr_t *attr,
+ apr_size_t size)
+{
+ attr->max_free = size;
+ return APR_SUCCESS;
+}
+
#if APR_HAS_THREAD_LOCAL
static APR_THREAD_LOCAL apr_thread_t *current_thread = NULL;
#endif
@@ -170,27 +177,22 @@ static apr_status_t alloc_thread(apr_thread_t **new,
{
apr_status_t stat;
apr_abortfunc_t abort_fn = apr_pool_abort_get(pool);
- apr_allocator_t *allocator;
apr_pool_t *p;
/* The thread can be detached anytime (from the creation or later with
* apr_thread_detach), so it needs its own pool and allocator to not
* depend on a parent pool which could be destroyed before the thread
* exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
+ * not be used nor create children pools outside the thread. Passing
+ * NULL allocator will create one like that.
*/
- stat = apr_allocator_create(&allocator);
+ stat = apr_pool_create_unmanaged_ex(&p, abort_fn, NULL);
if (stat != APR_SUCCESS) {
- if (abort_fn)
- abort_fn(stat);
return stat;
}
- stat = apr_pool_create_unmanaged_ex(&p, abort_fn, allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
+ if (attr && attr->max_free) {
+ apr_allocator_max_free_set(apr_pool_allocator_get(p), attr->max_free);
}
- apr_allocator_owner_set(allocator, p);
(*new) = (apr_thread_t *)apr_pcalloc(p, sizeof(apr_thread_t));
if ((*new) == NULL) {
diff --git a/threadproc/win32/proc.c b/threadproc/win32/proc.c
index 283e19afd..c0df40184 100644
--- a/threadproc/win32/proc.c
+++ b/threadproc/win32/proc.c
@@ -45,7 +45,7 @@ static apr_file_t no_file = { NULL, INVALID_HANDLE_VALUE, };
#define LOGON32_LOGON_NETWORK 3
#endif
-/*
+/*
* some of the ideas expressed herein are based off of Microsoft
* Knowledge Base article: Q190351
*
@@ -60,7 +60,7 @@ APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new,
}
APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
- apr_int32_t in,
+ apr_int32_t in,
apr_int32_t out,
apr_int32_t err)
{
@@ -68,7 +68,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if (in) {
/* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
- * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
+ * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose
* the CHILD/PARENT blocking flags for the stdin pipe.
* stdout/stderr map to the correct mode by default.
*/
@@ -79,7 +79,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if (in == APR_NO_FILE)
attr->child_in = &no_file;
- else {
+ else {
stat = apr_file_pipe_create_ex(&attr->child_in, &attr->parent_in,
in, attr->pool);
}
@@ -89,7 +89,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if (out && stat == APR_SUCCESS) {
if (out == APR_NO_FILE)
attr->child_out = &no_file;
- else {
+ else {
stat = apr_file_pipe_create_ex(&attr->parent_out, &attr->child_out,
out, attr->pool);
}
@@ -99,7 +99,7 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
if (err && stat == APR_SUCCESS) {
if (err == APR_NO_FILE)
attr->child_err = &no_file;
- else {
+ else {
stat = apr_file_pipe_create_ex(&attr->parent_err, &attr->child_err,
err, attr->pool);
}
@@ -109,8 +109,8 @@ APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
return stat;
}
-APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr,
- apr_file_t *child_in,
+APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr,
+ apr_file_t *child_in,
apr_file_t *parent_in)
{
apr_status_t rv = APR_SUCCESS;
@@ -188,24 +188,24 @@ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr,
}
APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
- const char *dir)
+ const char *dir)
{
/* curr dir must be in native format, there are all sorts of bugs in
* the NT library loading code that flunk the '/' parsing test.
*/
- return apr_filepath_merge(&attr->currdir, NULL, dir,
+ return apr_filepath_merge(&attr->currdir, NULL, dir,
APR_FILEPATH_NATIVE, attr->pool);
}
APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
- apr_cmdtype_e cmd)
+ apr_cmdtype_e cmd)
{
attr->cmdtype = cmd;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
- apr_int32_t det)
+ apr_int32_t det)
{
attr->detached = det;
return APR_SUCCESS;
@@ -213,14 +213,14 @@ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
static apr_status_t attr_cleanup(void *theattr)
{
- apr_procattr_t *attr = (apr_procattr_t *)theattr;
+ apr_procattr_t *attr = (apr_procattr_t *)theattr;
if (attr->user_token)
CloseHandle(attr->user_token);
attr->user_token = NULL;
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
+APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
const char *username,
const char *password)
{
@@ -230,14 +230,14 @@ APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
apr_status_t rv;
apr_size_t len, wlen;
- if (apr_os_level >= APR_WIN_NT_4)
+ if (apr_os_level >= APR_WIN_NT_4)
{
if (attr->user_token) {
/* Cannot set that twice */
if (attr->errfn) {
- attr->errfn(attr->pool, 0,
- apr_pstrcat(attr->pool,
- "function called twice"
+ attr->errfn(attr->pool, 0,
+ apr_pstrcat(attr->pool,
+ "function called twice"
" on username: ", username, NULL));
}
return APR_EINVAL;
@@ -248,8 +248,8 @@ APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
if ((rv = apr_conv_utf8_to_utf16(username, &len, wusername, &wlen))
!= APR_SUCCESS) {
if (attr->errfn) {
- attr->errfn(attr->pool, rv,
- apr_pstrcat(attr->pool, "utf8 to utf16 conversion failed"
+ attr->errfn(attr->pool, rv,
+ apr_pstrcat(attr->pool, "utf8 to utf16 conversion failed"
" on username: ", username, NULL));
}
return rv;
@@ -261,26 +261,26 @@ APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
if ((rv = apr_conv_utf8_to_utf16(password, &len, wpassword, &wlen))
!= APR_SUCCESS) {
if (attr->errfn) {
- attr->errfn(attr->pool, rv, "utf8 to utf16 conversion"
+ attr->errfn(attr->pool, rv, "utf8 to utf16 conversion"
" failed on password: <redacted>");
}
return rv;
}
}
- if (!LogonUserW(wusername,
- NULL,
+ if (!LogonUserW(wusername,
+ NULL,
wpassword ? wpassword : L"",
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&user)) {
- /* Logon Failed */
+ /* Logon Failed */
return apr_get_os_error();
}
if (wpassword)
memset(wpassword, 0, wlen * sizeof(apr_wchar_t));
/* Get the primary token for user */
- if (!DuplicateTokenEx(user,
- TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
+ if (!DuplicateTokenEx(user,
+ TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
NULL,
SecurityImpersonation,
TokenPrimary,
@@ -419,25 +419,25 @@ static char *apr_caret_escape_args(apr_pool_t *p, const char *str)
unsigned char *d;
const unsigned char *s;
- cmd = apr_palloc(p, 2 * strlen(str) + 1); /* Be safe */
+ cmd = apr_palloc(p, 2 * strlen(str) + 1); /* Be safe */
d = (unsigned char *)cmd;
s = (const unsigned char *)str;
for (; *s; ++s) {
- /*
+ /*
* Newlines to Win32/OS2 CreateProcess() are ill advised.
* Convert them to spaces since they are effectively white
* space to most applications
*/
- if (*s == '\r' || *s == '\n') {
- *d++ = ' ';
+ if (*s == '\r' || *s == '\n') {
+ *d++ = ' ';
continue;
- }
+ }
- if (IS_SHCHAR(*s)) {
- *d++ = '^';
- }
- *d++ = *s;
+ if (IS_SHCHAR(*s)) {
+ *d++ = '^';
+ }
+ *d++ = *s;
}
*d = '\0';
@@ -503,7 +503,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
apr_size_t i;
const char *argv0;
char *cmdline;
- char *pEnvBlock;
+ apr_wchar_t *pEnvBlock;
PROCESS_INFORMATION pi;
DWORD dwCreationFlags = 0;
@@ -519,14 +519,14 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
* not manage the stdio handles properly when running old 16
* bit executables if the detached attribute is set.
*/
- /*
- * XXX DETACHED_PROCESS won't on Win9x at all; on NT/W2K
+ /*
+ * XXX DETACHED_PROCESS won't on Win9x at all; on NT/W2K
* 16 bit executables fail (MS KB: Q150956)
*/
dwCreationFlags |= DETACHED_PROCESS;
}
- /* progname must be unquoted, in native format, as there are all sorts
+ /* progname must be unquoted, in native format, as there are all sorts
* of bugs in the NT library loader code that fault when parsing '/'.
* XXX progname must be NULL if this is a 16 bit app running in WOW
*/
@@ -536,18 +536,18 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
if (attr->cmdtype == APR_PROGRAM || attr->cmdtype == APR_PROGRAM_ENV) {
char *fullpath = NULL;
- if ((rv = apr_filepath_merge(&fullpath, attr->currdir, progname,
+ 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,
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool, "filepath_merge failed.",
+ " currdir: ", attr->currdir,
" progname: ", progname, NULL));
}
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
@@ -557,10 +557,10 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
* built-in shell command.)
*/
char *fullpath = NULL;
- if ((rv = apr_filepath_merge(&fullpath, "", progname,
+ if ((rv = apr_filepath_merge(&fullpath, "", progname,
APR_FILEPATH_NATIVE, pool)) == APR_SUCCESS) {
progname = fullpath;
- }
+ }
}
if (has_space(progname)) {
@@ -600,8 +600,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
}
cmdline = apr_pstrcat(pool, shellcmd, " /C \"", argv0, cmdline, "\"", NULL);
- }
- else
+ }
+ else
{
/* Win32 is _different_ than unix. While unix will find the given
* program since it's already chdir'ed, Win32 cannot since the parent
@@ -645,7 +645,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
* is not a shellcmd, and the source of argv[] is untrusted.
* Notice we escape ALL the cmdline args, including the quotes
* around the individual args themselves. No sense in allowing
- * the shift-state to be toggled, and the application will
+ * the shift-state to be toggled, and the application will
* not see the caret escapes.
*/
cmdline = apr_caret_escape_args(pool, cmdline);
@@ -690,31 +690,31 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
* Win32's CreateProcess call requires that the environment
* be passed in an environment block, a null terminated block of
* null terminated strings.
- */
+ */
i = 0;
iEnvBlockLen = 1;
while (env[i]) {
iEnvBlockLen += strlen(env[i]) + 1;
i++;
}
- if (!i)
+ if (!i)
++iEnvBlockLen;
{
apr_wchar_t *pNext;
- pEnvBlock = (char *)apr_palloc(pool, iEnvBlockLen * 2);
+ pEnvBlock = apr_palloc(pool, iEnvBlockLen * sizeof(apr_wchar_t));
dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
i = 0;
- pNext = (apr_wchar_t*)pEnvBlock;
+ pNext = pEnvBlock;
while (env[i]) {
apr_size_t in = strlen(env[i]) + 1;
- if ((rv = apr_conv_utf8_to_utf16(env[i], &in,
- pNext, &iEnvBlockLen))
+ if ((rv = apr_conv_utf8_to_utf16(env[i], &in,
+ pNext, &iEnvBlockLen))
!= APR_SUCCESS) {
if (attr->errfn) {
- attr->errfn(pool, rv,
- apr_pstrcat(pool, "utf8 to utf16 conversion failed"
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool, "utf8 to utf16 conversion failed"
" on this string: ", env[i], NULL));
}
return rv;
@@ -722,11 +722,11 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
pNext = wcschr(pNext, L'\0') + 1;
i++;
}
- if (!i)
+ if (!i)
*(pNext++) = L'\0';
- *pNext = L'\0';
+ *pNext = L'\0';
}
- }
+ }
new->invoked = cmdline;
@@ -746,8 +746,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
if ((rv = apr_conv_utf8_to_utf16(progname, &nprg, wprg, &nwprg))
!= APR_SUCCESS) {
if (attr->errfn) {
- attr->errfn(pool, rv,
- apr_pstrcat(pool, "utf8 to utf16 conversion failed"
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool, "utf8 to utf16 conversion failed"
" on progname: ", progname, NULL));
}
return rv;
@@ -761,8 +761,8 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
if ((rv = apr_conv_utf8_to_utf16(cmdline, &ncmd, wcmd, &nwcmd))
!= APR_SUCCESS) {
if (attr->errfn) {
- attr->errfn(pool, rv,
- apr_pstrcat(pool, "utf8 to utf16 conversion failed"
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool, "utf8 to utf16 conversion failed"
" on cmdline: ", cmdline, NULL));
}
return rv;
@@ -774,12 +774,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
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_utf16(attr->currdir, &ncwd,
+ if ((rv = apr_conv_utf8_to_utf16(attr->currdir, &ncwd,
wcwd, &nwcwd))
!= APR_SUCCESS) {
if (attr->errfn) {
- attr->errfn(pool, rv,
- apr_pstrcat(pool, "utf8 to utf16 conversion failed"
+ attr->errfn(pool, rv,
+ apr_pstrcat(pool, "utf8 to utf16 conversion failed"
" on currdir: ", attr->currdir, NULL));
}
return rv;
@@ -794,7 +794,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
si.wShowWindow = SW_HIDE;
}
- /* LOCK CRITICAL SECTION
+ /* LOCK CRITICAL SECTION
* before we begin to manipulate the inherited handles
*/
EnterCriticalSection(&proc_lock);
@@ -814,12 +814,12 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
SetHandleInformation(si.hStdInput,
HANDLE_FLAG_INHERIT, 0);
- if ( (si.hStdInput = attr->child_in->filehand)
+ if ( (si.hStdInput = attr->child_in->filehand)
!= INVALID_HANDLE_VALUE )
SetHandleInformation(si.hStdInput, HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT);
}
-
+
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
if (attr->child_out && attr->child_out->filehand)
{
@@ -829,7 +829,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
SetHandleInformation(si.hStdOutput,
HANDLE_FLAG_INHERIT, 0);
- if ( (si.hStdOutput = attr->child_out->filehand)
+ if ( (si.hStdOutput = attr->child_out->filehand)
!= INVALID_HANDLE_VALUE )
SetHandleInformation(si.hStdOutput, HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT);
@@ -844,7 +844,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
SetHandleInformation(si.hStdError,
HANDLE_FLAG_INHERIT, 0);
- if ( (si.hStdError = attr->child_err->filehand)
+ if ( (si.hStdError = attr->child_err->filehand)
!= INVALID_HANDLE_VALUE )
SetHandleInformation(si.hStdError, HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT);
@@ -852,7 +852,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
}
if (attr->user_token) {
/* XXX: for terminal services, handles can't be cannot be
- * inherited across sessions. This process must be created
+ * inherited across sessions. This process must be created
* in our existing session. lpDesktop assignment appears
* to be wrong according to these rules.
*/
@@ -865,7 +865,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
LeaveCriticalSection(&proc_lock);
return rv;
}
- rv = CreateProcessAsUserW(attr->user_token,
+ if (!CreateProcessAsUserW(attr->user_token,
wprg, wcmd,
attr->sa,
NULL,
@@ -873,18 +873,30 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
dwCreationFlags,
pEnvBlock,
wcwd,
- &si, &pi);
+ &si, &pi)) {
+ /* Save error code. */
+ rv = apr_get_os_error();
+ }
+ else {
+ rv = APR_SUCCESS;
+ }
RevertToSelf();
}
else {
- rv = CreateProcessW(wprg, wcmd, /* Executable & Command line */
+ if (!CreateProcessW(wprg, wcmd, /* Executable & Command line */
NULL, NULL, /* Proc & thread security attributes */
TRUE, /* Inherit handles */
dwCreationFlags, /* Creation flags */
pEnvBlock, /* Environment block */
wcwd, /* Current directory name */
- &si, &pi);
+ &si, &pi)) {
+ /* Save error code. */
+ rv = apr_get_os_error();
+ }
+ else {
+ rv = APR_SUCCESS;
+ }
}
if ((attr->child_in && attr->child_in->filehand)
@@ -903,32 +915,41 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
SetHandleInformation(GetStdHandle(STD_ERROR_HANDLE),
stderr_reset, stderr_reset);
}
- /* RELEASE CRITICAL SECTION
+
+ if (rv == APR_SUCCESS) {
+ /* Close our side of pipes before releasing lock: otherwise they
+ * could like to other process when apr_proc_create() is used from
+ * from multiple threads.
+ */
+ if ((attr->child_in) && (attr->child_in != &no_file)) {
+ apr_file_close(attr->child_in);
+ }
+ if ((attr->child_out) && (attr->child_out != &no_file)) {
+ apr_file_close(attr->child_out);
+ }
+ if ((attr->child_err) && (attr->child_err != &no_file)) {
+ apr_file_close(attr->child_err);
+ }
+ }
+
+ /* RELEASE CRITICAL SECTION
* The state of the inherited handles has been restored.
*/
LeaveCriticalSection(&proc_lock);
}
- /* Check CreateProcess result
+ /* Check CreateProcess result
*/
- if (!rv)
- return apr_get_os_error();
+ if (rv) {
+ return rv;
+ }
/* XXX Orphaned handle warning - no fix due to broken apr_proc_t api.
*/
new->hproc = pi.hProcess;
new->pid = pi.dwProcessId;
- if ((attr->child_in) && (attr->child_in != &no_file)) {
- apr_file_close(attr->child_in);
- }
- if ((attr->child_out) && (attr->child_out != &no_file)) {
- apr_file_close(attr->child_out);
- }
- if ((attr->child_err) && (attr->child_err != &no_file)) {
- apr_file_close(attr->child_err);
- }
CloseHandle(pi.hThread);
return APR_SUCCESS;
@@ -938,7 +959,7 @@ static apr_exit_why_e why_from_exit_code(DWORD exit) {
/* See WinNT.h STATUS_ACCESS_VIOLATION and family for how
* this class of failures was determined
*/
- if (((exit & 0xC0000000) == 0xC0000000)
+ if (((exit & 0xC0000000) == 0xC0000000)
&& !(exit & 0x3FFF0000))
return APR_PROC_SIGNAL;
else
@@ -993,7 +1014,7 @@ APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
else
CloseHandle(hProcess);
}
- else {
+ else {
/* Process has exited.
* No need to wait for its termination.
*/
diff --git a/threadproc/win32/signals.c b/threadproc/win32/signals.c
index 48676d856..15733622a 100644
--- a/threadproc/win32/signals.c
+++ b/threadproc/win32/signals.c
@@ -28,9 +28,9 @@
#include <sys/wait.h>
#endif
-/* Windows only really support killing process, but that will do for now.
+/* Windows only really support killing process, but that will do for now.
*
- * ### Actually, closing the input handle to the proc should also do fine
+ * ### Actually, closing the input handle to the proc should also do fine
* for most console apps. This definitely needs improvement...
*/
APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int signal)
@@ -39,7 +39,7 @@ APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int signal)
if (TerminateProcess(proc->hproc, signal) == 0) {
return apr_get_os_error();
}
- /* On unix, SIGKILL leaves a apr_proc_wait()able pid lying around,
+ /* On unix, SIGKILL leaves a apr_proc_wait()able pid lying around,
* so we will leave hproc alone until the app calls apr_proc_wait().
*/
return APR_SUCCESS;
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c
index 90ee9f1cb..502c317a8 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -23,7 +23,7 @@
#ifdef HAVE_PROCESS_H
#include <process.h>
#endif
-#include "apr_arch_misc.h"
+#include "apr_arch_misc.h"
#include "apr_arch_utf8.h"
/* Chosen for us by apr_initialize */
@@ -32,7 +32,7 @@ DWORD tls_apr_thread = 0;
APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new,
apr_pool_t *pool)
{
- (*new) = (apr_threadattr_t *)apr_palloc(pool,
+ (*new) = (apr_threadattr_t *)apr_palloc(pool,
sizeof(apr_threadattr_t));
if ((*new) == NULL) {
@@ -73,6 +73,13 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
return APR_ENOTIMPL;
}
+APR_DECLARE(apr_status_t) apr_threadattr_max_free_set(apr_threadattr_t *attr,
+ apr_size_t size)
+{
+ attr->max_free = size;
+ return APR_SUCCESS;
+}
+
#if APR_HAS_THREAD_LOCAL
static APR_THREAD_LOCAL apr_thread_t *current_thread = NULL;
#endif
@@ -103,27 +110,22 @@ static apr_status_t alloc_thread(apr_thread_t **new,
{
apr_status_t stat;
apr_abortfunc_t abort_fn = apr_pool_abort_get(pool);
- apr_allocator_t *allocator;
apr_pool_t *p;
/* The thread can be detached anytime (from the creation or later with
* apr_thread_detach), so it needs its own pool and allocator to not
* depend on a parent pool which could be destroyed before the thread
* exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
+ * not be used nor create children pools outside the thread. Passing
+ * NULL allocator will create one like that.
*/
- stat = apr_allocator_create(&allocator);
+ stat = apr_pool_create_unmanaged_ex(&p, abort_fn, NULL);
if (stat != APR_SUCCESS) {
- if (abort_fn)
- abort_fn(stat);
return stat;
}
- stat = apr_pool_create_unmanaged_ex(&p, abort_fn, allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
+ if (attr && attr->max_free) {
+ apr_allocator_max_free_set(apr_pool_allocator_get(p), attr->max_free);
}
- apr_allocator_owner_set(allocator, p);
(*new) = (apr_thread_t *)apr_pcalloc(p, sizeof(apr_thread_t));
if ((*new) == NULL) {
@@ -237,7 +239,7 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
{
apr_status_t rv = APR_SUCCESS;
DWORD ret;
-
+
if (!thd->td) {
/* Can not join on detached threads */
return APR_DETACH;
@@ -382,11 +384,11 @@ APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
if (hthread) {
return hthread;
}
-
+
hproc = GetCurrentProcess();
hthread = GetCurrentThread();
- if (!DuplicateHandle(hproc, hthread,
- hproc, &hthread, 0, FALSE,
+ if (!DuplicateHandle(hproc, hthread,
+ hproc, &hthread, 0, FALSE,
DUPLICATE_SAME_ACCESS)) {
return NULL;
}
diff --git a/threadproc/win32/threadpriv.c b/threadproc/win32/threadpriv.c
index 1cce0c667..f6d0dc2b3 100644
--- a/threadproc/win32/threadpriv.c
+++ b/threadproc/win32/threadpriv.c
@@ -59,7 +59,7 @@ APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv,
APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key)
{
if (TlsFree(key->key)) {
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
return apr_get_os_error();
}
@@ -97,5 +97,5 @@ APR_DECLARE(apr_status_t) apr_os_threadkey_put(apr_threadkey_t **key,
}
(*key)->key = *thekey;
return APR_SUCCESS;
-}
+}