diff options
author | Jacek Pielaszkiewicz <j.pielaszkie@samsung.com> | 2013-06-19 14:13:54 +0200 |
---|---|---|
committer | Łukasz Stelmach <l.stelmach@samsung.com> | 2013-10-29 17:49:57 +0100 |
commit | af5addd65413d857521ee1595c76940e8fa5a0cb (patch) | |
tree | 39ca10ccb8948a535de924db374732ecb119d771 | |
parent | e12bb2e1ae504c518316ef3aa5b436a6d80c497a (diff) | |
download | sensor-framework-af5addd65413d857521ee1595c76940e8fa5a0cb.tar.gz sensor-framework-af5addd65413d857521ee1595c76940e8fa5a0cb.tar.bz2 sensor-framework-af5addd65413d857521ee1595c76940e8fa5a0cb.zip |
sensor-framework - add support for systemd
The following changes have been implemenetd:
1. socket activation by systemd
2. the service has been updated to send startup statu to systemd
(by calling sd_notify())
Conflicts:
packaging/sensor-framework.spec
Change-Id: I4e86baa23f09cf17329c06728ce46b9ef1739ecb
Signed-off-by: Jacek Pielaszkiewicz <j.pielaszkie@samsung.com>
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | packaging/sensor-framework.spec | 12 | ||||
-rwxr-xr-x | server/include/cserver.h | 3 | ||||
-rwxr-xr-x | server/src/cserver.cpp | 44 | ||||
-rw-r--r-- | systemd/sensor-framework.service (renamed from packaging/sensor-framework.service) | 2 | ||||
-rw-r--r-- | systemd/sensor-framework.socket | 8 |
6 files changed, 72 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 73545f8..3db477c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,9 @@ cmake_minimum_required(VERSION 2.6) project(sensor_framework_main CXX) +include(TizenCommon) include(FindPkgConfig) -pkg_check_modules(rpkgs REQUIRED sf_common vconf heynoti) +pkg_check_modules(rpkgs REQUIRED sf_common vconf heynoti libsystemd-daemon) add_definitions(${rpkgs_CFLAGS}) # to install pkgconfig setup file. @@ -71,3 +72,10 @@ if("${PLATFORM_ARCH}" MATCHES "arch_sdk") endif() install(PROGRAMS sfsvc DESTINATION /etc/rc.d/init.d) + +####################### systemd files installation ############################ +INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/systemd/sensor-framework.service + ${CMAKE_CURRENT_SOURCE_DIR}/systemd/sensor-framework.socket + DESTINATION ${LIB_INSTALL_DIR}/systemd/system) + diff --git a/packaging/sensor-framework.spec b/packaging/sensor-framework.spec index 64fb17e..edb2c4f 100644 --- a/packaging/sensor-framework.spec +++ b/packaging/sensor-framework.spec @@ -6,7 +6,6 @@ Release: 1 Group: Framework/system License: Apache License, Version 2.0 Source0: %{name}-%{version}.tar.gz -Source1: sensor-framework.service Source1001: sensor-framework.manifest %ifarch %{arm} @@ -29,6 +28,8 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(sf_common) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(heynoti) +BuildRequires: pkgconfig(libsystemd-daemon) +%{?systemd_requires} %description Sensor framework @@ -49,8 +50,9 @@ mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants -install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/system/ +mkdir -p %{buildroot}%{_libdir}/systemd/system/sockets.target.wants ln -s ../sensor-framework.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/sensor-framework.service +ln -s ../sensor-framework.socket %{buildroot}%{_libdir}/systemd/system/sockets.target.wants/sensor-framework.socket # FIXME: remove initscripts after we start using systemd mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc3.d @@ -86,8 +88,10 @@ vconftool set -t int memory/private/sensor/80001 0 -i vconftool set -t int memory/private/sensor/80002 0 -i vconftool set -t int memory/private/sensor/poweroff 0 -i +systemctl daemon-reload + %files -%manifest %{name}.manifest +%manifest sensor-framework.manifest %attr(0755,root,root) %{_sysconfdir}/rc.d/init.d/sfsvc %{_sysconfdir}/rc.d/rc3.d/S40sfsvc %{_sysconfdir}/rc.d/rc4.d/S40sfsvc @@ -97,6 +101,8 @@ vconftool set -t int memory/private/sensor/poweroff 0 -i %attr(0644,root,root)/usr/etc/sf_processor.conf %attr(0644,root,root)/usr/etc/sf_sensor.conf %{_libdir}/systemd/system/sensor-framework.service +%{_libdir}/systemd/system/sensor-framework.socket %{_libdir}/systemd/system/multi-user.target.wants/sensor-framework.service +%{_libdir}/systemd/system/sockets.target.wants/sensor-framework.socket /usr/share/license/%{name} diff --git a/server/include/cserver.h b/server/include/cserver.h index 7298632..5075c42 100755 --- a/server/include/cserver.h +++ b/server/include/cserver.h @@ -38,6 +38,9 @@ public: void sf_main_loop_stop(void); private: + int get_systemd_socket(const char *name); + +private: struct client_ctx_t { ctype *module; diff --git a/server/src/cserver.cpp b/server/src/cserver.cpp index d63db28..b1aa624 100755 --- a/server/src/cserver.cpp +++ b/server/src/cserver.cpp @@ -22,7 +22,7 @@ - +#include <systemd/sd-daemon.h> #include <stdio.h> #include <errno.h> #include <dlfcn.h> @@ -1155,15 +1155,52 @@ void cserver::sf_main_loop_stop(void) } } +int cserver::get_systemd_socket(const char *name) +{ + int type = SOCK_STREAM; + int listening = 1; + size_t length = 0; + int fd = -1; + int n; + + // Gets number of created by systemd file descriptors that represent open sockets. + n = sd_listen_fds(1); + + // Check open sockets count (must be 1) + if (n != 1) + return -1; + + // File descriptor calculation + fd = SD_LISTEN_FDS_START + 0; + + // File descriptor veryfication. + if(sd_is_socket_unix(fd, type, listening, name, length) > 0) + return fd; + + // No proper socket or error + return -1; +} + + void cserver::sf_main_loop(void) { csock *ipc = NULL; + int sockfd = -1; int fd = -1; g_mainloop = g_main_loop_new(NULL, FALSE); try { - ipc = new csock((char*)STR_SF_IPC_SOCKET, csock::SOCK_TCP|csock::SOCK_WORKER, 0, 1); + // Get systemd socket + sockfd = cserver::get_systemd_socket(STR_SF_IPC_SOCKET); + + if (sockfd >= 0) { + // Systemd socket exists - short csock object setup + ipc = new csock(sockfd, csock::SOCK_TCP|csock::SOCK_WORKER); + } else { + // No systemd socket - standard csock object setup + ipc = new csock((char*)STR_SF_IPC_SOCKET, csock::SOCK_TCP|csock::SOCK_WORKER, 0, 1); + } } catch (int ErrNo) { ERR("ipc class create fail , errno : %d , errstr : %s\n",ErrNo, strerror(ErrNo)); return ; @@ -1200,6 +1237,9 @@ void cserver::sf_main_loop(void) fd = -1; } + // Notification to systemd + sd_notify(0, "READY=1"); + g_main_loop_run(g_mainloop); g_main_loop_unref(g_mainloop); diff --git a/packaging/sensor-framework.service b/systemd/sensor-framework.service index 6369769..fd92c5a 100644 --- a/packaging/sensor-framework.service +++ b/systemd/sensor-framework.service @@ -3,7 +3,7 @@ Description=Start the sensor framework [Service] -Type=simple +Type=notify ExecStart=/usr/bin/sf_server -s /usr/etc/sf_sensor.conf -f /usr/etc/sf_filter.conf -p /usr/etc/sf_processor.conf -d /usr/etc/sf_data_stream.conf [Install] diff --git a/systemd/sensor-framework.socket b/systemd/sensor-framework.socket new file mode 100644 index 0000000..2c38d52 --- /dev/null +++ b/systemd/sensor-framework.socket @@ -0,0 +1,8 @@ +[Unit] +Description=Sensor Framework socket + +[Socket] +ListenStream=/tmp/sf_socket +SocketMode=0777 +PassCredentials=yes +Accept=false |