summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/sd-bus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-05-17 03:13:58 +0200
committerLennart Poettering <lennart@poettering.net>2013-05-17 04:26:27 +0200
commit45fbe937d7ca8d0da9ea276d57bc70ebd41c285e (patch)
tree95b216605530430206c7d863bca4d1d610382d25 /src/libsystemd-bus/sd-bus.c
parentd5a2b9a6f455468a0f29483303657ab4fd7013d8 (diff)
bus: add minimal locking around the memfd cache
We want to allow clients to process an sd_bus_message on a different thread than it was received on. Since unreffing a bus message might readd some of its memfds to the memfd cache add some minimal locking around the cache.
Diffstat (limited to 'src/libsystemd-bus/sd-bus.c')
-rw-r--r--src/libsystemd-bus/sd-bus.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index fd19ff32b0..5e66a31162 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -27,6 +27,7 @@
#include <sys/poll.h>
#include <byteswap.h>
#include <sys/mman.h>
+#include <pthread.h>
#include "util.h"
#include "macro.h"
@@ -106,6 +107,8 @@ static void bus_free(sd_bus *b) {
bus_kernel_flush_memfd(b);
+ assert_se(pthread_mutex_destroy(&b->memfd_cache_mutex) == 0);
+
free(b);
}
@@ -125,6 +128,8 @@ int sd_bus_new(sd_bus **ret) {
r->negotiate_fds = true;
r->original_pid = getpid();
+ assert_se(pthread_mutex_init(&r->memfd_cache_mutex, NULL) == 0);
+
/* We guarantee that wqueue always has space for at least one
* entry */
r->wqueue = new(sd_bus_message*, 1);