Replace semaphores/benaphores in the env, fork, and user/group code by lazy
mutexes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34340 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,7 +4,7 @@ UsePrivateHeaders app shared [ FDirName syslog_daemon ] ;
|
|||||||
UsePrivateSystemHeaders ;
|
UsePrivateSystemHeaders ;
|
||||||
UsePrivateHeaders kernel ;
|
UsePrivateHeaders kernel ;
|
||||||
# For util/KMessage.h
|
# For util/KMessage.h
|
||||||
UsePrivateHeaders libroot runtime_loader ;
|
UsePrivateHeaders libroot runtime_loader shared ;
|
||||||
|
|
||||||
if $(HAIKU_MULTIUSER_QUERY) = 1 {
|
if $(HAIKU_MULTIUSER_QUERY) = 1 {
|
||||||
PWD_BACKEND = pwd_query.c ;
|
PWD_BACKEND = pwd_query.c ;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
SubDir HAIKU_TOP src system libroot posix stdlib ;
|
SubDir HAIKU_TOP src system libroot posix stdlib ;
|
||||||
|
|
||||||
UsePrivateHeaders drivers libroot runtime_loader ;
|
UsePrivateHeaders drivers libroot runtime_loader shared ;
|
||||||
UsePrivateSystemHeaders ;
|
UsePrivateSystemHeaders ;
|
||||||
|
|
||||||
MergeObject posix_stdlib.o :
|
MergeObject posix_stdlib.o :
|
||||||
|
|||||||
@@ -11,21 +11,14 @@
|
|||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
#include <libroot_lock.h>
|
|
||||||
#include <libroot_private.h>
|
#include <libroot_private.h>
|
||||||
|
#include <locks.h>
|
||||||
#include <runtime_loader.h>
|
#include <runtime_loader.h>
|
||||||
|
#include <syscall_utils.h>
|
||||||
#include <user_runtime.h>
|
#include <user_runtime.h>
|
||||||
|
|
||||||
|
|
||||||
#define RETURN_AND_SET_ERRNO(err) \
|
static lazy_mutex sEnvLock;
|
||||||
if (err < 0) { \
|
|
||||||
errno = err; \
|
|
||||||
return -1; \
|
|
||||||
} \
|
|
||||||
return err;
|
|
||||||
|
|
||||||
|
|
||||||
static benaphore sEnvLock;
|
|
||||||
static char **sManagedEnviron;
|
static char **sManagedEnviron;
|
||||||
|
|
||||||
char **environ = NULL;
|
char **environ = NULL;
|
||||||
@@ -34,14 +27,14 @@ char **environ = NULL;
|
|||||||
static inline void
|
static inline void
|
||||||
lock_variables(void)
|
lock_variables(void)
|
||||||
{
|
{
|
||||||
benaphore_lock(&sEnvLock);
|
lazy_mutex_lock(&sEnvLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
unlock_variables(void)
|
unlock_variables(void)
|
||||||
{
|
{
|
||||||
benaphore_unlock(&sEnvLock);
|
lazy_mutex_unlock(&sEnvLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,7 +186,7 @@ update_variable(const char *name, int32 length, const char *value,
|
|||||||
static void
|
static void
|
||||||
environ_fork_hook(void)
|
environ_fork_hook(void)
|
||||||
{
|
{
|
||||||
benaphore_init(&sEnvLock, "env lock");
|
lazy_mutex_init(&sEnvLock, "env lock");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -206,7 +199,7 @@ __init_env(const struct user_space_program_args *args)
|
|||||||
// Following POSIX, there is no need to make any of the environment
|
// Following POSIX, there is no need to make any of the environment
|
||||||
// functions thread-safe - but we do it anyway as much as possible to
|
// functions thread-safe - but we do it anyway as much as possible to
|
||||||
// protect our implementation
|
// protect our implementation
|
||||||
benaphore_init(&sEnvLock, "env lock");
|
lazy_mutex_init(&sEnvLock, "env lock");
|
||||||
environ = args->env;
|
environ = args->env;
|
||||||
sManagedEnviron = NULL;
|
sManagedEnviron = NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <locks.h>
|
||||||
#include <libroot_private.h>
|
#include <libroot_private.h>
|
||||||
#include <runtime_loader.h>
|
#include <runtime_loader.h>
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
@@ -22,7 +23,7 @@ typedef struct fork_hook {
|
|||||||
|
|
||||||
static fork_hook *sPrepareHooks, *sParentHooks, *sChildHooks;
|
static fork_hook *sPrepareHooks, *sParentHooks, *sChildHooks;
|
||||||
static fork_hook *sLastParentHook, *sLastChildHook;
|
static fork_hook *sLastParentHook, *sLastChildHook;
|
||||||
static sem_id sForkLock;
|
static lazy_mutex sForkLock;
|
||||||
|
|
||||||
extern thread_id __main_thread_id;
|
extern thread_id __main_thread_id;
|
||||||
|
|
||||||
@@ -95,10 +96,7 @@ call_fork_hooks(fork_hook *hook)
|
|||||||
status_t
|
status_t
|
||||||
__init_fork(void)
|
__init_fork(void)
|
||||||
{
|
{
|
||||||
sForkLock = create_sem(1, "fork lock");
|
lazy_mutex_init(&sForkLock, "fork lock");
|
||||||
if (sForkLock < B_OK)
|
|
||||||
return sForkLock;
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,9 +109,7 @@ __init_fork(void)
|
|||||||
status_t
|
status_t
|
||||||
__register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
|
__register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
|
||||||
{
|
{
|
||||||
status_t status;
|
status_t status = lazy_mutex_lock(&sForkLock);
|
||||||
|
|
||||||
while ((status = acquire_sem(sForkLock)) == B_INTERRUPTED);
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -126,7 +122,7 @@ __register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(voi
|
|||||||
if (status == B_OK && child)
|
if (status == B_OK && child)
|
||||||
status = add_fork_hook(&sChildHooks, &sLastChildHook, child);
|
status = add_fork_hook(&sChildHooks, &sLastChildHook, child);
|
||||||
|
|
||||||
release_sem(sForkLock);
|
lazy_mutex_unlock(&sForkLock);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +133,7 @@ fork(void)
|
|||||||
thread_id thread;
|
thread_id thread;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
while ((status = acquire_sem(sForkLock)) == B_INTERRUPTED);
|
status = lazy_mutex_lock(&sForkLock);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -147,7 +143,7 @@ fork(void)
|
|||||||
thread = _kern_fork();
|
thread = _kern_fork();
|
||||||
if (thread < 0) {
|
if (thread < 0) {
|
||||||
// something went wrong
|
// something went wrong
|
||||||
release_sem(sForkLock);
|
lazy_mutex_unlock(&sForkLock);
|
||||||
errno = thread;
|
errno = thread;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -164,7 +160,7 @@ fork(void)
|
|||||||
} else {
|
} else {
|
||||||
// we are the parent
|
// we are the parent
|
||||||
call_fork_hooks(sParentHooks);
|
call_fork_hooks(sParentHooks);
|
||||||
release_sem(sForkLock);
|
lazy_mutex_unlock(&sForkLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <libroot_lock.h>
|
|
||||||
#include <libroot_private.h>
|
#include <libroot_private.h>
|
||||||
|
#include <locks.h>
|
||||||
#include <RegistrarDefs.h>
|
#include <RegistrarDefs.h>
|
||||||
|
|
||||||
#include <util/KMessage.h>
|
#include <util/KMessage.h>
|
||||||
@@ -28,21 +28,22 @@ const char* BPrivate::kPasswdFile = "/etc/passwd";
|
|||||||
const char* BPrivate::kGroupFile = "/etc/group";
|
const char* BPrivate::kGroupFile = "/etc/group";
|
||||||
const char* BPrivate::kShadowPwdFile = "/etc/shadow";
|
const char* BPrivate::kShadowPwdFile = "/etc/shadow";
|
||||||
|
|
||||||
static benaphore sUserGroupLock;
|
static lazy_mutex sUserGroupLock;
|
||||||
static port_id sRegistrarPort = -1;
|
static port_id sRegistrarPort = -1;
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPrivate::user_group_lock()
|
BPrivate::user_group_lock()
|
||||||
{
|
{
|
||||||
return benaphore_lock(&sUserGroupLock);
|
return lazy_mutex_lock(&sUserGroupLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPrivate::user_group_unlock()
|
BPrivate::user_group_unlock()
|
||||||
{
|
{
|
||||||
return benaphore_unlock(&sUserGroupLock);
|
lazy_mutex_unlock(&sUserGroupLock);
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -384,12 +385,12 @@ BPrivate::parse_shadow_pwd_line(char* line, char*& name, char*& password,
|
|||||||
void
|
void
|
||||||
__init_pwd_backend(void)
|
__init_pwd_backend(void)
|
||||||
{
|
{
|
||||||
benaphore_init(&sUserGroupLock, "user group");
|
lazy_mutex_init(&sUserGroupLock, "user group");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
__reinit_pwd_backend_after_fork(void)
|
__reinit_pwd_backend_after_fork(void)
|
||||||
{
|
{
|
||||||
benaphore_init(&sUserGroupLock, "user group");
|
lazy_mutex_init(&sUserGroupLock, "user group");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user