From 41bb90025fbe75dbc13f6bfc926109e1a337f591 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 9 Mar 2021 13:24:11 +0900 Subject: [PATCH] Rearrange header and source files Change-Id: I7cb9725a5be1ac4ead7cac73d50203f413f669cf Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 12 ++--- .../{dbus-system-iface.h => dbus-iface-system.h} | 0 src/libgdbus/{dbus-system.c => libgdbus.c} | 2 +- src/libgdbus/{dbus-system.h => libgdbus.h} | 2 +- .../dbus-systemd.c => libsystemd/libsystemd.c} | 40 +++++++++++++- .../dbus-systemd.h => libsystemd/libsystemd.h} | 3 +- src/libsystemd/systemd-state.c | 61 ---------------------- src/libsystemd/systemd-state.h | 35 ------------- 8 files changed, 48 insertions(+), 107 deletions(-) rename src/libgdbus/{dbus-system-iface.h => dbus-iface-system.h} (100%) rename src/libgdbus/{dbus-system.c => libgdbus.c} (99%) rename src/libgdbus/{dbus-system.h => libgdbus.h} (99%) rename src/{libgdbus/dbus-systemd.c => libsystemd/libsystemd.c} (93%) rename src/{libgdbus/dbus-systemd.h => libsystemd/libsystemd.h} (95%) delete mode 100644 src/libsystemd/systemd-state.c delete mode 100644 src/libsystemd/systemd-state.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d314ee5..e16516d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,16 +12,14 @@ SET(INCLUDEDIR "${PREFIX}/include") SET(VERSION 4.1) SET(libsyscommon_SRCS - src/libgdbus/dbus-system.c - src/libgdbus/dbus-systemd.c - src/libsystemd/systemd-state.c + src/libgdbus/libgdbus.c + src/libsystemd/libsystemd.c src/libcommon/ini-parser.c ) SET(HEADERS - src/libgdbus/dbus-system.h - src/libgdbus/dbus-system-iface.h - src/libgdbus/dbus-systemd.h - src/libsystemd/systemd-state.h + src/libgdbus/libgdbus.h + src/libgdbus/dbus-iface-system.h + src/libsystemd/libsystemd.h src/libcommon/list.h src/libcommon/ini-parser.h src/libcommon/file.h diff --git a/src/libgdbus/dbus-system-iface.h b/src/libgdbus/dbus-iface-system.h similarity index 100% rename from src/libgdbus/dbus-system-iface.h rename to src/libgdbus/dbus-iface-system.h diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/libgdbus.c similarity index 99% rename from src/libgdbus/dbus-system.c rename to src/libgdbus/libgdbus.c index 45b0874..499a449 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/libgdbus.c @@ -24,7 +24,7 @@ #include #include "shared/log.h" -#include "dbus-system.h" +#include "libgdbus.h" /* 10 seconds */ #define DBUS_REPLY_TIMEOUT (10000) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/libgdbus.h similarity index 99% rename from src/libgdbus/dbus-system.h rename to src/libgdbus/libgdbus.h index c707d19..99fdc3e 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/libgdbus.h @@ -26,7 +26,7 @@ #include #include -#include "dbus-system-iface.h" +#include "dbus-iface-system.h" typedef struct { const unsigned char *data; diff --git a/src/libgdbus/dbus-systemd.c b/src/libsystemd/libsystemd.c similarity index 93% rename from src/libgdbus/dbus-systemd.c rename to src/libsystemd/libsystemd.c index 14c8a72..a463118 100644 --- a/src/libgdbus/dbus-systemd.c +++ b/src/libsystemd/libsystemd.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include "shared/log.h" @@ -483,3 +483,41 @@ GVariant *systemd_get_service_property(const char *unit, const char *property) free(escaped); return val; } + +#define SYSTEMD_DBUS_METHOD_SYSTEM_STATE "SystemState" +#define SYSTEMD_STATE_RUNNING "running" +#define SYSTEMD_STATE_DEGRADED "degraded" + +int check_system_boot_finished(void) +{ + char *state = NULL; + int ret = 0; + size_t len; + GVariant *reply = NULL; + + reply = systemd_get_manager_property(SYSTEMD_DBUS_METHOD_SYSTEM_STATE); + if (!reply) { + _E("Failed to get system state: No reply"); + goto err; + } + if (!g_variant_get_safe(reply, "s", &state)) { + _E("Failed to get system state(%s)", g_variant_get_type_string(reply)); + goto err; + } + + _I("System state=%s", state); + + len = strlen(state) + 1; + if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) || + !strncmp(state, SYSTEMD_STATE_DEGRADED, len)) + ret = 1; + else + ret = 0; + +err: + if (reply) + g_variant_unref(reply); + free(state); + + return ret; +} diff --git a/src/libgdbus/dbus-systemd.h b/src/libsystemd/libsystemd.h similarity index 95% rename from src/libgdbus/dbus-systemd.h rename to src/libsystemd/libsystemd.h index 4d15200..79c9f9b 100644 --- a/src/libgdbus/dbus-systemd.h +++ b/src/libsystemd/libsystemd.h @@ -20,7 +20,7 @@ #ifndef __DBUS_SYSTEMD_H__ #define __DBUS_SYSTEMD_H__ -#include "dbus-system.h" +#include #ifdef __cplusplus extern "C" { @@ -49,6 +49,7 @@ GVariant *systemd_get_unit_property (const char *unit, GVariant *systemd_get_service_property (const char *unit, const char *property); +int check_system_boot_finished(void); #ifdef __cplusplus } diff --git a/src/libsystemd/systemd-state.c b/src/libsystemd/systemd-state.c deleted file mode 100644 index 1c25575..0000000 --- a/src/libsystemd/systemd-state.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * libsyscommon - * - * Copyright (c) 2019 Samsung Electronics Co., Ltd. - * - * 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. - */ - -#include -#include -#include - -#include "shared/log.h" - -#define SYSTEMD_DBUS_METHOD_SYSTEM_STATE "SystemState" -#define SYSTEMD_STATE_RUNNING "running" -#define SYSTEMD_STATE_DEGRADED "degraded" - -int check_system_boot_finished(void) -{ - char *state = NULL; - int ret = 0; - size_t len; - GVariant *reply = NULL; - - reply = systemd_get_manager_property(SYSTEMD_DBUS_METHOD_SYSTEM_STATE); - if (!reply) { - _E("Failed to get system state: No reply"); - goto err; - } - if (!g_variant_get_safe(reply, "s", &state)) { - _E("Failed to get system state(%s)", g_variant_get_type_string(reply)); - goto err; - } - - _I("System state=%s", state); - - len = strlen(state) + 1; - if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) || - !strncmp(state, SYSTEMD_STATE_DEGRADED, len)) - ret = 1; - else - ret = 0; - -err: - if (reply) - g_variant_unref(reply); - free(state); - - return ret; -} diff --git a/src/libsystemd/systemd-state.h b/src/libsystemd/systemd-state.h deleted file mode 100644 index 54b4217..0000000 --- a/src/libsystemd/systemd-state.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * libsyscommon - * - * Copyright (c) 2019 Samsung Electronics Co., Ltd. - * - * 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. - */ - - -#ifndef __SYSTEMD_STATE_H__ -#define __SYSTEMD_STATE_H__ - -#include "dbus-systemd.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int check_system_boot_finished(void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif __SYSTEMD_STATE_H__ -- 2.7.4