summaryrefslogtreecommitdiff
path: root/locks
diff options
context:
space:
mode:
authorrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2001-09-24 05:41:57 +0000
committerrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2001-09-24 05:41:57 +0000
commit3f30404584064f4837a5cf06459ef504232b5617 (patch)
treee34e93e845eb991ef8372608a36a01fc2d0dc206 /locks
parent048270c5f60e0c1b6ae9ceded824da40f46d3be8 (diff)
downloadlibapr-3f30404584064f4837a5cf06459ef504232b5617.tar.gz
Add the apr_file_mktemp function. This creates and opens a
temporary file, for use by the program. This file is created delete_on_close. The initial implementation only works on Unix, but Windows is coming soon. This also modifies all of the process lock functions that need a temporary file to use the new apr_file_mktemp function. Submitted by: Ryan Bloom git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62368 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r--locks/unix/crossproc.c51
-rw-r--r--locks/unix/locks.c6
-rw-r--r--locks/unix/proc_mutex.c65
3 files changed, 71 insertions, 51 deletions
diff --git a/locks/unix/crossproc.c b/locks/unix/crossproc.c
index f555b2a21..2ed15f3ad 100644
--- a/locks/unix/crossproc.c
+++ b/locks/unix/crossproc.c
@@ -53,6 +53,7 @@
*/
#include "apr.h"
+#include "apr_file_io.h"
#include "apr_strings.h"
#include "locks.h"
#include "fileio.h" /* for apr_mkstemp() */
@@ -77,9 +78,9 @@ static apr_status_t sysv_cleanup(void *lock_)
apr_lock_t *lock=lock_;
union semun ick;
- if (lock->interproc != -1) {
+ if (lock->interproc->filedes != -1) {
ick.val = 0;
- semctl(lock->interproc, 0, IPC_RMID, ick);
+ semctl(lock->interproc->filedes, 0, IPC_RMID, ick);
}
return APR_SUCCESS;
}
@@ -89,15 +90,16 @@ static apr_status_t sysv_create(apr_lock_t *new, const char *fname)
union semun ick;
apr_status_t stat;
- new->interproc = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
+ new->interproc = apr_palloc(new->pool, sizeof(*new->interproc));
+ new->interproc->filedes = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
- if (new->interproc < 0) {
+ if (new->interproc->filedes < 0) {
stat = errno;
sysv_cleanup(new);
return stat;
}
ick.val = 1;
- if (semctl(new->interproc, 0, SETVAL, ick) < 0) {
+ if (semctl(new->interproc->filedes, 0, SETVAL, ick) < 0) {
stat = errno;
sysv_cleanup(new);
return stat;
@@ -113,7 +115,7 @@ static apr_status_t sysv_acquire(apr_lock_t *lock)
int rc;
do {
- rc = semop(lock->interproc, &op_on, 1);
+ rc = semop(lock->interproc->filedes, &op_on, 1);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -127,7 +129,7 @@ static apr_status_t sysv_release(apr_lock_t *lock)
int rc;
do {
- rc = semop(lock->interproc, &op_off, 1);
+ rc = semop(lock->interproc->filedes, &op_off, 1);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -369,23 +371,25 @@ static apr_status_t fcntl_cleanup(void *lock_)
if (status != APR_SUCCESS)
return status;
}
- close(lock->interproc);
return APR_SUCCESS;
}
static apr_status_t fcntl_create(apr_lock_t *new, const char *fname)
{
+ int rv;
+
if (fname) {
new->fname = apr_pstrdup(new->pool, fname);
- new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
+ rv = apr_file_open(&new->interproc, new->fname,
+ APR_CREATE | APR_WRITE | APR_EXCL, 0644, new->pool);
}
else {
new->fname = apr_pstrdup(new->pool, "/tmp/aprXXXXXX");
- new->interproc = apr_mkstemp(new->fname);
+ rv = apr_file_mktemp(&new->interproc, new->fname, new->pool);
}
- if (new->interproc < 0) {
+ if (rv != APR_SUCCESS) {
apr_status_t stat = errno;
fcntl_cleanup(new);
@@ -404,7 +408,7 @@ static apr_status_t fcntl_acquire(apr_lock_t *lock)
int rc;
do {
- rc = fcntl(lock->interproc, F_SETLKW, &lock_it);
+ rc = fcntl(lock->interproc->filedes, F_SETLKW, &lock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -418,7 +422,7 @@ static apr_status_t fcntl_release(apr_lock_t *lock)
int rc;
do {
- rc = fcntl(lock->interproc, F_SETLKW, &unlock_it);
+ rc = fcntl(lock->interproc->filedes, F_SETLKW, &unlock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -480,23 +484,26 @@ static apr_status_t flock_cleanup(void *lock_)
if (status != APR_SUCCESS)
return status;
}
- close(lock->interproc);
+ apr_file_close(lock->interproc);
unlink(lock->fname);
return APR_SUCCESS;
}
static apr_status_t flock_create(apr_lock_t *new, const char *fname)
{
+ int rv;
+
if (fname) {
new->fname = apr_pstrdup(new->pool, fname);
- new->interproc = open(new->fname, O_CREAT | O_WRONLY | O_EXCL, 0600);
+ rv = apr_file_open(&new->interproc, new->fname,
+ APR_CREATE | APR_WRITE | APR_EXCL, 0644, new->pool);
}
else {
new->fname = apr_pstrdup(new->pool, "/tmp/aprXXXXXX");
- new->interproc = apr_mkstemp(new->fname);
+ rv = apr_file_mktemp(&new->interproc, new->fname, new->pool);
}
- if (new->interproc < 0) {
+ if (rv != APR_SUCCESS) {
apr_status_t stat = errno;
flock_cleanup(new);
@@ -513,7 +520,7 @@ static apr_status_t flock_acquire(apr_lock_t *lock)
int rc;
do {
- rc = flock(lock->interproc, LOCK_EX);
+ rc = flock(lock->interproc->filedes, LOCK_EX);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -527,7 +534,7 @@ static apr_status_t flock_release(apr_lock_t *lock)
int rc;
do {
- rc = flock(lock->interproc, LOCK_UN);
+ rc = flock(lock->interproc->filedes, LOCK_UN);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -550,14 +557,16 @@ static apr_status_t flock_child_init(apr_lock_t **lock, apr_pool_t *cont,
const char *fname)
{
apr_lock_t *new;
+ int rv;
new = (apr_lock_t *)apr_palloc(cont, sizeof(apr_lock_t));
memcpy(new, *lock, sizeof *new);
new->pool = cont;
new->fname = apr_pstrdup(cont, fname);
- new->interproc = open(new->fname, O_WRONLY, 0600);
- if (new->interproc == -1) {
+ rv = apr_file_open(&new->interproc, new->fname,
+ APR_CREATE | APR_WRITE, 0600, new->pool);
+ if (rv != APR_SUCCESS) {
apr_status_t stat = errno;
flock_destroy(new);
diff --git a/locks/unix/locks.c b/locks/unix/locks.c
index fe96abea6..7e5d3b69e 100644
--- a/locks/unix/locks.c
+++ b/locks/unix/locks.c
@@ -243,7 +243,7 @@ APR_DECLARE(apr_status_t) apr_lock_create_np(apr_lock_t **lock, apr_locktype_e t
new->type = type;
new->scope = scope;
#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
- new->interproc = -1;
+ new->interproc = NULL;
#endif
if ((stat = create_lock(new, mech, fname)) != APR_SUCCESS)
@@ -370,7 +370,7 @@ APR_DECLARE(apr_status_t) apr_lock_data_set(apr_lock_t *lock, void *data, const
APR_DECLARE(apr_status_t) apr_os_lock_get(apr_os_lock_t *oslock, apr_lock_t *lock)
{
#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
- oslock->crossproc = lock->interproc;
+ oslock->crossproc = lock->interproc->filedes;
#endif
#if APR_HAS_PROC_PTHREAD_SERIALIZE
oslock->pthread_interproc = lock->pthread_interproc;
@@ -395,7 +395,7 @@ APR_DECLARE(apr_status_t) apr_os_lock_put(apr_lock_t **lock, apr_os_lock_t *thel
(*lock)->pool = pool;
}
#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
- (*lock)->interproc = thelock->crossproc;
+ apr_os_file_put(&(*lock)->interproc, &thelock->crossproc, pool);
#endif
#if APR_HAS_PROC_PTHREAD_SERIALIZE
(*lock)->pthread_interproc = thelock->pthread_interproc;
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c
index 037b5a160..125a9b26f 100644
--- a/locks/unix/proc_mutex.c
+++ b/locks/unix/proc_mutex.c
@@ -77,9 +77,9 @@ static apr_status_t proc_mutex_sysv_cleanup(void *mutex_)
apr_proc_mutex_t *mutex=mutex_;
union semun ick;
- if (mutex->interproc != -1) {
+ if (mutex->interproc->filedes != -1) {
ick.val = 0;
- semctl(mutex->interproc, 0, IPC_RMID, ick);
+ semctl(mutex->interproc->filedes, 0, IPC_RMID, ick);
}
return APR_SUCCESS;
}
@@ -90,15 +90,16 @@ static apr_status_t proc_mutex_sysv_create(apr_proc_mutex_t *new_mutex,
union semun ick;
apr_status_t stat;
- new_mutex->interproc = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
+ new_mutex->interproc = apr_palloc(new_mutex->pool, sizeof(*new_mutex->interproc));
+ new_mutex->interproc->filedes = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
- if (new_mutex->interproc < 0) {
+ if (new_mutex->interproc->filedes < 0) {
stat = errno;
proc_mutex_sysv_cleanup(new_mutex);
return stat;
}
ick.val = 1;
- if (semctl(new_mutex->interproc, 0, SETVAL, ick) < 0) {
+ if (semctl(new_mutex->interproc->filedes, 0, SETVAL, ick) < 0) {
stat = errno;
proc_mutex_sysv_cleanup(new_mutex);
return stat;
@@ -115,7 +116,7 @@ static apr_status_t proc_mutex_sysv_acquire(apr_proc_mutex_t *mutex)
int rc;
do {
- rc = semop(mutex->interproc, &proc_mutex_op_on, 1);
+ rc = semop(mutex->interproc->filedes, &proc_mutex_op_on, 1);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -129,7 +130,7 @@ static apr_status_t proc_mutex_sysv_release(apr_proc_mutex_t *mutex)
int rc;
do {
- rc = semop(mutex->interproc, &proc_mutex_op_off, 1);
+ rc = semop(mutex->interproc->filedes, &proc_mutex_op_off, 1);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -376,7 +377,7 @@ static apr_status_t proc_mutex_fcntl_cleanup(void *mutex_)
if (status != APR_SUCCESS)
return status;
}
- close(mutex->interproc);
+ apr_file_close(mutex->interproc);
return APR_SUCCESS;
}
@@ -384,23 +385,27 @@ static apr_status_t proc_mutex_fcntl_cleanup(void *mutex_)
static apr_status_t proc_mutex_fcntl_create(apr_proc_mutex_t *new_mutex,
const char *fname)
{
+ int rv;
+
if (fname) {
new_mutex->fname = apr_pstrdup(new_mutex->pool, fname);
- new_mutex->interproc = open(new_mutex->fname,
- O_CREAT | O_WRONLY | O_EXCL, 0644);
+ rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
+ APR_CREATE | APR_WRITE | APR_EXCL, 0644,
+ new_mutex->pool);
}
else {
new_mutex->fname = apr_pstrdup(new_mutex->pool, "/tmp/aprXXXXXX");
- new_mutex->interproc = apr_mkstemp(new_mutex->fname);
+ rv = apr_file_mktemp(&new_mutex->interproc, new_mutex->fname,
+ new_mutex->pool);
}
-
- if (new_mutex->interproc < 0) {
+
+ if (rv != APR_SUCCESS) {
proc_mutex_fcntl_cleanup(new_mutex);
return errno;
}
new_mutex->curr_locked = 0;
- unlink(new_mutex->fname);
+/* unlink(new_mutex->fname); */
apr_pool_cleanup_register(new_mutex->pool,
(void*)new_mutex,
proc_mutex_fcntl_cleanup,
@@ -413,7 +418,7 @@ static apr_status_t proc_mutex_fcntl_acquire(apr_proc_mutex_t *mutex)
int rc;
do {
- rc = fcntl(mutex->interproc, F_SETLKW, &proc_mutex_lock_it);
+ rc = fcntl(mutex->interproc->filedes, F_SETLKW, &proc_mutex_lock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -427,7 +432,7 @@ static apr_status_t proc_mutex_fcntl_release(apr_proc_mutex_t *mutex)
int rc;
do {
- rc = fcntl(mutex->interproc, F_SETLKW, &proc_mutex_unlock_it);
+ rc = fcntl(mutex->interproc->filedes, F_SETLKW, &proc_mutex_unlock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -488,7 +493,7 @@ static apr_status_t proc_mutex_flock_cleanup(void *mutex_)
if (status != APR_SUCCESS)
return status;
}
- close(mutex->interproc);
+ apr_file_close(mutex->interproc);
unlink(mutex->fname);
return APR_SUCCESS;
}
@@ -496,17 +501,21 @@ static apr_status_t proc_mutex_flock_cleanup(void *mutex_)
static apr_status_t proc_mutex_flock_create(apr_proc_mutex_t *new_mutex,
const char *fname)
{
+ int rv;
+
if (fname) {
new_mutex->fname = apr_pstrdup(new_mutex->pool, fname);
- new_mutex->interproc = open(new_mutex->fname,
- O_CREAT | O_WRONLY | O_EXCL, 0600);
+ rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
+ APR_CREATE | APR_WRITE | APR_EXCL, 0644,
+ new_mutex->pool);
}
else {
new_mutex->fname = apr_pstrdup(new_mutex->pool, "/tmp/aprXXXXXX");
- new_mutex->interproc = apr_mkstemp(new_mutex->fname);
+ rv = apr_file_mktemp(&new_mutex->interproc, new_mutex->fname,
+ new_mutex->pool);
}
-
- if (new_mutex->interproc < 0) {
+
+ if (rv != APR_SUCCESS) {
proc_mutex_flock_cleanup(new_mutex);
return errno;
}
@@ -522,7 +531,7 @@ static apr_status_t proc_mutex_flock_acquire(apr_proc_mutex_t *mutex)
int rc;
do {
- rc = flock(mutex->interproc, LOCK_EX);
+ rc = flock(mutex->interproc->filedes, LOCK_EX);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -536,7 +545,7 @@ static apr_status_t proc_mutex_flock_release(apr_proc_mutex_t *mutex)
int rc;
do {
- rc = flock(mutex->interproc, LOCK_UN);
+ rc = flock(mutex->interproc->filedes, LOCK_UN);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
@@ -560,14 +569,16 @@ static apr_status_t proc_mutex_flock_child_init(apr_proc_mutex_t **mutex,
const char *fname)
{
apr_proc_mutex_t *new_mutex;
+ int rv;
new_mutex = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
memcpy(new_mutex, *mutex, sizeof *new_mutex);
new_mutex->pool = pool;
new_mutex->fname = apr_pstrdup(pool, fname);
- new_mutex->interproc = open(new_mutex->fname, O_WRONLY, 0600);
- if (new_mutex->interproc == -1) {
+ rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
+ APR_CREATE | APR_WRITE, 0600, new_mutex->pool);
+ if (rv != APR_SUCCESS) {
proc_mutex_flock_destroy(new_mutex);
return errno;
}
@@ -705,7 +716,7 @@ APR_DECLARE(apr_status_t) apr_proc_mutex_create_np(apr_proc_mutex_t **mutex,
new_mutex->pool = pool;
#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
- new_mutex->interproc = -1;
+ new_mutex->interproc = NULL;
#endif
if ((stat = proc_mutex_create(new_mutex, mech, fname)) != APR_SUCCESS)