X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fsystemd.c;h=e49ce8af13d6feabd010f009f02b9efc109a798a;hb=65353dce81a629e042800bb7b86fcd869a76727e;hp=1adb75ab66dc6e345d4d6445860ae0e9ce40013f;hpb=d7e4faba5d1744160d538edd74bc4bdd8a173b1a;p=src%2Fapp-framework-binder.git diff --git a/src/systemd.c b/src/systemd.c index 1adb75ab..e49ce8af 100644 --- a/src/systemd.c +++ b/src/systemd.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2019 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,41 +25,53 @@ #include #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); }