aboutsummaryrefslogtreecommitdiffstats
path: root/src/systemd.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2019-02-14 09:37:26 +0100
committerJose Bollo <jose.bollo@iot.bzh>2019-03-27 10:48:40 +0100
commitc330ecf92fef81fdb0471715326b8bc6b4d52bc6 (patch)
treeb403a04b9035d326ff97f6b58f1a51e58014fe59 /src/systemd.c
parentd7e4faba5d1744160d538edd74bc4bdd8a173b1a (diff)
system & jobs: Reverse link and acquiring events
- The new version of 'systemd_get_event_loop' dont depends anymore on jobs but returns a unique systemd event loop for any threads. - The event loop of jobs now use system.h function instead of the opposite. - The function 'jobs_get_sd_event' is removed - The function 'jobs_acquire_event_manager' is introduced. It is designed to that the current thread can manipulate the single event manager Change-Id: I31fe48dfe0f2cfa4d468e49338d36fea6e7e8081 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/systemd.c')
-rw-r--r--src/systemd.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/systemd.c b/src/systemd.c
index 1adb75ab..29d626bc 100644
--- a/src/systemd.c
+++ b/src/systemd.c
@@ -25,41 +25,53 @@
#include <systemd/sd-daemon.h>
#include "systemd.h"
-#include "jobs.h"
static struct sd_bus *sdbusopen(struct sd_bus **p, int (*f)(struct sd_bus **))
{
- if (*p == NULL) {
- int rc = f(p);
- if (rc < 0) {
- errno = -rc;
- *p = NULL;
- } else {
- rc = sd_bus_attach_event(*p, systemd_get_event_loop(), 0);
+ int rc;
+ struct sd_bus *r;
+
+ r = *p;
+ if (!r) {
+ rc = f(&r);
+ if (rc >= 0) {
+ rc = sd_bus_attach_event(r, systemd_get_event_loop(), 0);
if (rc < 0) {
- sd_bus_unref(*p);
- errno = -rc;
- *p = NULL;
+ sd_bus_unref(r);
+ r = 0;
}
}
+ if (rc < 0)
+ errno = -rc;
+ *p = r;
}
- return *p;
+ return r;
}
struct sd_event *systemd_get_event_loop()
{
- return jobs_get_sd_event();
+ static struct sd_event *result = 0;
+ int rc;
+
+ if (!result) {
+ rc = sd_event_new(&result);
+ if (rc < 0) {
+ errno = -rc;
+ result = NULL;
+ }
+ }
+ return result;
}
struct sd_bus *systemd_get_user_bus()
{
- static struct sd_bus *result = NULL;
+ static struct sd_bus *result = 0;
return sdbusopen((void*)&result, (void*)sd_bus_open_user);
}
struct sd_bus *systemd_get_system_bus()
{
- static struct sd_bus *result = NULL;
+ static struct sd_bus *result = 0;
return sdbusopen((void*)&result, (void*)sd_bus_open_system);
}