util_mutex.c revision 0c32a43de97332a10a45ca4213339132dd4a3844
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* util_mutex.c: Useful functions for determining allowable
* mutexes and mutex settings
*/
#include "apr.h"
#include "apr_hash.h"
#include "apr_strings.h"
#include "apr_lib.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_main.h"
#include "http_config.h"
#include "http_log.h"
#include "util_mutex.h"
#include "unixd.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* getpid() */
#endif
const char **mutexfile)
{
/* Split arg into meth and file */
if (file) {
*(file++) = '\0';
if (!*file) {
}
}
/* APR determines temporary filename unless overridden below,
* we presume file indicates an mutexfile is a file path
* unless the method sets mutexfile=file and NULLs file
*/
return APR_ENOLOCK;
}
/* NOTE: previously, 'yes' implied 'sem' */
}
}
#endif
}
#endif
* if provided and fall back on APR's default if not. Today, APR
* will ignore it, but once supported it has an absurdly short limit.
*/
if (file) {
}
}
#endif
}
#endif
}
#endif
else {
return APR_ENOTIMPL;
}
/* Unless the method above assumed responsibility for setting up
* mutexfile and NULLing out file, presume it is a file we
* are looking to use
*/
if (file) {
if (!*mutexfile) {
return APR_BADARG;
}
}
return APR_SUCCESS;
}
typedef struct {
int set;
int none;
const char *dir;
} mutex_cfg_t;
/* hash is created the first time a module calls ap_mutex_register(),
* rather than attempting to be the REALLY_REALLY_FIRST pre-config
* hook; it is cleaned up when the associated pool goes away; assume
* pconf is the pool passed to ap_mutex_register()
*/
static apr_hash_t *mxcfg_by_type;
{
return APR_SUCCESS;
}
static void mx_hash_init(apr_pool_t *p)
{
if (mxcfg_by_type) {
return;
}
mxcfg_by_type = apr_hash_make(p);
/* initialize default mutex configuration */
}
{
const char *mutexdir;
return err;
}
if (!mxcfg) {
}
if (rv == APR_ENOTIMPL) {
}
else if (rv == APR_BADARG
return apr_pstrcat(p, "Invalid Mutex directory in argument ",
}
return apr_psprintf(p,
"None is not allowed for mutex type %s",
type);
}
}
else {
if (mutexdir) { /* retain mutex default if not configured */
}
}
return NULL;
}
const char *type,
const char *default_dir,
{
return APR_EINVAL;
}
if (options & AP_MUTEX_DEFAULT_NONE) {
}
return APR_SUCCESS;
}
{
if (mech != APR_LOCK_FLOCK
&& mech != APR_LOCK_FCNTL
&& mech != APR_LOCK_DEFAULT
#endif
) {
return 0;
}
return 1;
}
const char *type,
const char *instance_id)
{
const char *pid_suffix = "";
return NULL;
}
#if HAVE_UNISTD_H
#endif
return ap_server_root_relative(p,
apr_pstrcat(p,
"/",
type,
NULL));
}
{
/* MUST exist in table, or wasn't registered */
if (!mxcfg) {
return NULL;
}
/* order of precedence:
* 1. Mutex directive for this mutex
* 2. Mutex directive for "default"
* 3. Defaults for this mutex from ap_mutex_register()
* 4. Global defaults
*/
}
}
}
else {
}
/* a file-based mutex mechanism was configured, but
* without a mutex file directory; go back through
* the chain to find the directory, store in new
* mutex cfg structure
*/
/* !true if dir not already set: mxcfg->set && defcfg->dir */
}
}
else {
}
}
return newcfg;
}
{
"Invalid options were specified when creating the %s mutex",
type);
}
{
"Can't create mutex of unknown type %s", type);
}
const char *fname)
{
"Couldn't create the %s mutex %s%s%s", type,
}
{
"Couldn't set permissions on the %s mutex; "
"check User and Group directives",
type);
}
const char *type,
const char *instance_id,
server_rec *s, apr_pool_t *p,
{
const char *fname;
if (options) {
return APR_EINVAL;
}
if (!mxcfg) {
log_unknown_type(s, type);
return APR_EINVAL;
}
return APR_SUCCESS;
}
if (rv != APR_SUCCESS) {
return rv;
}
#ifdef AP_NEED_SET_MUTEX_PERMS
if (rv != APR_SUCCESS) {
return rv;
}
#endif
return APR_SUCCESS;
}
const char *type,
const char *instance_id,
server_rec *s, apr_pool_t *p,
{
const char *fname;
if (options) {
return APR_EINVAL;
}
if (!mxcfg) {
log_unknown_type(s, type);
return APR_EINVAL;
}
return APR_SUCCESS;
}
if (rv != APR_SUCCESS) {
return rv;
}
#ifdef AP_NEED_SET_MUTEX_PERMS
if (rv != APR_SUCCESS) {
return rv;
}
#endif
return APR_SUCCESS;
}