From d7e4faba5d1744160d538edd74bc4bdd8a173b1a Mon Sep 17 00:00:00 2001 From: José Bollo Date: Thu, 14 Feb 2019 10:15:40 +0100 Subject: Rename afb-systemd to systemd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Files "afb-systemd.[ch]" are renamed "systemd.[ch]" and their functions "afb_systemd_*" are renamed "systemd_*" Change-Id: I8362a2ca8b71945b54c6ab9a7ead51d9c50bc8e2 Signed-off-by: José Bollo --- src/CMakeLists.txt | 2 +- src/afb-api-dbus.c | 7 ++-- src/afb-export.c | 21 +++++------ src/afb-fdev.c | 4 +-- src/afb-hsrv.c | 4 +-- src/afb-socket.c | 5 +-- src/afb-systemd.c | 103 ----------------------------------------------------- src/afb-systemd.h | 30 ---------------- src/afb-ws-json1.c | 3 +- src/systemd.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/systemd.h | 30 ++++++++++++++++ 11 files changed, 157 insertions(+), 155 deletions(-) delete mode 100644 src/afb-systemd.c delete mode 100644 src/afb-systemd.h create mode 100644 src/systemd.c create mode 100644 src/systemd.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 086a2aa1..3c9763d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,7 +56,6 @@ SET(AFB_LIB_SOURCES afb-session.c afb-socket.c afb-stub-ws.c - afb-systemd.c afb-trace.c afb-websock.c afb-ws-client.c @@ -74,6 +73,7 @@ SET(AFB_LIB_SOURCES process-name.c sig-monitor.c subpath.c + systemd.c verbose.c watchdog.c websock.c diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c index f4132946..8c55ed01 100644 --- a/src/afb-api-dbus.c +++ b/src/afb-api-dbus.c @@ -33,8 +33,6 @@ #include -#include "afb-systemd.h" - #include "afb-session.h" #include "afb-msg-json.h" #include "afb-api.h" @@ -44,8 +42,9 @@ #include "afb-cred.h" #include "afb-evt.h" #include "afb-xreq.h" -#include "verbose.h" +#include "verbose.h" +#include "systemd.h" static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/"; @@ -130,7 +129,7 @@ static struct api_dbus *make_api_dbus_3(int system, const char *path, size_t pat } /* choose the bus */ - sdbus = (system ? afb_systemd_get_system_bus : afb_systemd_get_user_bus)(); + sdbus = (system ? systemd_get_system_bus : systemd_get_user_bus)(); if (sdbus == NULL) goto error2; diff --git a/src/afb-export.c b/src/afb-export.c index 0023f71e..b5a4b9e3 100644 --- a/src/afb-export.c +++ b/src/afb-export.c @@ -39,7 +39,6 @@ #include "afb-api-so-v2.h" #include "afb-api-v3.h" #include "afb-common.h" -#include "afb-systemd.h" #include "afb-cred.h" #include "afb-evt.h" #include "afb-export.h" @@ -48,6 +47,8 @@ #include "afb-session.h" #include "afb-xreq.h" #include "afb-calls.h" + +#include "systemd.h" #include "jobs.h" #include "verbose.h" #include "globset.h" @@ -450,21 +451,21 @@ static int hooked_event_broadcast_cb(struct afb_api_x3 *closure, const char *nam static struct sd_event *hooked_get_event_loop(struct afb_api_x3 *closure) { struct afb_export *export = from_api_x3(closure); - struct sd_event *r = afb_systemd_get_event_loop(); + struct sd_event *r = systemd_get_event_loop(); return afb_hook_api_get_event_loop(export, r); } static struct sd_bus *hooked_get_user_bus(struct afb_api_x3 *closure) { struct afb_export *export = from_api_x3(closure); - struct sd_bus *r = afb_systemd_get_user_bus(); + struct sd_bus *r = systemd_get_user_bus(); return afb_hook_api_get_user_bus(export, r); } static struct sd_bus *hooked_get_system_bus(struct afb_api_x3 *closure) { struct afb_export *export = from_api_x3(closure); - struct sd_bus *r = afb_systemd_get_system_bus(); + struct sd_bus *r = systemd_get_system_bus(); return afb_hook_api_get_system_bus(export, r); } @@ -536,9 +537,9 @@ static const struct afb_daemon_itf_x1 daemon_itf = { .vverbose_v2 = vverbose_cb, .event_make = legacy_event_x1_make_cb, .event_broadcast = event_broadcast_cb, - .get_event_loop = afb_systemd_get_event_loop, - .get_user_bus = afb_systemd_get_user_bus, - .get_system_bus = afb_systemd_get_system_bus, + .get_event_loop = systemd_get_event_loop, + .get_user_bus = systemd_get_user_bus, + .get_system_bus = systemd_get_system_bus, .rootdir_get_fd = afb_common_rootdir_get_fd, .rootdir_open_locale = rootdir_open_locale_cb, .queue_job = queue_job_cb, @@ -1051,9 +1052,9 @@ static const struct afb_api_x3_itf api_x3_itf = { .vverbose = (void*)vverbose_cb, - .get_event_loop = afb_systemd_get_event_loop, - .get_user_bus = afb_systemd_get_user_bus, - .get_system_bus = afb_systemd_get_system_bus, + .get_event_loop = systemd_get_event_loop, + .get_user_bus = systemd_get_user_bus, + .get_system_bus = systemd_get_system_bus, .rootdir_get_fd = afb_common_rootdir_get_fd, .rootdir_open_locale = rootdir_open_locale_cb, .queue_job = queue_job_cb, diff --git a/src/afb-fdev.c b/src/afb-fdev.c index 42436373..fa1a402f 100644 --- a/src/afb-fdev.c +++ b/src/afb-fdev.c @@ -17,10 +17,10 @@ #include "fdev.h" -#include "afb-systemd.h" +#include "systemd.h" #include "fdev-systemd.h" struct fdev *afb_fdev_create(int fd) { - return fdev_systemd_create(afb_systemd_get_event_loop(), fd); + return fdev_systemd_create(systemd_get_event_loop(), fd); } diff --git a/src/afb-hsrv.c b/src/afb-hsrv.c index ba1dac12..ed0adeeb 100644 --- a/src/afb-hsrv.c +++ b/src/afb-hsrv.c @@ -42,11 +42,11 @@ #include "afb-hsrv.h" #include "afb-fdev.h" #include "afb-socket.h" + #include "fdev.h" #include "verbose.h" #include "locale-root.h" - -#include "afb-systemd.h" +#include "systemd.h" #include "jobs.h" #define JSON_CONTENT "application/json" diff --git a/src/afb-socket.c b/src/afb-socket.c index 9f2be989..cf788de6 100644 --- a/src/afb-socket.c +++ b/src/afb-socket.c @@ -31,7 +31,8 @@ #include "afb-fdev.h" #include "afb-socket.h" -#include "afb-systemd.h" + +#include "systemd.h" #include "fdev.h" #include "verbose.h" @@ -228,7 +229,7 @@ static int open_systemd(const char *spec) errno = EAFNOSUPPORT; return -1; #else - return afb_systemd_fds_for(spec); + return systemd_fds_for(spec); #endif } diff --git a/src/afb-systemd.c b/src/afb-systemd.c deleted file mode 100644 index 3fcf7612..00000000 --- a/src/afb-systemd.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2015-2019 "IoT.bzh" - * Author José Bollo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define _GNU_SOURCE - -#include -#include - -#include -#include -#include - -#include "afb-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, afb_systemd_get_event_loop(), 0); - if (rc < 0) { - sd_bus_unref(*p); - errno = -rc; - *p = NULL; - } - } - } - return *p; -} - -struct sd_event *afb_systemd_get_event_loop() -{ - return jobs_get_sd_event(); -} - -struct sd_bus *afb_systemd_get_user_bus() -{ - static struct sd_bus *result = NULL; - return sdbusopen((void*)&result, (void*)sd_bus_open_user); -} - -struct sd_bus *afb_systemd_get_system_bus() -{ - static struct sd_bus *result = NULL; - return sdbusopen((void*)&result, (void*)sd_bus_open_system); -} - -static char **fds_names() -{ - static char *null; - static char **names; - - int rc; - - if (!names) { - rc = sd_listen_fds_with_names(1, &names); - if (rc <= 0) { - errno = -rc; - names = &null; - } - } - return names; -} - -int afb_systemd_fds_init() -{ - errno = 0; - fds_names(); - return -!!errno; -} - -int afb_systemd_fds_for(const char *name) -{ - int idx; - char **names; - - names = fds_names(); - for (idx = 0 ; names[idx] != NULL ; idx++) - if (!strcmp(name, names[idx])) - return idx + SD_LISTEN_FDS_START; - - errno = ENOENT; - return -1; -} - diff --git a/src/afb-systemd.h b/src/afb-systemd.h deleted file mode 100644 index c7b56968..00000000 --- a/src/afb-systemd.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2015-2019 "IoT.bzh" - * Author José Bollo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -struct sd_event; -struct sd_bus; - -extern struct sd_event *afb_systemd_get_event_loop(); -extern struct sd_bus *afb_systemd_get_user_bus(); -extern struct sd_bus *afb_systemd_get_system_bus(); - -extern int afb_systemd_fds_init(); -extern int afb_systemd_fds_for(const char *name); - - diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c index 3bd1472b..197d0c86 100644 --- a/src/afb-ws-json1.c +++ b/src/afb-ws-json1.c @@ -27,7 +27,6 @@ #include "afb-wsj1.h" #include "afb-ws-json1.h" -#include "afb-systemd.h" #include "afb-msg-json.h" #include "afb-session.h" #include "afb-cred.h" @@ -35,6 +34,8 @@ #include "afb-xreq.h" #include "afb-context.h" #include "afb-evt.h" + +#include "systemd.h" #include "verbose.h" #include "fdev.h" diff --git a/src/systemd.c b/src/systemd.c new file mode 100644 index 00000000..1adb75ab --- /dev/null +++ b/src/systemd.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015-2019 "IoT.bzh" + * Author José Bollo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE + +#include +#include + +#include +#include +#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); + if (rc < 0) { + sd_bus_unref(*p); + errno = -rc; + *p = NULL; + } + } + } + return *p; +} + +struct sd_event *systemd_get_event_loop() +{ + return jobs_get_sd_event(); +} + +struct sd_bus *systemd_get_user_bus() +{ + static struct sd_bus *result = NULL; + return sdbusopen((void*)&result, (void*)sd_bus_open_user); +} + +struct sd_bus *systemd_get_system_bus() +{ + static struct sd_bus *result = NULL; + return sdbusopen((void*)&result, (void*)sd_bus_open_system); +} + +static char **fds_names() +{ + static char *null; + static char **names; + + int rc; + + if (!names) { + rc = sd_listen_fds_with_names(1, &names); + if (rc <= 0) { + errno = -rc; + names = &null; + } + } + return names; +} + +int systemd_fds_init() +{ + errno = 0; + fds_names(); + return -!!errno; +} + +int systemd_fds_for(const char *name) +{ + int idx; + char **names; + + names = fds_names(); + for (idx = 0 ; names[idx] != NULL ; idx++) + if (!strcmp(name, names[idx])) + return idx + SD_LISTEN_FDS_START; + + errno = ENOENT; + return -1; +} + diff --git a/src/systemd.h b/src/systemd.h new file mode 100644 index 00000000..d9efa352 --- /dev/null +++ b/src/systemd.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015-2019 "IoT.bzh" + * Author José Bollo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +struct sd_event; +struct sd_bus; + +extern struct sd_event *systemd_get_event_loop(); +extern struct sd_bus *systemd_get_user_bus(); +extern struct sd_bus *systemd_get_system_bus(); + +extern int systemd_fds_init(); +extern int systemd_fds_for(const char *name); + + -- cgit 1.2.3-korg