diff options
author | Mladen Turk <mturk@apache.org> | 2009-02-24 12:32:47 +0000 |
---|---|---|
committer | Mladen Turk <mturk@apache.org> | 2009-02-24 12:32:47 +0000 |
commit | 3d15c4a7e109eff8b9de935003112da225db7836 (patch) | |
tree | c0d42d049b189901f48cfea5ae33230cf410cffe /threadproc/unix | |
parent | a21324766d8958b75f528a66e9c33b9a0a185d9c (diff) | |
download | apr-3d15c4a7e109eff8b9de935003112da225db7836.tar.gz |
Remove simple ipc because of -1
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@747357 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc/unix')
-rw-r--r-- | threadproc/unix/proc.c | 191 |
1 files changed, 1 insertions, 190 deletions
diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c index d3181c0db..6c4786653 100644 --- a/threadproc/unix/proc.c +++ b/threadproc/unix/proc.c @@ -19,7 +19,6 @@ #include "apr_portable.h" #include "apr_signal.h" #include "apr_random.h" -#include "apr_arch_proc_mutex.h" /* Heavy on no'ops, here's what we want to pass if there is APR_NO_FILE * requested for a specific child handle; @@ -217,73 +216,6 @@ APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, return APR_SUCCESS; } -APR_DECLARE(apr_status_t) apr_procattr_ipc_data_set(apr_procattr_t *attr, - const void *data, - apr_size_t size) -{ - attr->ipc_data = data; - attr->ipc_size = size; - return APR_SUCCESS; -} - -APR_DECLARE(apr_status_t) apr_procattr_ipc_data_get(apr_procattr_t *attr, - void **data, - apr_size_t *size) -{ - if (attr->ipc_shm && attr->ipc_size) { - *data = apr_shm_baseaddr_get(attr->ipc_shm); - *size = attr->ipc_size; - return APR_SUCCESS; - } - else - return APR_EINIT; -} - -/* Global ipc data setup if we are child - * of the process that used child_data_set - * TODO: This can probably be some struct. - */ -static void *ipc_shm_data = NULL; -static apr_size_t ipc_shm_size = 0; -static int ipc_shm_init = 0; -static apr_pool_t *ipc_pool = NULL; - -static apr_status_t proc_ipc_init() -{ - apr_status_t rv; - char envname[64]; - const char *shmname = NULL; - apr_shm_t *shm; - - if (ipc_shm_init++) - return APR_SUCCESS; - apr_pool_create(&ipc_pool, NULL); - apr_snprintf(envname, sizeof(envname), "_APRIPC%" APR_PID_T_FMT, getpid()); - shmname = getenv(envname); - if (!shmname) - return APR_ENOMEM; - if ((rv = apr_shm_attach(&shm, shmname, ipc_pool)) != APR_SUCCESS) - return rv; - ipc_shm_data = apr_shm_baseaddr_get(shm); - ipc_shm_size = apr_shm_size_get(shm); - return APR_SUCCESS; -} - -APR_DECLARE(apr_status_t) apr_proc_parent_ipc_data_get(void **data, - apr_size_t *size) -{ - if (!ipc_shm_init) { - if (proc_ipc_init() != APR_SUCCESS) - return APR_ENOMEM; - } - if (!ipc_shm_data) - return APR_ENOMEM; - - *data = ipc_shm_data; - *size = ipc_shm_size; - return APR_SUCCESS; -} - APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *pool) { int pid; @@ -421,11 +353,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, apr_pool_t *pool) { int i; - apr_status_t rc = APR_SUCCESS; const char * const empty_envp[] = {NULL}; - apr_proc_mutex_t *ipc_mutex = NULL; - const char *shmname = NULL; - apr_file_t *shmfile = NULL; if (!env) { /* Specs require an empty array instead of NULL; * Purify will trigger a failure, even if many @@ -464,40 +392,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } } - if (attr->ipc_data && attr->ipc_size) { - const char *tempdir; - char *template; - - rc = apr_temp_dir_get(&tempdir, pool); - if (rc != APR_SUCCESS) { - return rc; - } - apr_filepath_merge(&template, tempdir, - "apr.ipc.XXXXXX", - APR_FILEPATH_NATIVE, pool); - rc = apr_file_mktemp(&shmfile, template, 0, pool); - if (rc != APR_SUCCESS) { - return rc; - } - rc = apr_file_name_get(&shmname, shmfile); - if (rc != APR_SUCCESS) { - return rc; - } - /* Create startup ipc mutex. - * The purpose of this mutex is to enable - * the 'start suspended' process behaviour. - * We need to create the shared memory after - * fork() and we don't know in advance what - * the child pid will be. Mutex locks the child - * until we create the shared memory which - * can be then attached at child's apr_initialize. - */ - if ((rc = apr_proc_mutex_create(&ipc_mutex, NULL, - APR_LOCK_DEFAULT, attr->pool)) != APR_SUCCESS) { - return rc; - } - apr_proc_mutex_lock(ipc_mutex); - } if ((new->pid = fork()) < 0) { return errno; } @@ -505,58 +399,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, int status; /* child process */ - if (ipc_mutex) { - char *env0; - if ((rc = apr_proc_mutex_child_init(&ipc_mutex, - NULL, pool)) != APR_SUCCESS) { - /* This should never happen. - * We cannot continue. - */ - if (attr->errfn) { - attr->errfn(pool, rc, "ipc mutex init failed"); - } - _exit(-1); - } - /* Wait util the parent initializes shared memory. - */ - if ((rc = apr_proc_mutex_lock(ipc_mutex)) != APR_SUCCESS) { - /* Locking failed. - * Probably the parent ended prematurely - */ - if (attr->errfn) { - attr->errfn(pool, rc, "ipc mutex lock failed"); - } - _exit(-1); - } - env0 = apr_psprintf(pool, "_APRIPC%" APR_PID_T_FMT "=%s", - getpid(), shmname); - putenv(env0); - if (!env) { - const char const *newenv[2]; - newenv[0] = env0; - newenv[1] = NULL; - env = newenv; - } - else { - const char **newenv; - i = 0; - while (env[i]) - i++; - newenv = apr_palloc(pool, sizeof(char *) * (i + 1)); - newenv[0] = env0; - i = 0; - while (env[i]) { - newenv[i + 1] = env[i]; - i++; - } - env = newenv; - } - - /* By now we should have the ipc shared memory set up. - * We don't need the mutex any more. - */ - apr_proc_mutex_destroy(ipc_mutex); - } /* * If we do exec cleanup before the dup2() calls to set up pipes * on 0-2, we accidentally close the pipes used by programs like @@ -613,7 +455,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, apr_signal(SIGCHLD, SIG_DFL); /* not sure if this is needed or not */ - if (attr->currdir != NULL) { if (chdir(attr->currdir) == -1) { if (attr->errfn) { @@ -753,36 +594,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, _exit(-1); /* if we get here, there is a problem, so exit with an * error code. */ } - if (ipc_mutex) { - apr_file_close(shmfile); - rc = apr_shm_create(&attr->ipc_shm, attr->ipc_size, - shmname, attr->pool); - if (rc == APR_SUCCESS) { - if (!geteuid()) { - /* Set ipc shared memory permissions for - * our child process. - */ - APR_PERMS_SET_FN(shm)(attr->ipc_shm, - APR_FPROT_UREAD | APR_FPROT_UWRITE, - attr->uid, attr->gid); - } - /* Fill in shared memory with ipc data */ - memcpy(apr_shm_baseaddr_get(attr->ipc_shm), - attr->ipc_data, attr->ipc_size); - /* Unlock the ipc startup mutex. - * This mutex is destroyed when attr->pool is cleared - * or destroyed because it might not yet be initialised - * inside the child. - */ - apr_proc_mutex_unlock(ipc_mutex); - } - else { - /* Destroy the mutex. - * This will cause the forked child to exit. - */ - apr_proc_mutex_destroy(ipc_mutex); - } - } /* Parent process */ if (attr->child_in && (attr->child_in->filedes != -1)) { @@ -797,7 +608,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, apr_file_close(attr->child_err); } - return rc; + return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc, |