From: Jaemin Ryu Date: Tue, 22 Aug 2017 05:55:51 +0000 (+0900) Subject: Support socket activation X-Git-Tag: submit/tizen/20170828.072251^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f7b9d98242b7f64d1f1fa83ee53ee1750d55653d;p=platform%2Fcore%2Fsecurity%2Fklay.git Support socket activation Change-Id: I1a27526ba58a48cc2c2eeb879d74df5de5b1695c Signed-off-by: Jaemin Ryu --- diff --git a/include/klay/mainloop.h b/include/klay/mainloop.h index b06d66b..3c3f55d 100644 --- a/include/klay/mainloop.h +++ b/include/klay/mainloop.h @@ -41,7 +41,7 @@ public: void addEventSource(const int fd, const Event events, Callback&& callback); void removeEventSource(const int fd); bool dispatch(const int timeout); - void run(); + void run(int timeout = -1); void stop(); private: diff --git a/include/klay/rmi/service.h b/include/klay/rmi/service.h index 83b68be..2cd75f0 100644 --- a/include/klay/rmi/service.h +++ b/include/klay/rmi/service.h @@ -153,7 +153,7 @@ public: Service(const Service&) = delete; Service& operator=(const Service&) = delete; - void start(); + void start(bool activation = false, int timeout = -1); void stop(); void setAuditTrail(const AuditTrail& trail); diff --git a/include/klay/rmi/socket.h b/include/klay/rmi/socket.h index 99d0e63..a222016 100644 --- a/include/klay/rmi/socket.h +++ b/include/klay/rmi/socket.h @@ -53,15 +53,13 @@ public: void sendFileDescriptors(const int* fds, const size_t nr) const; void receiveFileDescriptors(int* fds, const size_t nr) const; - static Socket create(const std::string& path); + static Socket create(const std::string& path, bool activation = false); static Socket connect(const std::string& path); private: static int createRegularSocket(const std::string& path); -#ifdef USE_SYSTEMD_SOCKET_ACTIVATION static int createSystemdSocket(const std::string& path); -#endif private: int socketFd; diff --git a/packaging/klay.spec b/packaging/klay.spec index 5ead7f0..fb8f85a 100755 --- a/packaging/klay.spec +++ b/packaging/klay.spec @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(libsystemd-daemon) BuildRequires: pkgconfig(libtzplatform-config) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b43848e..f4d6828 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,6 +67,7 @@ PKG_CHECK_MODULES(KLAY_DEPS REQUIRED gio-2.0 libxml-2.0 sqlite3 dlog + libsystemd-daemon ) INCLUDE_DIRECTORIES(SYSTEM ${KLAY_INCLUDE} diff --git a/src/mainloop.cpp b/src/mainloop.cpp index aea2f69..c1dd277 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -84,7 +84,7 @@ void Mainloop::removeEventSource(const int fd) ::epoll_ctl(pollFd, EPOLL_CTL_DEL, fd, NULL); } -bool Mainloop::dispatch(const int timeout) +bool Mainloop::dispatch(int timeout) { int nfds; epoll_event event[MAX_EPOLL_EVENTS]; @@ -93,8 +93,8 @@ bool Mainloop::dispatch(const int timeout) nfds = ::epoll_wait(pollFd, event, MAX_EPOLL_EVENTS, timeout); } while ((nfds == -1) && (errno == EINTR)); - if (nfds < 0) { - throw Exception(GetSystemErrorMessage()); + if (nfds <= 0) { + return false; } for (int i = 0; i < nfds; i++) { @@ -136,12 +136,14 @@ void Mainloop::prepare() addEventSource(wakeupSignal.getFd(), EPOLLIN, wakeupMainloop); } -void Mainloop::run() +void Mainloop::run(int timeout) { + bool done = false; + prepare(); - while (!stopped) { - dispatch(-1); + while (!stopped && !done) { + done = !dispatch(timeout); } } diff --git a/src/rmi/service.cpp b/src/rmi/service.cpp index c9da900..c6b9188 100644 --- a/src/rmi/service.cpp +++ b/src/rmi/service.cpp @@ -46,9 +46,9 @@ Service::~Service() { } -void Service::start() +void Service::start(bool activation, int timeout) { - Socket socket(Socket::create(address)); + Socket socket(Socket::create(address, activation)); auto accept = [&](int fd, runtime::Mainloop::Event event) { onNewConnection(std::make_shared(socket.accept())); @@ -58,7 +58,7 @@ void Service::start() EPOLLIN | EPOLLHUP | EPOLLRDHUP, accept); - mainloop.run(); + mainloop.run(timeout); } void Service::stop() diff --git a/src/rmi/socket.cpp b/src/rmi/socket.cpp index 049708b..c6dae17 100644 --- a/src/rmi/socket.cpp +++ b/src/rmi/socket.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -218,7 +219,6 @@ void Socket::receiveFileDescriptors(int* fds, const size_t nr) const } } -#ifdef USE_SYSTEMD_SOCKET_ACTIVATION int Socket::createSystemdSocket(const std::string& path) { int n = ::sd_listen_fds(-1); @@ -235,7 +235,6 @@ int Socket::createSystemdSocket(const std::string& path) return -1; } -#endif int Socket::createRegularSocket(const std::string& path) { @@ -279,18 +278,15 @@ int Socket::createRegularSocket(const std::string& path) return sockfd; } -Socket Socket::create(const std::string& path) +Socket Socket::create(const std::string& path, bool activation) { - int fd; + int fd = -1; -#ifdef USE_SYSTEMD_SOCKET_ACTIVATION - fd = createSystemdSocket(path); - if (fd == -1) { + if (activation) + fd = createSystemdSocket(path); + + if (fd == -1) fd = createRegularSocket(path); - } -#else - fd = createRegularSocket(path); -#endif return Socket(fd); }