From 62ae19bd3c8d067e8c4db2333f18af0f7130bc82 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 8 Apr 2019 17:33:17 +0900 Subject: [PATCH] Change library name to libsyscommon. - Add new function for systemd state Change-Id: Ie69b718918306fc55e6c801e4c8d0fcaa0ab79b0 Signed-off-by: Yunmi Ha --- CMakeLists.txt | 61 ++++++++++++++++++++++- src/libgdbus/libgdbus.pc.in => libsyscommon.pc.in | 10 ++-- packaging/libsyscommon.spec | 34 ++++++------- src/libgdbus/CMakeLists.txt | 58 --------------------- src/libsystemd/systemd-state.c | 60 ++++++++++++++++++++++ src/libsystemd/systemd-state.h | 35 +++++++++++++ 6 files changed, 174 insertions(+), 84 deletions(-) rename src/libgdbus/libgdbus.pc.in => libsyscommon.pc.in (54%) delete mode 100644 src/libgdbus/CMakeLists.txt create mode 100644 src/libsystemd/systemd-state.c create mode 100644 src/libsystemd/systemd-state.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 10850df..30c53c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,4 +2,63 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(libsyscommon C) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) -ADD_SUBDIRECTORY(src/libgdbus) \ No newline at end of file +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared) +# ADD_SUBDIRECTORY(src/libgdbus) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(LIBDIR ${LIB_INSTALL_DIR}) +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 +) +SET(HEADERS + src/libgdbus/dbus-system.h + src/libgdbus/dbus-systemd.h + src/libsystemd/systemd-state.h +) + +# CHECK PKG +INCLUDE(FindPkgConfig) +pkg_check_modules(syscommon REQUIRED + glib-2.0 + gio-2.0 + dlog + gio-unix-2.0) + +FOREACH(flag ${syscommon_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +# LIBRARY +ADD_LIBRARY(${PROJECT_NAME} SHARED ${libsyscommon_SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${syscommon_LDFLAGS} "-ldl" pthread) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fPIC") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME syscommon) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) + +# CONGIFURE FILE +FOREACH(flag ${syscommon_INCLUDE_DIRS}) + SET(SYSCOMMON_INCLUDEDIR "${SYSCOMMON_INCLUDEDIR} -I${flag}") +ENDFOREACH(flag) + +FOREACH(flag ${syscommon_LIBRARIES}) + SET(SYSCOMMON_LIBS "${SYSCOMMON_LIBS} -l${flag}") +ENDFOREACH(flag) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +# HEADER +FOREACH(hfile ${HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME}) +ENDFOREACH(hfile) diff --git a/src/libgdbus/libgdbus.pc.in b/libsyscommon.pc.in similarity index 54% rename from src/libgdbus/libgdbus.pc.in rename to libsyscommon.pc.in index 5616aac..8dda939 100644 --- a/src/libgdbus/libgdbus.pc.in +++ b/libsyscommon.pc.in @@ -9,9 +9,9 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: libgdbus -Description: Dbus library +Name: libsyscommon +Description: system common library Version: @VERSION@ -Requires.private: libgdbus -Cflags: -I${includedir} @GDBUS_INCLUDEDIR@ -Libs: -L${libdir} -lgdbus @GDBUS_LIBS@ +Requires.private: libsyscommon +Cflags: -I${includedir} @SYSCOMMON_INCLUDEDIR@ +Libs: -L${libdir} -lsyscommon @SYSCOMMON_LIBS@ diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 57175d4..5dfd090 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -21,24 +21,17 @@ Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig %description -System utility libraries. +System common utility libraries. -%package -n libgdbus -Summary: Dbus library +%package -n libsyscommon-devel +Summary: Header files for system common library License: Apache-2.0 - -%description -n libgdbus -Internal dbus library - -%package -n libgdbus-devel -Summary: Header files for dbus library -License: Apache-2.0 -Requires: libgdbus = %{version} +Requires: libsyscommon = %{version} Requires: pkgconfig(gio-2.0) Requires: pkgconfig(gio-unix-2.0) -%description -n libgdbus-devel -Development header files for dbus library. +%description -n libsyscommon-devel +Development header files for system common library. %prep %setup -q @@ -62,21 +55,22 @@ touch debugsources.list %postun -p /sbin/ldconfig -%files -n libgdbus +%files %defattr(-,root,root,-) %if 0%{?_with_tizen} %manifest %{name}.manifest %endif %license LICENSE.Apache-2.0 -%{_libdir}/libgdbus.so.* +%{_libdir}/libsyscommon.so.* -%files -n libgdbus-devel +%files -n libsyscommon-devel %defattr(-,root,root,-) %if 0%{?_with_tizen} %manifest %{name}.manifest %endif %license LICENSE.Apache-2.0 -%{_libdir}/libgdbus.so -%{_includedir}/libgdbus/dbus-system.h -%{_includedir}/libgdbus/dbus-systemd.h -%{_libdir}/pkgconfig/libgdbus.pc +%{_libdir}/libsyscommon.so +%{_includedir}/libsyscommon/dbus-system.h +%{_includedir}/libsyscommon/dbus-systemd.h +%{_includedir}/libsyscommon/systemd-state.h +%{_libdir}/pkgconfig/libsyscommon.pc diff --git a/src/libgdbus/CMakeLists.txt b/src/libgdbus/CMakeLists.txt deleted file mode 100644 index 9baa020..0000000 --- a/src/libgdbus/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(libgdbus C) - -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "${PREFIX}/bin") -SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include") -SET(VERSION 4.1) - -SET(libgdbus_SRCS - dbus-system.c - dbus-systemd.c -) -SET(HEADERS - dbus-system.h - dbus-systemd.h -) - -# CHECK PKG -INCLUDE(FindPkgConfig) -pkg_check_modules(gdbus REQUIRED - glib-2.0 - gio-2.0 - dlog - gio-unix-2.0) - -FOREACH(flag ${gdbus_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") - -# LIBRARY -ADD_LIBRARY(${PROJECT_NAME} SHARED ${libgdbus_SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gdbus_LDFLAGS} "-ldl" pthread) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fPIC") -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME gdbus) - -# INSTALL -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) - -# CONGIFURE FILE -FOREACH(flag ${gdbus_INCLUDE_DIRS}) - SET(GDBUS_INCLUDEDIR "${GDBUS_INCLUDEDIR} -I${flag}") -ENDFOREACH(flag) - -FOREACH(flag ${gdbus_LIBRARIES}) - SET(GDBUS_LIBS "${GDBUS_LIBS} -l${flag}") -ENDFOREACH(flag) - -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -# HEADER -FOREACH(hfile ${HEADERS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME}) -ENDFOREACH(hfile) diff --git a/src/libsystemd/systemd-state.c b/src/libsystemd/systemd-state.c new file mode 100644 index 0000000..0a6c744 --- /dev/null +++ b/src/libsystemd/systemd-state.c @@ -0,0 +1,60 @@ +/* + * 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 "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 (!dh_get_param_from_var(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 new file mode 100644 index 0000000..54b4217 --- /dev/null +++ b/src/libsystemd/systemd-state.h @@ -0,0 +1,35 @@ +/* + * 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