aboutsummaryrefslogtreecommitdiffstats
path: root/src/systemd.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2019-02-14 09:37:26 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2019-03-22 12:18:29 +0100
commitf282b0a0795e27c3b0c40e213f6bef1eb602fdc7 (patch)
treedd46396a2738c0b7d4e8aecf5a327a689d0bdae3 /src/systemd.c
parent7b9fa0ade3a8847c779f46fe50c97eed86917abc (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);
}