From: Sangwan Kwon Date: Mon, 6 Jan 2020 09:56:16 +0000 (+0900) Subject: Add compile-time switching to RMI socket X-Git-Tag: submit/tizen/20200810.073515~108 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1acb5188105035efc2856423563e80a8cb55f599;p=platform%2Fcore%2Fsecurity%2Fvist.git Add compile-time switching to RMI socket We should apply on-demand service based systemd. But docker does not support systemd. So, we need to switch socket at compile-time. - Docker: boost based socket - Tizen: systemd based socket Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/rmi/gateway.cpp b/src/vist/rmi/gateway.cpp index 72768c7..1a2c2e6 100644 --- a/src/vist/rmi/gateway.cpp +++ b/src/vist/rmi/gateway.cpp @@ -19,7 +19,12 @@ #include #include #include + +#ifdef TIZEN +#include +#else #include +#endif #include #include @@ -48,9 +53,13 @@ public: reply.enclose(result); return reply; - }; + }; +#ifdef TIZEN + this->server = std::make_unique(path, dispatcher); +#else this->server = std::make_unique(path, dispatcher); +#endif } inline void start() diff --git a/src/vist/rmi/impl/ondemand/server.hpp b/src/vist/rmi/impl/ondemand/server.hpp index 5745fbd..5a898e6 100644 --- a/src/vist/rmi/impl/ondemand/server.hpp +++ b/src/vist/rmi/impl/ondemand/server.hpp @@ -21,6 +21,10 @@ #include #include +#ifdef TIZEN +#include +#endif + #include #include @@ -39,7 +43,11 @@ class Server : public interface::Server { public: Server(const std::string& path, const interface::Task& task) : interface::Server(path, task), +#ifdef TIZEN + socket(SystemdSocket::Create(path)) +#else socket(path) +#endif { this->accept(task); } diff --git a/src/vist/rmi/impl/ondemand/systemd-socket.hpp b/src/vist/rmi/impl/ondemand/systemd-socket.hpp new file mode 100644 index 0000000..d952dd0 --- /dev/null +++ b/src/vist/rmi/impl/ondemand/systemd-socket.hpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + */ + +#pragma once + +#include +#include + +#include +#include +#include + +namespace vist { +namespace rmi { +namespace impl { +namespace ondemand { + +class SystemdSocket { +public: + static int Create(const std::string& path) + { + static int fds = -1; + + if (fds == -1) + fds = ::sd_listen_fds(0); + + if (fds < 0) + THROW(ErrCode::RuntimeError) << "Failed to get listened systemd fds."; + + for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + fds; ++fd) { + if (::sd_is_socket_unix(fd, SOCK_STREAM, 1, path.c_str(), 0) > 0) { + INFO(VIST) << "Systemd socket of service is found with fd: " << fd; + return fd; + } + } + + THROW(ErrCode::RuntimeError) << "Failed to find listened systemd fds."; + } +}; + +} // namespace ondemand +} // namespace impl +} // namespace rmi +} // namespace vist diff --git a/src/vist/rmi/remote.cpp b/src/vist/rmi/remote.cpp index 8d3b722..9f8923e 100644 --- a/src/vist/rmi/remote.cpp +++ b/src/vist/rmi/remote.cpp @@ -17,7 +17,12 @@ #include "remote.hpp" #include + +#ifdef TIZEN +#include +#else #include +#endif #include #include @@ -30,8 +35,13 @@ using namespace vist::rmi::impl; class Remote::Impl { public: - explicit Impl(const std::string& path) : client(std::make_unique(path)) + explicit Impl(const std::string& path) { +#ifdef TIZEN + this->client = std::make_unique(path); +#else + this->client = std::make_unique(path); +#endif } Message request(Message& message)