From: Sangwan Kwon Date: Mon, 23 Dec 2019 05:13:00 +0000 (+0900) Subject: Enable dlog only when the vist is running on Tizen X-Git-Tag: submit/tizen/20200810.073515~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ceded23e95d0fd6ffcbe17a65ca2ab0d32308b1;p=platform%2Fcore%2Fsecurity%2Fvist.git Enable dlog only when the vist is running on Tizen Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/CMakeLists.txt b/src/vist/CMakeLists.txt index 30d8026..65b8c3c 100644 --- a/src/vist/CMakeLists.txt +++ b/src/vist/CMakeLists.txt @@ -24,6 +24,7 @@ IF(DEFINED GBS_BUILD) SET(DEPENDENCY sqlite3 dlog gflags) PKG_CHECK_MODULES(VIST_COMMON_DEPS REQUIRED ${DEPENDENCY}) INCLUDE_DIRECTORIES(${VIST_COMMON_DEPS_INCLUDE_DIRS}) + ADD_DEFINITIONS(-DTIZEN="TIZEN") ENDIF(DEFINED GBS_BUILD) INCLUDE_DIRECTORIES(SYSTEM . common ${VIST_COMMON_DEPS_INCLUDE_DIRS}) diff --git a/src/vist/client/CMakeLists.txt b/src/vist/client/CMakeLists.txt index 0cf045c..0655f15 100644 --- a/src/vist/client/CMakeLists.txt +++ b/src/vist/client/CMakeLists.txt @@ -18,9 +18,7 @@ ADD_VIST_CLIENT_LIBRARY(vist_client query.cpp virtual-table.cpp) FILE(GLOB CLIENT_TESTS "tests/*.cpp") -#IF(DEFINED GBS_BUILD) - ADD_VIST_TEST(${CLIENT_TESTS}) - #ENDIF(DEFINED GBS_BUILD) +ADD_VIST_TEST(${CLIENT_TESTS}) ADD_LIBRARY(${TARGET_VIST_CLIENT_LIB} STATIC ${${TARGET_VIST_CLIENT_LIB}_SRCS}) TARGET_LINK_LIBRARIES(${TARGET_VIST_CLIENT_LIB} ${VIST_CLIENT_DEPS_LIBRARIES} diff --git a/src/vist/client/query.cpp b/src/vist/client/query.cpp index 5b1cbed..dcb84bd 100644 --- a/src/vist/client/query.cpp +++ b/src/vist/client/query.cpp @@ -30,7 +30,7 @@ Rows Query::Execute(const std::string& statement) INFO(VIST_CLIENT) << "Query execution: " << statement; rmi::Remote remote(SOCK_ADDR); - auto query = REMOTE_METHOD(remote, &Vist::query); + auto query = REMOTE_METHOD(remote, &Vistd::query); return query.invoke(statement); } diff --git a/src/vist/main/main.cpp b/src/vist/main/main.cpp index 8e64bbc..3288acc 100644 --- a/src/vist/main/main.cpp +++ b/src/vist/main/main.cpp @@ -14,17 +14,26 @@ * limitations under the License */ -#include +#include #include #include #include +#ifdef TIZEN +#include +#endif + using namespace vist; int main() try { - Vist::Instance().start(); +#ifdef TIZEN + LogStream::Init(std::make_shared()); +#endif + + Vistd::Instance().start(); + return EXIT_SUCCESS; } catch(const Exception& e) { ERROR(VIST) << "Failed while daemon is running." << e.what(); diff --git a/src/vist/service/CMakeLists.txt b/src/vist/service/CMakeLists.txt index ee1c427..983e1d2 100644 --- a/src/vist/service/CMakeLists.txt +++ b/src/vist/service/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License -ADD_VIST_LIBRARY(vist_core vist.cpp) +ADD_VIST_LIBRARY(vist_core vistd.cpp) FILE(GLOB CORE_TESTS "tests/*.cpp") ADD_VIST_TEST(${CORE_TESTS}) diff --git a/src/vist/service/tests/core.cpp b/src/vist/service/tests/core.cpp index 35a518d..8b32945 100644 --- a/src/vist/service/tests/core.cpp +++ b/src/vist/service/tests/core.cpp @@ -16,7 +16,7 @@ #include -#include +#include #include #include @@ -29,12 +29,12 @@ class CoreTests : public testing::Test {}; TEST_F(CoreTests, query_select) { - auto rows = Vist::Query("SELECT * FROM policy"); + auto rows = Vistd::Query("SELECT * FROM policy"); EXPECT_TRUE(rows.size() > 0); std::string statement = "SELECT * FROM policy WHERE name = 'sample-int-policy'"; - rows = Vist::Query(statement); + rows = Vistd::Query(statement); EXPECT_EQ(rows.size(), 1); EXPECT_EQ(rows[0]["name"], "sample-int-policy"); @@ -45,16 +45,16 @@ TEST_F(CoreTests, query_update) policy::API::Admin::Enroll("admin"); std::string statement = "SELECT * FROM policy WHERE name = 'sample-int-policy'"; - auto rows = Vist::Query(statement); + auto rows = Vistd::Query(statement); /// Initial policy value EXPECT_EQ(rows[0]["value"], "I/7"); statement = "UPDATE policy SET value = 'I/10' WHERE name = 'sample-int-policy'"; - rows = Vist::Query(statement); + rows = Vistd::Query(statement); EXPECT_EQ(rows.size(), 0); statement = "SELECT * FROM policy WHERE name = 'sample-int-policy'"; - rows = Vist::Query(statement); + rows = Vistd::Query(statement); EXPECT_EQ(rows[0]["value"], "I/10"); policy::API::Admin::Disenroll("admin"); diff --git a/src/vist/service/vist.cpp b/src/vist/service/vist.cpp deleted file mode 100644 index be4b68c..0000000 --- a/src/vist/service/vist.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 - */ - -#include "vist.hpp" - -#include -#include -#include - -#include -#include - -namespace { - const std::string SOCK_ADDR = "/tmp/.vist"; -} // anonymous namespace - -namespace vist { - -Vist::Vist() -{ - osquery::registryAndPluginInit(); -} - -void Vist::start() -{ - INFO(VIST) << "Vist daemon starts."; - rmi::Gateway gateway(SOCK_ADDR); - - EXPOSE(gateway, this, &Vist::query); - gateway.start(); -} - -Rows Vist::query(const std::string& statement) -{ - osquery::SQL sql(statement, true); - if (!sql.ok()) - THROW(ErrCode::RuntimeError) << "Faild to execute query: " << sql.getMessageString(); - - return std::move(sql.rows()); -} - -} // namespace vist diff --git a/src/vist/service/vist.hpp b/src/vist/service/vist.hpp deleted file mode 100644 index ab8b8df..0000000 --- a/src/vist/service/vist.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 { - -using Row = std::map; -using Rows = std::vector; - -class Vist final { -public: - ~Vist() = default; - - Vist(const Vist&) = delete; - Vist& operator=(const Vist&) = delete; - - Vist(Vist&&) = default; - Vist& operator=(Vist&&) = default; - - /// Exposed method (API) - Rows query(const std::string& statement); - - static Vist& Instance() - { - static Vist instance; - return instance; - } - - static Rows Query(const std::string& statement) - { - return Vist::Instance().query(statement); - } - - void start(); - -private: - explicit Vist(); -}; - -} // namespace vist diff --git a/src/vist/service/vistd.cpp b/src/vist/service/vistd.cpp new file mode 100644 index 0000000..0c16cff --- /dev/null +++ b/src/vist/service/vistd.cpp @@ -0,0 +1,55 @@ +/* + * 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 + */ + +#include "vistd.hpp" + +#include +#include +#include + +#include +#include + +namespace { + const std::string SOCK_ADDR = "/tmp/.vist"; +} // anonymous namespace + +namespace vist { + +Vistd::Vistd() +{ + osquery::registryAndPluginInit(); +} + +void Vistd::start() +{ + INFO(VIST) << "Vistd daemon starts."; + rmi::Gateway gateway(SOCK_ADDR); + + EXPOSE(gateway, this, &Vistd::query); + gateway.start(); +} + +Rows Vistd::query(const std::string& statement) +{ + osquery::SQL sql(statement, true); + if (!sql.ok()) + THROW(ErrCode::RuntimeError) << "Faild to execute query: " << sql.getMessageString(); + + return std::move(sql.rows()); +} + +} // namespace vist diff --git a/src/vist/service/vistd.hpp b/src/vist/service/vistd.hpp new file mode 100644 index 0000000..e5f4bb3 --- /dev/null +++ b/src/vist/service/vistd.hpp @@ -0,0 +1,58 @@ +/* + * 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 { + +using Row = std::map; +using Rows = std::vector; + +class Vistd final { +public: + ~Vistd() = default; + + Vistd(const Vistd&) = delete; + Vistd& operator=(const Vistd&) = delete; + + Vistd(Vistd&&) = default; + Vistd& operator=(Vistd&&) = default; + + /// Exposed method (API) + Rows query(const std::string& statement); + + static Vistd& Instance() + { + static Vistd instance; + return instance; + } + + static Rows Query(const std::string& statement) + { + return Vistd::Instance().query(statement); + } + + void start(); + +private: + explicit Vistd(); +}; + +} // namespace vist