From: Sangwan Kwon Date: Tue, 31 Dec 2019 04:39:36 +0000 (+0900) Subject: Add systemd socket X-Git-Tag: accepted/tizen/unified/20200810.122954~120 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee1a7b3931720d7cbbe27eca9f01e2259cc79ede;p=platform%2Fcore%2Fsecurity%2Fvist.git Add systemd socket Signed-off-by: Sangwan Kwon --- diff --git a/packaging/vist.spec b/packaging/vist.spec index 247bc98..4f18b9f 100644 --- a/packaging/vist.spec +++ b/packaging/vist.spec @@ -23,6 +23,7 @@ BuildRequires: pkgconfig(openssl) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(libsystemd-daemon) Requires: glog Requires: gflag Requires: boost-regex boost-system boost-thread boost-filesystem diff --git a/src/vist/CMakeLists.txt b/src/vist/CMakeLists.txt index 65b8c3c..bf217bd 100644 --- a/src/vist/CMakeLists.txt +++ b/src/vist/CMakeLists.txt @@ -21,7 +21,10 @@ SET(${TARGET_VIST_LIB}_TESTS "") SET(${TARGET_VIST_COMMON_LIB}_SRCS "") IF(DEFINED GBS_BUILD) - SET(DEPENDENCY sqlite3 dlog gflags) + SET(DEPENDENCY sqlite3 + dlog + gflags + libsystemd-daemon) PKG_CHECK_MODULES(VIST_COMMON_DEPS REQUIRED ${DEPENDENCY}) INCLUDE_DIRECTORIES(${VIST_COMMON_DEPS_INCLUDE_DIRS}) ADD_DEFINITIONS(-DTIZEN="TIZEN") diff --git a/src/vist/transport/systemd-socket.hpp b/src/vist/transport/systemd-socket.hpp new file mode 100644 index 0000000..4d768ed --- /dev/null +++ b/src/vist/transport/systemd-socket.hpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019 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 + +namespace vist { +namespace transport { + +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 transport +} // namespace vist