apply socket activation to amd and amd_session_agent 70/35770/5 accepted/tizen/mobile/20150225.053512 accepted/tizen/tv/20150225.100213 accepted/tizen/wearable/20150225.053943 submit/tizen_mobile/20150225.030152 submit/tizen_tv/20150225.030125 submit/tizen_wearable/20150225.030214
authorJiwoong Im <jiwoong.im@samsung.com>
Tue, 24 Feb 2015 11:45:00 +0000 (20:45 +0900)
committerSuchang Woo <suchang.woo@samsung.com>
Wed, 25 Feb 2015 02:56:10 +0000 (18:56 -0800)
- add socket unit and install unit file by making link in .target.wants
folder.
- Before create server socket in daemon, check if there is socket stream.
- amd and amd_session_agent can receive its preinitailized sockets from
systemd.

Change-Id: I0c58245e734796f2a89c751004703082445033af

CMakeLists.txt
am_daemon/amd_request.c
am_session_agent/agent.c
include/app_sock.h
packaging/ac.socket [new file with mode: 0644]
packaging/amd_session_agent.socket [new file with mode: 0644]
packaging/aul.spec
src/app_sock.c

index 1374bb2..54032e4 100644 (file)
@@ -22,7 +22,7 @@ INCLUDE(FindPkgConfig)
 SET(AUL-1_PKG_CHECK_MODULES dlog libprivilege-control app-checker rua glib-2.0 vconf pkgmgr-info privacy-manager-client)
 pkg_check_modules(pkgs REQUIRED  ${AUL-1_PKG_CHECK_MODULES} )
 
-pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime app-checker libtzplatform-config pkgmgr-info)
+pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime app-checker libtzplatform-config pkgmgr-info libsystemd-daemon)
 PKG_CHECK_MODULES(PKGS REQUIRED glib-2.0 gio-2.0 dlog bundle rua)
 
 FIND_LIBRARY(LIB_DL dl)
index 6dc90ff..a2c4697 100644 (file)
@@ -422,7 +422,12 @@ int _requset_init(struct amdmgr *amd)
        GPollFD *gpollfd;
        GSource *src;
 
-       fd = __create_server_sock(AUL_UTIL_PID);
+       fd = __create_sock_activation();
+       if (fd == -1) {
+               _D("Create server socket without socket activation");
+               fd = __create_server_sock(AUL_UTIL_PID);
+       }
+
        src = g_source_new(&funcs, sizeof(GSource));
 
        gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
index 6193cf9..817dedf 100644 (file)
@@ -731,25 +731,27 @@ _static_ void __agent_main_loop(int main_fd)
 _static_ int __agent_pre_init(int argc, char **argv)
 {
        int fd;
-       char *socket_path = NULL;
+       char socket_path[PATH_MAX];
        /* signal init*/
        __signal_init();
 
-    /* get my(agent) command line*/
-    agent_cmdline = __proc_get_cmdline_bypid(getpid());
-    if (agent_cmdline == NULL) {
-        _E("agent cmdline fail to get");
-        return -1;
-    }
-    _D("agent cmdline = %s", agent_cmdline);
+       /* get my(agent) command line*/
+       agent_cmdline = __proc_get_cmdline_bypid(getpid());
+       if (agent_cmdline == NULL) {
+               _E("agent cmdline fail to get");
+               return -1;
+       }
+       _D("agent cmdline = %s", agent_cmdline);
 
        /* create agent socket */
-    asprintf(&socket_path,"/run/user/%d/amd_agent",getuid());
-       if(socket_path)
+
+       fd = __create_sock_activation();
+       if (fd == -1) {
+               _D("Create server socket without socket activation");
+               snprintf(socket_path, sizeof(socket_path),
+                               "/run/user/%d/amd_agent", getuid());
                fd = __create_server_sock_by_path(socket_path);
-       else
-               return -1;
-       free(socket_path);
+       }
        if (fd < 0) {
                _E("server sock error");
                return -1;
index f6129c6..7b70ac1 100644 (file)
@@ -90,5 +90,6 @@ app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr);
 app_pkt_t *__app_send_cmd_with_result(int pid, int cmd, unsigned char *kb_data, int datalen);
 int __create_agent_client_sock(int uid);
 int __create_server_sock_by_path(char *path);
+int __create_sock_activation(void);
 #endif
 
diff --git a/packaging/ac.socket b/packaging/ac.socket
new file mode 100644 (file)
index 0000000..16a8e1f
--- /dev/null
@@ -0,0 +1,6 @@
+[Socket]
+ListenStream=/tmp/alaunch/-2
+DirectoryMode=0777
+
+[Install]
+WantedBy=sockets.target
diff --git a/packaging/amd_session_agent.socket b/packaging/amd_session_agent.socket
new file mode 100644 (file)
index 0000000..cf31aa8
--- /dev/null
@@ -0,0 +1,5 @@
+[Socket]
+ListenStream=/run/user/%U/amd_agent
+
+[Install]
+WantedBy=sockets.target
index 41e0a68..7ae9d72 100644 (file)
@@ -5,8 +5,10 @@ Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
-Source102:  ac.service
+Source101:  ac.service
+Source102:  ac.socket
 Source103:  amd_session_agent.service
+Source104:  amd_session_agent.socket
 Source1001: %{name}.manifest
 
 Requires(post):   /sbin/ldconfig
@@ -32,6 +34,7 @@ BuildRequires:  pkgconfig(pkgmgr-info)
 BuildRequires:  libattr-devel
 BuildRequires:  pkgconfig(privacy-manager-client)
 BuildRequires:  pkgconfig(libtzplatform-config)
+BuildRequires:  pkgconfig(libsystemd-daemon)
 
 %description
 Application utility library
@@ -82,10 +85,18 @@ mkdir -p %{buildroot}%{TZ_SYS_DB}
 sqlite3 %{buildroot}%{TZ_SYS_DB}/.mida.db < %{buildroot}%{_datadir}/aul/mida_db.sql
 rm -rf %{buildroot}%{_datadir}/aul/mida_db.sql
 
-mkdir -p %{buildroot}%{_unitdir}
-mkdir -p %{buildroot}%{_unitdir_user}
-install -m 0644 %SOURCE102 %{buildroot}%{_unitdir}/ac.service
+mkdir -p %{buildroot}%{_unitdir}/default.target.wants
+mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants
+mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants
+mkdir -p %{buildroot}%{_unitdir_user}/sockets.target.wants
+install -m 0644 %SOURCE101 %{buildroot}%{_unitdir}/ac.service
+install -m 0644 %SOURCE102 %{buildroot}%{_unitdir}/ac.socket
 install -m 0644 %SOURCE103 %{buildroot}%{_unitdir_user}/amd_session_agent.service
+install -m 0644 %SOURCE104 %{buildroot}%{_unitdir_user}/amd_session_agent.socket
+ln -sf ../ac.service %{buildroot}%{_unitdir}/default.target.wants/ac.service
+ln -sf ../ac.socket %{buildroot}%{_unitdir}/sockets.target.wants/ac.socket
+ln -sf ../amd_session_agent.service %{buildroot}%{_unitdir_user}/default.target.wants/amd_session_agent.service
+ln -sf ../amd_session_agent.socket %{buildroot}%{_unitdir_user}/sockets.target.wants/amd_session_agent.socket
 
 %preun
 if [ $1 == 0 ]; then
@@ -96,8 +107,6 @@ fi
 
 %post
 /sbin/ldconfig
-systemctl enable ac
-systemctl --global enable amd_session_agent
 systemctl daemon-reload
 if [ $1 == 1 ]; then
     systemctl restart ac.service
@@ -126,7 +135,13 @@ systemctl daemon-reload
 %{_datadir}/aul/preload_list.txt
 %{_datadir}/aul/preexec_list.txt
 %{_unitdir}/ac.service
+%{_unitdir}/default.target.wants/ac.service
+%{_unitdir}/ac.socket
+%{_unitdir}/sockets.target.wants/ac.socket
 %{_unitdir_user}/amd_session_agent.service
+%{_unitdir_user}/default.target.wants/amd_session_agent.service
+%{_unitdir_user}/amd_session_agent.socket
+%{_unitdir_user}/sockets.target.wants/amd_session_agent.socket
 %{_bindir}/amd
 %{_bindir}/daemon-manager-release-agent
 %{_bindir}/daemon-manager-launch-agent
index 84b6f4f..1bc43ed 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/xattr.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <systemd/sd-daemon.h>
 
 #include "app_sock.h"
 #include "simple_util.h"
@@ -187,10 +188,21 @@ int __create_server_sock_by_path(char *path)
        return fd;
 }
 
+int __create_sock_activation(void)
+{
+       int fds;
 
+       fds = sd_listen_fds(0);
+       if (fds == 1)
+               return SD_LISTEN_FDS_START;
 
+       if (fds > 1)
+               _E("Too many file descriptors received.\n");
+       else
+               _D("There is no socket stream");
 
-
+       return -1;
+}
 
 int __create_agent_client_sock(int uid)
 {