summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDariusz Michaluk <d.michaluk@samsung.com>2013-05-22 08:42:41 (GMT)
committerDariusz Michaluk <d.michaluk@samsung.com>2013-06-06 12:46:42 (GMT)
commita4f7c6920c024d37b8aaf20d9048a5a5666229bd (patch)
tree04ff602b56ef94a37fb43508a18f55f928ea1a7b
parent6f4e661192f57cde2a5302f9b74193328e1f8a10 (diff)
downloadstarter-a4f7c6920c024d37b8aaf20d9048a5a5666229bd.zip
starter-a4f7c6920c024d37b8aaf20d9048a5a5666229bd.tar.gz
starter-a4f7c6920c024d37b8aaf20d9048a5a5666229bd.tar.bz2
Convert to systemd API
-enable socket activation, -enable sd_notify (start-up completion notification), -build package changes. Change-Id: I39f3ce485cad4131252f58aa34949befd642bc1d
-rwxr-xr-xCMakeLists.txt6
-rw-r--r--packaging/starter.spec13
-rwxr-xr-xsrc/lock-daemon.c81
-rwxr-xr-xsrc/starter.c2
-rwxr-xr-xstarter.manifest3
-rw-r--r--systemd/starter.path (renamed from packaging/starter.path)0
-rw-r--r--systemd/starter.service (renamed from packaging/starter.service)0
-rw-r--r--systemd/starter.socket6
8 files changed, 71 insertions, 40 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d563331..59a317e 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@ pkg_check_modules(pkgs REQUIRED
capi-appfw-application
capi-system-info
pkgmgr-info
+ libsystemd-daemon
)
FOREACH(flag ${pkgs_CFLAGS})
@@ -99,3 +100,8 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/rd3starter DESTINATION /etc/init.d
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
#INSTALL to /etc/init.d
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/starter.service DESTINATION /usr/lib/systemd/user)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/starter.socket DESTINATION /usr/lib/systemd/user)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/starter.path DESTINATION /usr/lib/systemd/user)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE.Flora DESTINATION /usr/share/license/starter)
diff --git a/packaging/starter.spec b/packaging/starter.spec
index 9d027fc..612bdc5 100644
--- a/packaging/starter.spec
+++ b/packaging/starter.spec
@@ -5,8 +5,6 @@ Release: 3
Group: TO_BE/FILLED_IN
License: TO_BE/FILLED_IN
Source0: starter-%{version}.tar.gz
-Source1: starter.service
-Source2: starter.path
Requires(post): /usr/bin/vconftool
BuildRequires: cmake
BuildRequires: pkgconfig(ail)
@@ -35,6 +33,8 @@ BuildRequires: pkgconfig(xcomposite)
BuildRequires: pkgconfig(xext)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(libsystemd-daemon)
+
BuildRequires: cmake
BuildRequires: edje-bin
BuildRequires: gettext-tools
@@ -58,11 +58,11 @@ rm -rf %{buildroot}
%make_install
mkdir -p %{buildroot}%{_libdir}/systemd/user/core-efl.target.wants
-install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/user/
-install -m 0644 %SOURCE2 %{buildroot}%{_libdir}/systemd/user/
+mkdir -p %{buildroot}%{_libdir}/systemd/user/sockets.target.wants
ln -s ../starter.path %{buildroot}%{_libdir}/systemd/user/core-efl.target.wants/starter.path
+ln -s ../starter.service %{buildroot}%{_libdir}/systemd/user/core-efl.target.wants/starter.service
+ln -s ../starter.socket %{buildroot}%{_libdir}/systemd/user/sockets.target.wants/starter.socket
mkdir -p %{buildroot}/usr/share/license
-cp -f LICENSE.Flora %{buildroot}/usr/share/license/%{name}
mkdir -p %{buildroot}/opt/data/home-daemon
%post
@@ -105,6 +105,9 @@ ln -sf /etc/init.d/rd3starter /etc/rc.d/rc3.d/S43starter
/usr/ug/res/locale/*/LC_MESSAGES/*
%{_libdir}/systemd/user/starter.path
%{_libdir}/systemd/user/starter.service
+%{_libdir}/systemd/user/starter.socket
%{_libdir}/systemd/user/core-efl.target.wants/starter.path
+%{_libdir}/systemd/user/core-efl.target.wants/starter.service
+%{_libdir}/systemd/user/sockets.target.wants/starter.socket
/usr/share/license/%{name}
/opt/data/home-daemon
diff --git a/src/lock-daemon.c b/src/lock-daemon.c
index 2ceb5be..d3908a5 100755
--- a/src/lock-daemon.c
+++ b/src/lock-daemon.c
@@ -20,7 +20,7 @@
#include <vconf.h>
#include <vconf-keys.h>
-
+#include <systemd/sd-daemon.h>
#include <glib.h>
#include <poll.h>
#include <stdio.h>
@@ -293,49 +293,60 @@ static int lockd_create_sock(void)
struct sockaddr_un saddr;
int fd;
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) {
- if (errno == EINVAL) {
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) {
- LOCKD_DBG
- ("second chance - socket create error");
- return -1;
- }
- } else {
- LOCKD_DBG("socket error");
- return -1;
+ int n = sd_listen_fds(1);
+ if (n > 1) {
+ LOCKD_DBG("too many file descriptors received");
+ return -1;
+ } else if (n == 1) {
+ int r;
+ if ((r = sd_is_socket_unix(SD_LISTEN_FDS_START, SOCK_STREAM, 1, PHLOCK_SOCK_PREFIX, 0)) <= 0) {
+ LOCKD_DBG("passed systemd file descriptor is of wrong type");
+ return -1;
+ }
+ fd = SD_LISTEN_FDS_START + 0;
+ } else {
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ if (errno == EINVAL) {
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ LOCKD_DBG("second chance - socket create error");
+ return -1;
+ }
+ } else {
+ LOCKD_DBG("socket error");
+ return -1;
+ }
}
- }
- bzero(&saddr, sizeof(saddr));
- saddr.sun_family = AF_UNIX;
+ bzero(&saddr, sizeof(saddr));
+ saddr.sun_family = AF_UNIX;
- strncpy(saddr.sun_path, PHLOCK_SOCK_PREFIX, strlen(PHLOCK_SOCK_PREFIX));
- saddr.sun_path[strlen(PHLOCK_SOCK_PREFIX)] = 0;
+ strncpy(saddr.sun_path, PHLOCK_SOCK_PREFIX, strlen(PHLOCK_SOCK_PREFIX));
+ saddr.sun_path[strlen(PHLOCK_SOCK_PREFIX)] = 0;
- unlink(saddr.sun_path);
+ unlink(saddr.sun_path);
- if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
- LOCKD_DBG("bind error");
- close(fd);
- return -1;
- }
+ if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
+ LOCKD_DBG("bind error");
+ close(fd);
+ return -1;
+ }
- if (chmod(saddr.sun_path, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) {
- LOCKD_DBG("failed to change the socket permission");
- close(fd);
- return -1;
- }
+ if (chmod(saddr.sun_path, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) {
+ LOCKD_DBG("failed to change the socket permission");
+ close(fd);
+ return -1;
+ }
- lockd_set_sock_option(fd, 0);
+ lockd_set_sock_option(fd, 0);
- if (listen(fd, 10) == -1) {
- LOCKD_DBG("listen error");
- close(fd);
- return -1;
+ if (listen(fd, 10) == -1) {
+ LOCKD_DBG("listen error");
+ close(fd);
+ return -1;
+ }
}
-
return fd;
}
diff --git a/src/starter.c b/src/starter.c
index 9a6a946..d96c444 100755
--- a/src/starter.c
+++ b/src/starter.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include <string.h>
#include <poll.h>
+#include <systemd/sd-daemon.h>
#include <aul.h>
#include <vconf.h>
@@ -261,6 +262,7 @@ int main(int argc, char *argv[])
_init(&ad);
+ sd_notify(0, "READY=1");
elm_run();
_fini(&ad);
diff --git a/starter.manifest b/starter.manifest
index d2210a5..62d872a 100755
--- a/starter.manifest
+++ b/starter.manifest
@@ -11,6 +11,9 @@
<filesystem path="/etc/init.d/rd4starter" label="_" exec_label="none" />
<filesystem path="/usr/lib/systemd/user/starter.path" label="_" exec_label="none" />
<filesystem path="/usr/lib/systemd/user/starter.service" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/user/starter.socket" label="_" exec_label="none" />
<filesystem path="/usr/lib/systemd/user/core-efl.target.wants/starter.path" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/user/core-efl.target.wants/starter.service" label="_" exec_label="none" />
+ <filesystem path="/usr/lib/systemd/user/sockets.target.wants/starter.socket" label="_" exec_label="none" />
</assign>
</manifest>
diff --git a/packaging/starter.path b/systemd/starter.path
index 724239c..724239c 100644
--- a/packaging/starter.path
+++ b/systemd/starter.path
diff --git a/packaging/starter.service b/systemd/starter.service
index 63d0e3f..63d0e3f 100644
--- a/packaging/starter.service
+++ b/systemd/starter.service
diff --git a/systemd/starter.socket b/systemd/starter.socket
new file mode 100644
index 0000000..871d9d3
--- /dev/null
+++ b/systemd/starter.socket
@@ -0,0 +1,6 @@
+[Socket]
+ListenStream=/tmp/phlock
+SocketMode=0777
+
+[Install]
+WantedBy=sockets.target