You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Elison Smith <el...@gmail.com> on 2009/03/21 06:57:00 UTC
apr_global_mutex_lock() failing with "permission denied"
I am using shared memory to share some data between my module instances in
Apache child processes, and apr_global_mutex_t to achieve
mutually-exclusive reads and writes.
In a post_config_hook, I create the mutex using apr_global_mutex_create()
and then reopen it inside each child process by calling
apr_global_mutex_child_init() inside a child_init hook.
However, when I try to grab the lock inside a child, the operation fails
with a "permission denied". For the lock file, I am using "/tmp/tmp" which
is a file writeable by all.
Any clues?
Re: apr_global_mutex_lock() failing with "permission denied"
Posted by Yoichi Kawasaki <yo...@gmail.com>.
Hi Elison.
2009/3/21 Elison Smith <el...@gmail.com>:
> I am using shared memory to share some data between my module instances in
> Apache child processes, and apr_global_mutex_t to achieve
> mutually-exclusive reads and writes.
>
> In a post_config_hook, I create the mutex using apr_global_mutex_create()
> and then reopen it inside each child process by calling
> apr_global_mutex_child_init() inside a child_init hook.
>
> However, when I try to grab the lock inside a child, the operation fails
> with a "permission denied". For the lock file, I am using "/tmp/tmp" which
> is a file writeable by all.
>
> Any clues?
>
the platform on which your module runs is unix?
There should be such a permission problem if the parent process
starts as root while child processes as user/group that you
specify in apache configuration file.
In that case, use unixd_set_global_mutex_perms in child_init hook,
after apr_global_mutex_create just like this below:
** code snippet from mod_rewrite.c
-------------------------------------------------------------------------
#ifdef AP_NEED_SET_MUTEX_PERMS
#include "unixd.h"
#endif
...
/* create the lockfile */
rc = apr_global_mutex_create(&rewrite_mapr_lock_acquire, lockname,
APR_LOCK_DEFAULT, p);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s,
"mod_rewrite: Parent could not create RewriteLock "
"file %s", lockname);
return rc;
}
#ifdef AP_NEED_SET_MUTEX_PERMS
rc = unixd_set_global_mutex_perms(rewrite_mapr_lock_acquire);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s,
"mod_rewrite: Parent could not set permissions "
"on RewriteLock; check User and Group directives");
return rc;
}
#endif
-------------------------------------------------------------------------
you should also see unixd.h (/path-to-apache/include/unixd.h)
-------------------------------------------------------------------------
/**
* One of the functions to set mutex permissions should be called in
* the parent process on platforms that switch identity when the
* server is started as root.
* If the child init logic is performed before switching identity
* (e.g., MPM setup for an accept mutex), it should only be called
* for SysV semaphores. Otherwise, it is safe to call it for all
* mutex types.
*/
AP_DECLARE(apr_status_t) unixd_set_proc_mutex_perms(apr_proc_mutex_t *pmutex);
AP_DECLARE(apr_status_t)
unixd_set_global_mutex_perms(apr_global_mutex_t *gmutex);
AP_DECLARE(apr_status_t) unixd_accept(void **accepted, ap_listen_rec
*lr, apr_pool_t *ptrans);
-------------------------------------------------------------------------
good luck!
Yoichi
--
--
Yoichi Kawasaki <yo...@gmail.com>