summaryrefslogtreecommitdiff
path: root/dbus/dbus-userdb-util.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-04-16 16:28:44 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-06-17 17:00:00 +0100
commit2b3272c75ae48c93911bd6f656965cf77d6de3e8 (patch)
treec612839ca6bf80883028d7e39c7c894d8c56b900 /dbus/dbus-userdb-util.c
parentc80c20af46c5f43dcbe672f2c6d8aec0e7f2bbd6 (diff)
downloaddbus-2b3272c75ae48c93911bd6f656965cf77d6de3e8.tar.gz
Make taking a global lock automatically initialize locking if needed
This lets them be thread-safe by default, at the cost that they can now fail. init_uninitialized_locks() and init_global_locks() must now both reimplement the equivalent of _dbus_register_shutdown_func(), by using _dbus_platform_rmutex_lock() on the same underlying mutex around a call to _dbus_register_shutdown_func_unlocked(). This is because if they used the usual _DBUS_LOCK() API (as _dbus_register_shutdown_func() does), it would automatically try to initialize global locking, leading to infinite recursion. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk> Reviewed-by: Anas Nashif <anas.nashif@intel.com>
Diffstat (limited to 'dbus/dbus-userdb-util.c')
-rw-r--r--dbus/dbus-userdb-util.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/dbus/dbus-userdb-util.c b/dbus/dbus-userdb-util.c
index 5af00922..38ea4ef0 100644
--- a/dbus/dbus-userdb-util.c
+++ b/dbus/dbus-userdb-util.c
@@ -104,7 +104,11 @@ _dbus_is_console_user (dbus_uid_t uid,
#endif /* HAVE_CONSOLE_OWNER_FILE */
- _dbus_user_database_lock_system ();
+ if (!_dbus_user_database_lock_system ())
+ {
+ _DBUS_SET_OOM (error);
+ return FALSE;
+ }
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -158,7 +162,10 @@ _dbus_get_group_id (const DBusString *groupname,
{
DBusUserDatabase *db;
const DBusGroupInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -195,7 +202,10 @@ _dbus_get_user_id_and_primary_group (const DBusString *username,
{
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -388,7 +398,9 @@ _dbus_groups_from_uid (dbus_uid_t uid,
*group_ids = NULL;
*n_group_ids = 0;
- _dbus_user_database_lock_system ();
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)