From 1c6e9b79ab4d7705bd85241e54923d6d514f58f3 Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Wed, 22 Jul 2015 15:18:09 +0200 Subject: [PATCH 01/16] Main page in Markdown format [Feature] N/A [Cause] N/A [Solution] N/A [Verification] ./generate_documentation.sh and verify Change-Id: I6b4f55de7f48bb66b3dd40a2313b6137919f028f --- doc/custom.css | 2 +- doc/doxygen.cfg | 10 +++++----- doc/mainpage.dox | 12 ------------ doc/mainpage.md | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 18 deletions(-) delete mode 100644 doc/mainpage.dox create mode 100644 doc/mainpage.md diff --git a/doc/custom.css b/doc/custom.css index 301ee53..726b998 100644 --- a/doc/custom.css +++ b/doc/custom.css @@ -1,7 +1,7 @@ /* The standard CSS for doxygen 1.8.6 */ body, table, div, p, dl { - font: 400 14px/22px Roboto,sans-serif; + font: 400 16px/24px Roboto,sans-serif; } /* @group Heading Levels */ diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg index 99e7685..40e7b49 100644 --- a/doc/doxygen.cfg +++ b/doc/doxygen.cfg @@ -743,11 +743,11 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = ../common \ - ../client \ - ../server \ - ../cli \ - mainpage.dox +INPUT = ../common \ + ../client \ + ../server \ + ../cli \ + mainpage.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/doc/mainpage.dox b/doc/mainpage.dox deleted file mode 100644 index b3b7f34..0000000 --- a/doc/mainpage.dox +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @mainpage Vasum - * - * Vasum is an environment separation mechanism based on Linux Containers (LXC). The idea behind - * the project is to easily create separate environments (for example Tizen operating systems) - * running on one physical device. What differs Vasum from other currently available environment - * separation mechanisms is its ease of use - Vasum comes with pre-defined templates to easily - * create new environments, and high configurability. - * - * For now Vasum uses LXC for Linux Containers management. The project is mostly written in modern - * C++ and is well tested. - */ diff --git a/doc/mainpage.md b/doc/mainpage.md new file mode 100644 index 0000000..74635db --- /dev/null +++ b/doc/mainpage.md @@ -0,0 +1,17 @@ +Introduction {#mainpage} +============ + +[Vasum](https://wiki.tizen.org/wiki/Security:Vasum) is a Linux daemon and a set of utilities used for managing para-virtualization. It uses Linux Containers to create separate, graphical environments called the *zones*. One can concurrently run several zones on one physical device. Vasum exports a rich C/DBus API that the application frameworks can use to interact with zones. + + +For now Vasum uses [LXC](https://linuxcontainers.org/lxc/introduction/) for Linux Containers management. The project is mostly written in modern C++ and is [well tested](https://wiki.tizen.org/wiki/Weekly_test_results_for_Tizen_3.X_security_framework). + +Vasum's development takes place on [review.tizen.org/gerrit/](http://review.tizen.org/gerrit/) (registration on [tizen.org](http://tizen.org) is required). + +## Installation and usage + +The installation process and simple verification is described [here](https://wiki.tizen.org/wiki/Security:Vasum:Usage "Vasum on Tizen"). + +## API + +Vasum daemon can be accessed via C API or DBus. You can find the API documentation [here](https://wiki.tizen.org/wiki/Security:Vasum:API). Be aware that the API will most likely change in the near future. -- 2.7.4 From 55883266a8a176536ccdeff814680d840d8c9baf Mon Sep 17 00:00:00 2001 From: Lukasz Kostyra Date: Mon, 20 Jul 2015 13:18:41 +0200 Subject: [PATCH 02/16] Fix Doxygen warnings [Bug] Doxygen warnings during documentation generation. [Cause] Some docblocks were incomplete. [Solution] Fix warnings. [Verification] Build, run tests, ./generate_documentation.sh. During doc generation there will be warnings related to command-line-interface.hpp stating "no matching file memeber". This is a Doxygen bug and the only possible fix is to replace Args typedef with std::vector. Change-Id: I1523dc83a5f5e9902e5983ac5b95497d61f71cfc --- client/vasum-client.h | 19 +++++++++++-------- common/utils/latch.hpp | 6 +++--- server/fake-power-manager-dbus-definitions.hpp | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/client/vasum-client.h b/client/vasum-client.h index 4544893..cd38aee 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -743,8 +743,8 @@ VsmStatus vsm_netdev_down(VsmClient client, * * @param[in] client vasum-server's client * @param[in] zone zone name - * @param[in] zoneDev in host network device id - * @param[in] hostDev in zone network device id + * @param[in] zoneDev Device ID in Zone network + * @param[in] hostDev Device ID in Host network * @return status of this function call */ VsmStatus vsm_create_netdev_veth(VsmClient client, @@ -752,13 +752,16 @@ VsmStatus vsm_create_netdev_veth(VsmClient client, const char* zoneDev, const char* hostDev); /** - * Create macvlab in zone + * Create macvlan in zone * - * @param[in] client vasum-server's client - * @param[in] zone zone name - * @param[in] zoneDev in host network device id - * @param[in] hostDev in zone network device id + * @param[in] client vasum-server's client + * @param[in] zone Zone name + * @param[in] zoneDev Device ID in Zone network + * @param[in] hostDev Device ID in Host network + * @param[in] mode Mode with which macvlan will be created. * @return status of this function call + * + * @see macvlan_mode */ VsmStatus vsm_create_netdev_macvlan(VsmClient client, const char* zone, @@ -866,7 +869,7 @@ VsmStatus vsm_declare_link(VsmClient client, * Get all declarations * * Gets all declarations of resourcies - * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki) + * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_file) * * @param[in] client vasum-server's client * @param[in] zone zone id diff --git a/common/utils/latch.hpp b/common/utils/latch.hpp index ad48475..4c46daf 100644 --- a/common/utils/latch.hpp +++ b/common/utils/latch.hpp @@ -61,14 +61,14 @@ public: bool wait(const unsigned int timeoutMs); /** - * Waits for @ref n occurrences of event. + * Waits for @n occurrences of event. * - * @param n number of occurrences to wait for + * @param n number of occurrences to wait for */ void waitForN(const unsigned int n); /** - * Waits for @ref n occurrences of event with timeout. + * Waits for @n occurrences of event with timeout. * * @param n number of occurrences to wait for * @param timeoutMs timeout in ms to wait for diff --git a/server/fake-power-manager-dbus-definitions.hpp b/server/fake-power-manager-dbus-definitions.hpp index 0abeb73..a9931aa 100644 --- a/server/fake-power-manager-dbus-definitions.hpp +++ b/server/fake-power-manager-dbus-definitions.hpp @@ -17,7 +17,7 @@ */ /** - * @file fake-power-manager-dbus-definitions.h + * @file * @author Lukasz Kostyra (l.kostyra@samsung.com) * @brief Declaration of fake dbus definitions from power-manager. Made only to test API in * ZoneConnection. -- 2.7.4 From af340cab5cd8d531cd57458dcfa173bd89319b33 Mon Sep 17 00:00:00 2001 From: Lukasz Kostyra Date: Wed, 22 Jul 2015 15:34:12 +0200 Subject: [PATCH 03/16] Enable file path stripping in Doxygen [Feature] N/A [Cause] N/A [Solution] N/A [Verification] ./generate_documentation.sh, access file's doc and check page title Change-Id: I9f05262a5ec73327492aad722b15393335fc46c1 --- doc/doxygen.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg index 40e7b49..3373847 100644 --- a/doc/doxygen.cfg +++ b/doc/doxygen.cfg @@ -144,7 +144,7 @@ FULL_PATH_NAMES = YES # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH = +STRIP_FROM_PATH = ../ # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which -- 2.7.4 From eb997958fb16998ac0a5a2c659d3a69aa1922e92 Mon Sep 17 00:00:00 2001 From: Lukasz Kostyra Date: Thu, 23 Jul 2015 08:06:23 +0200 Subject: [PATCH 04/16] Modify generate_documentation.sh [Feature] N/A [Cause] N/A [Solution] N/A [Verification] Run script, output html dir should be in doc directory. Run without doxygen installed, should exit with an error message. Change-Id: Ibfc0026da771ba1415f034ce8e81eaeb1deab0c2 --- doc/generate_documentation.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/generate_documentation.sh b/doc/generate_documentation.sh index f36bf06..e9f4721 100755 --- a/doc/generate_documentation.sh +++ b/doc/generate_documentation.sh @@ -2,4 +2,19 @@ DOC_CFG="doxygen.cfg" +# Check if doxy is visible +echo -n "Checking for doxygen... " +EXE_PATH=$(which doxygen) +if [ ! -x "$EXE_PATH" ] ; then + echo "NOT FOUND, EXITING" +else + echo "FOUND" +fi + +# Change pwd to script dir, to keep the paths consistent +pushd . > /dev/null +cd "$(dirname "${BASH_SOURCE[0]}" )" + doxygen "$DOC_CFG" + +popd > /dev/null -- 2.7.4 From 1899a99c617d097cee2139003de16896ca78e66c Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Thu, 23 Jul 2015 14:28:21 +0200 Subject: [PATCH 05/16] Added libLogger's documentation [Feature] N/A [Cause] N/A [Solution] N/A [Verification] ./generate_documentation.sh and verify Change-Id: I53a75f358e0e9182f51334544cb5da9722182cf9 --- doc/doxygen.cfg | 7 +++--- libs/logger/backend.hpp | 3 ++- libs/logger/level.hpp | 16 ++++++++----- libs/logger/logger-scope.hpp | 5 ++++- libs/logger/logger.hpp | 53 ++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg index 3373847..8800673 100644 --- a/doc/doxygen.cfg +++ b/doc/doxygen.cfg @@ -747,6 +747,7 @@ INPUT = ../common \ ../client \ ../server \ ../cli \ + ../libs \ mainpage.md # This tag can be used to specify the character encoding of the source files @@ -896,7 +897,7 @@ USE_MDFILE_AS_MAINPAGE = # also VERBATIM_HEADERS is set to NO. # The default value is: NO. -SOURCE_BROWSER = YES +SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body of functions, # classes and enums directly into the documentation. @@ -915,13 +916,13 @@ STRIP_CODE_COMMENTS = YES # function all documented functions referencing it will be listed. # The default value is: NO. -REFERENCED_BY_RELATION = YES +REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES then for each documented function # all documented entities called/used by that function will be listed. # The default value is: NO. -REFERENCES_RELATION = YES +REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set # to YES, then the hyperlinks from functions in REFERENCES_RELATION and diff --git a/libs/logger/backend.hpp b/libs/logger/backend.hpp index 99b0c49..2866fbc 100644 --- a/libs/logger/backend.hpp +++ b/libs/logger/backend.hpp @@ -32,7 +32,8 @@ namespace logger { /** - * Abstract class for logger + * @brief Abstract class for logger backends + * @ingroup libLogger */ class LogBackend { public: diff --git a/libs/logger/level.hpp b/libs/logger/level.hpp index 7902301..fd33343 100644 --- a/libs/logger/level.hpp +++ b/libs/logger/level.hpp @@ -29,13 +29,17 @@ namespace logger { +/** + * @brief Available log levels + * @ingroup libLogger + */ enum class LogLevel { - TRACE, - DEBUG, - INFO, - WARN, - ERROR, - HELP + TRACE, ///< Most detailed log level + DEBUG, ///< Debug logs + INFO, ///< Information + WARN, ///< Warnings + ERROR, ///< Errors + HELP ///< Helper logs }; /** diff --git a/libs/logger/logger-scope.hpp b/libs/logger/logger-scope.hpp index cefd912..41a99bf 100644 --- a/libs/logger/logger-scope.hpp +++ b/libs/logger/logger-scope.hpp @@ -70,7 +70,10 @@ private: } // namespace logger -// macro to automatically create LoggerScope object +/** + * @brief Automatically create LoggerScope object which logs at the construction and destruction + * @ingroup libLogger + */ #define LOGS(MSG) logger::LoggerScope logScopeObj(__FILE__, __LINE__, __func__, \ logger::SStreamWrapper() << MSG, \ PROJECT_SOURCE_DIR) diff --git a/libs/logger/logger.hpp b/libs/logger/logger.hpp index 3a0dee4..328bd05 100644 --- a/libs/logger/logger.hpp +++ b/libs/logger/logger.hpp @@ -18,10 +18,44 @@ /** * @file - * @author Jan Olszak (j.olszak@samsung.com) - * @brief Logger + * @author Jan Olszak (j.olszak@samsung.com) + * @defgroup libLogger libLogger + * @brief C++ library for handling logging. + * + * There are few backends implemented and it's possible to create your own by inheriting after the @ref logger::LogBackend interface. + * + * Example usage: + * @code + * using namespace logger; + * + * // Set minimal logging level + * Logger::setLogLevel("TRACE"); + * + * + * // Set one of the possible backends: + * Logger::setLogBackend(new NullLogger()); + * Logger::setLogBackend(new SystemdJournalBackend()); + * Logger::setLogBackend(new FileBackend("/tmp/logs.txt")); + * Logger::setLogBackend(new SyslogBackend()); + * Logger::setLogBackend(new StderrBackend()); + * + * + * // All logs should be visible: + * LOGE("Error"); + * LOGW("Warning"); + * LOGI("Information"); + * LOGD("Debug"); + * LOGT("Trace"); + * LOGH("Helper"); + * + * { + * LOGS("Scope"); + * } + * + * @endcode */ + #ifndef COMMON_LOGGER_LOGGER_HPP #define COMMON_LOGGER_LOGGER_HPP @@ -57,6 +91,8 @@ public: } // namespace logger +/*@{*/ +/// @brief Generic logging macro #define LOG(SEVERITY, MESSAGE) \ do { \ if (logger::Logger::getLogLevel() <= logger::LogLevel::SEVERITY) { \ @@ -71,11 +107,24 @@ public: } \ } while (0) + +/// Logging errors #define LOGE(MESSAGE) LOG(ERROR, MESSAGE) + +/// Logging warnings #define LOGW(MESSAGE) LOG(WARN, MESSAGE) + +/// Logging information #define LOGI(MESSAGE) LOG(INFO, MESSAGE) + +/// Logging debug information #define LOGD(MESSAGE) LOG(DEBUG, MESSAGE) + +/// Logging helper information (for debugging purposes) #define LOGH(MESSAGE) LOG(HELP, MESSAGE) + +/// Logging tracing information #define LOGT(MESSAGE) LOG(TRACE, MESSAGE) #endif // COMMON_LOGGER_LOGGER_HPP +/*@}*/ \ No newline at end of file -- 2.7.4 From da007dabea6e5a0724844ed7eae1e48cd598b723 Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Fri, 17 Jul 2015 16:49:43 +0200 Subject: [PATCH 06/16] Clean up zones root path [Feature] Clean up zones root path (according to cleanUpZonesPath flag) [Cause] N/A [Solution] Added cleanUpZonesPath to daemon.conf which tells whether to remove unknown files from the zonesPath; Added (vsm_)clean_up_zones_root to cli and client [Verification] Build, install, create files in zonesPath, run vasum-server with different flag value, check if zonesPath is as it should; execute command Change-Id: I64a1656ef05ccd5fd7e83a48cd50234e2e6bd4b4 --- cli/command-line-interface.cpp | 7 ++ cli/command-line-interface.hpp | 7 ++ cli/main.cpp | 9 +++ client/vasum-client-impl.cpp | 9 +++ client/vasum-client-impl.hpp | 5 ++ client/vasum-client.cpp | 5 ++ client/vasum-client.h | 7 ++ server/configs/daemon.conf.in | 1 + server/host-dbus-connection.cpp | 6 ++ server/host-dbus-definitions.hpp | 3 + server/host-ipc-connection.cpp | 11 ++++ server/host-ipc-connection.hpp | 1 + server/host-ipc-definitions.hpp | 1 + server/zones-manager-config.hpp | 6 ++ server/zones-manager.cpp | 97 ++++++++++++++++++++++++++-- server/zones-manager.hpp | 1 + tests/unit_tests/configs/test-daemon.conf.in | 1 + 17 files changed, 173 insertions(+), 4 deletions(-) diff --git a/cli/command-line-interface.cpp b/cli/command-line-interface.cpp index cdd64b4..29dd4a3 100644 --- a/cli/command-line-interface.cpp +++ b/cli/command-line-interface.cpp @@ -649,5 +649,12 @@ void netdev_down(const Args& argv) argv[2].c_str())); } +void clean_up_zones_root(const Args& /* argv */) +{ + using namespace std::placeholders; + + CommandLineInterface::executeCallback(bind(vsm_clean_up_zones_root, _1)); +} + } // namespace cli } // namespace vasum diff --git a/cli/command-line-interface.hpp b/cli/command-line-interface.hpp index 54ea7b9..f13fab5 100644 --- a/cli/command-line-interface.hpp +++ b/cli/command-line-interface.hpp @@ -340,6 +340,13 @@ void netdev_up(const Args& argv); */ void netdev_down(const Args& argv); +/** + * Parses command line arguments and call vsm_clean_up_zones_root + * + * @see vsm_clean_up_zones_root + */ +void clean_up_zones_root(const Args& argv); + } // namespace cli } // namespace vasum diff --git a/cli/main.cpp b/cli/main.cpp index c5fe0c1..efff7c6 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -328,6 +328,15 @@ std::map commands = { {{"zone_id", "id zone name"}, {"netdev_id", "network device id"}} } + }, + { + "clean_up_zones_root", { + clean_up_zones_root, + "clean_up_zones_root", + "Clean up zones root directory", + MODE_COMMAND_LINE | MODE_INTERACTIVE, + {} + } } }; diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index d99b08b..78c2d8f 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -882,3 +882,12 @@ VsmStatus Client::vsm_remove_declaration(const char* id, VsmString declaration) }); } +VsmStatus Client::vsm_clean_up_zones_root() noexcept +{ + return coverException([&] { + mClient->callSync( + api::ipc::METHOD_CLEAN_UP_ZONES_ROOT, + std::make_shared()); + }); +} + diff --git a/client/vasum-client-impl.hpp b/client/vasum-client-impl.hpp index 57797c2..1195b66 100644 --- a/client/vasum-client-impl.hpp +++ b/client/vasum-client-impl.hpp @@ -340,6 +340,11 @@ public: */ VsmStatus vsm_remove_declaration(const char* zone, VsmString declaration) noexcept; + /** + * @see ::vsm_clean_up_zones_root + */ + VsmStatus vsm_clean_up_zones_root() noexcept; + private: struct Status { Status(); diff --git a/client/vasum-client.cpp b/client/vasum-client.cpp index ac77187..68496d5 100644 --- a/client/vasum-client.cpp +++ b/client/vasum-client.cpp @@ -390,3 +390,8 @@ API VsmStatus vsm_remove_declaration(VsmClient client, return getClient(client).vsm_remove_declaration(zone, declaration); } +API VsmStatus vsm_clean_up_zones_root(VsmClient client) +{ + return getClient(client).vsm_clean_up_zones_root(); +} + diff --git a/client/vasum-client.h b/client/vasum-client.h index cd38aee..06ad043 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -894,6 +894,13 @@ VsmStatus vsm_remove_declaration(VsmClient client, const char* zone, VsmString declaration); +/** + * Clean up zones root directory + * + * Removes all unknown zones root directory entry + * @return status of this function call + */ +VsmStatus vsm_clean_up_zones_root(VsmClient client); /** @} Host API */ diff --git a/server/configs/daemon.conf.in b/server/configs/daemon.conf.in index f3dd9fd..96d748f 100644 --- a/server/configs/daemon.conf.in +++ b/server/configs/daemon.conf.in @@ -2,6 +2,7 @@ "dbPath" : "/etc/vasum/vasum.db", "zoneIds" : [], "zonesPath" : "${DATA_DIR}/zones", + "cleanUpZonesPath" : false, "zoneImagePath" : "", "zoneTemplateDir" : "/etc/vasum/templates/", "runMountPointPrefix" : "/var/run/zones", diff --git a/server/host-dbus-connection.cpp b/server/host-dbus-connection.cpp index 53fc271..90a248b 100644 --- a/server/host-dbus-connection.cpp +++ b/server/host-dbus-connection.cpp @@ -405,6 +405,12 @@ void HostDbusConnection::onMessageCall(const std::string& objectPath, mZonesManagerPtr->handleSwitchToDefaultCall(EMPTY_CALLER, rb); return; } + + if (methodName == api::dbus::METHOD_CLEAN_UP_ZONES_ROOT) { + auto rb = std::make_shared>(result); + mZonesManagerPtr->handleCleanUpZonesRootCall(rb); + return; + } } void HostDbusConnection::onClientVanished(const std::string& name) diff --git a/server/host-dbus-definitions.hpp b/server/host-dbus-definitions.hpp index 7aeaf31..d06d087 100644 --- a/server/host-dbus-definitions.hpp +++ b/server/host-dbus-definitions.hpp @@ -66,6 +66,7 @@ const std::string METHOD_CREATE_FILE = "CreateFile"; const std::string METHOD_LOCK_QUEUE = "LockQueue"; const std::string METHOD_UNLOCK_QUEUE = "UnlockQueue"; const std::string METHOD_SWITCH_TO_DEFAULT = "SwitchToDefault"; +const std::string METHOD_CLEAN_UP_ZONES_ROOT = "CleanUpZonesRoot"; const std::string DEFINITION = "" @@ -205,6 +206,8 @@ const std::string DEFINITION = " " " " " " + " " + " " " " ""; diff --git a/server/host-ipc-connection.cpp b/server/host-ipc-connection.cpp index d3684b9..c2ba755 100644 --- a/server/host-ipc-connection.cpp +++ b/server/host-ipc-connection.cpp @@ -135,6 +135,9 @@ HostIPCConnection::HostIPCConnection(ipc::epoll::EventPoll& eventPoll, ZonesMana setCreateFileCallback(std::bind(&ZonesManager::handleCreateFileCall, mZonesManagerPtr, _1, _2)); + + setCleanUpZonesRootCallback(std::bind(&ZonesManager::handleCleanUpZonesRootCall, + mZonesManagerPtr, _1)); } HostIPCConnection::~HostIPCConnection() @@ -392,4 +395,12 @@ void HostIPCConnection::setCreateFileCallback(const Method::type& callback) +{ + typedef IPCMethodWrapper Callback; + mService->setMethodHandler( + api::ipc::METHOD_CLEAN_UP_ZONES_ROOT, + Callback::getWrapper(callback)); +} + } // namespace vasum diff --git a/server/host-ipc-connection.hpp b/server/host-ipc-connection.hpp index da3dbd4..47a7612 100644 --- a/server/host-ipc-connection.hpp +++ b/server/host-ipc-connection.hpp @@ -87,6 +87,7 @@ private: void setRevokeDeviceCallback(const Method::type& callback); void setSwitchToDefaultCallback(const Method::type& callback); void setCreateFileCallback(const Method::type& callback); + void setCleanUpZonesRootCallback(const Method::type& callback); std::unique_ptr mService; ZonesManager* mZonesManagerPtr; diff --git a/server/host-ipc-definitions.hpp b/server/host-ipc-definitions.hpp index 5fb6114..143f89d 100644 --- a/server/host-ipc-definitions.hpp +++ b/server/host-ipc-definitions.hpp @@ -60,6 +60,7 @@ const ::ipc::MethodID METHOD_CREATE_FILE = 27; const ::ipc::MethodID METHOD_LOCK_QUEUE = 28; const ::ipc::MethodID METHOD_UNLOCK_QUEUE = 29; const ::ipc::MethodID METHOD_SWITCH_TO_DEFAULT = 30; +const ::ipc::MethodID METHOD_CLEAN_UP_ZONES_ROOT = 31; } // namespace ipc } // namespace api diff --git a/server/zones-manager-config.hpp b/server/zones-manager-config.hpp index 6e4625f..e300e75 100644 --- a/server/zones-manager-config.hpp +++ b/server/zones-manager-config.hpp @@ -49,6 +49,11 @@ struct ZonesManagerConfig { std::string zonesPath; /** + * If set then all files not related with existing containers will be removed + */ + bool cleanUpZonesPath; + + /** * A path where the zones image reside. Empty path means that zones image won't be * copied to zonesPath when creating new zone. */ @@ -83,6 +88,7 @@ struct ZonesManagerConfig { ( dbPath, zonesPath, + cleanUpZonesPath, zoneImagePath, zoneTemplateDir, availableVTs, diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 0787be0..484b3e9 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -45,6 +45,8 @@ #include #include #include +#include +#include namespace vasum { @@ -61,6 +63,11 @@ const boost::regex ZONE_IP_THIRD_OCTET_REGEX("~IP~"); const unsigned int ZONE_IP_BASE_THIRD_OCTET = 100; +const std::vector prohibitedZonesNames{ + ENABLED_FILE_NAME, + "lxc-monitord.log" +}; + template void remove(std::vector& v, const T& item) { @@ -97,6 +104,55 @@ bool zoneIsRunning(const std::unique_ptr& zone) { return zone->isRunning(); } +bool isalnum(const std::string& str) +{ + for (const auto& c : str) { + if (!std::isalnum(c)) { + return false; + } + } + return true; +} + +void cleanUpUnknownsFromRoot(const boost::filesystem::path& zonesPath, + const std::vector& zoneIds, + bool dryRun) +{ + namespace fs = boost::filesystem; + const auto end = fs::directory_iterator(); + + std::set knowns(zoneIds.begin(), zoneIds.end()); + knowns.insert(prohibitedZonesNames.begin(), prohibitedZonesNames.end()); + + // Remove all directories that start with '.' + for (auto zoneDir = fs::directory_iterator(zonesPath); zoneDir != end; ++zoneDir) { + if (zoneDir->path().filename().string()[0] == '.') { + if (!dryRun) { + fs::remove_all(zoneDir->path()); + LOGI("Remove directory entry: " << *zoneDir); + } else { + LOGI("Remove directory entry (dry run): " << *zoneDir); + } + } + } + + for (auto zoneDir = fs::directory_iterator(zonesPath); zoneDir != end; ++zoneDir) { + const auto zoneIt = knowns.find(zoneDir->path().filename().string()); + if (zoneIt == knowns.end()) { + if (!dryRun) { + const std::string filename = '.' + zoneDir->path().filename().string(); + fs::path newName = zoneDir->path().parent_path() / filename; + + fs::rename(zoneDir->path(), newName); + fs::remove_all(newName); + LOGI("Remove directory entry: " << *zoneDir); + } else { + LOGI("Remove directory entry (dry run): " << *zoneDir); + } + } + } +} + } // namespace @@ -133,6 +189,8 @@ void ZonesManager::start() mIsRunning = true; + cleanUpUnknownsFromRoot(mConfig.zonesPath, mDynamicConfig.zoneIds, !mConfig.cleanUpZonesPath); + #ifdef DBUS_CONNECTION using namespace std::placeholders; mProxyCallPolicy.reset(new ProxyCallPolicy(mConfig.proxyCallRules)); @@ -1132,11 +1190,16 @@ int ZonesManager::getVTForNewZone() void ZonesManager::createZone(const std::string& id, const std::string& templateName) { - if (id.empty()) { // TODO validate id (no spaces, slashes etc) + if (id.empty() || !isalnum(id)) { LOGE("Failed to add zone - invalid name."); throw InvalidZoneIdException("Invalid name"); } + if (find(prohibitedZonesNames.begin(), prohibitedZonesNames.end(), id) != prohibitedZonesNames.end()) { + LOGE("Cannot create " << id << " zone - name is not allowed!"); + throw InvalidZoneIdException("Zone name is not allowed"); + } + LOGI("Creating zone " << id); Lock lock(mMutex); @@ -1151,6 +1214,12 @@ void ZonesManager::createZone(const std::string& id, throw InvalidZoneIdException("Already exists"); } + if (fs::exists(fs::path(mConfig.zonesPath) / id)) { + LOGE("Cannot create " << id << " zone - file system already exists!"); + throw InvalidZoneIdException("Zone file system already exists but there is no configuration for it. " + "Check cleanUpZonesPath in daemon.conf"); + } + const std::string zonePathStr = utils::createFilePath(mConfig.zonesPath, id, "/"); // copy zone image if config contains path to image @@ -1210,9 +1279,9 @@ void ZonesManager::handleCreateZoneCall(const api::CreateZoneIn& data, createZone(data.first, data.second); result->setVoid(); } catch (const InvalidZoneIdException& e) { - result->setError(api::ERROR_INVALID_ID, "Existing or invalid zone id"); - } catch (const std::runtime_error& e) { - result->setError(api::ERROR_INTERNAL, "Failed to create zone"); + result->setError(api::ERROR_INVALID_ID, e.what()); + } catch (const std::exception& e) { + result->setError(api::ERROR_INTERNAL, e.what()); } }; @@ -1456,4 +1525,24 @@ void ZonesManager::handleRevokeDeviceCall(const api::RevokeDeviceIn& data, tryAddTask(handler, result, true); } +void ZonesManager::handleCleanUpZonesRootCall(api::MethodResultBuilder::Pointer result) +{ + auto handler = [&, this] { + LOGI("CleanUpZonesRoot call"); + try { + std::vector zonesIds; + Lock lock(mMutex); + for (const auto& zone : mZones) { + zonesIds.push_back(zone->getId()); + } + cleanUpUnknownsFromRoot(mConfig.zonesPath, zonesIds, false); + } catch (const std::exception& e) { + result->setError(api::ERROR_INTERNAL, e.what()); + } + result->setVoid(); + }; + + tryAddTask(handler, result, true); +} + } // namespace vasum diff --git a/server/zones-manager.hpp b/server/zones-manager.hpp index 6a7a2c4..de6663d 100644 --- a/server/zones-manager.hpp +++ b/server/zones-manager.hpp @@ -196,6 +196,7 @@ public: api::MethodResultBuilder::Pointer result); void handleSwitchToDefaultCall(const std::string& caller, api::MethodResultBuilder::Pointer result); + void handleCleanUpZonesRootCall(api::MethodResultBuilder::Pointer result); private: typedef std::recursive_mutex Mutex; diff --git a/tests/unit_tests/configs/test-daemon.conf.in b/tests/unit_tests/configs/test-daemon.conf.in index 5151fbe..66ca69f 100644 --- a/tests/unit_tests/configs/test-daemon.conf.in +++ b/tests/unit_tests/configs/test-daemon.conf.in @@ -2,6 +2,7 @@ "dbPath" : "/tmp/ut-zones/vasum.db", "zoneIds" : [], "zonesPath" : "/tmp/ut-zones", + "cleanUpZonesPath" : false, "zoneImagePath" : "", "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/templates/", "runMountPointPrefix" : "", -- 2.7.4 From bb2451e1f9c5fc978b9773ca316cca99e5b78b2a Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Fri, 24 Jul 2015 11:25:51 +0200 Subject: [PATCH 07/16] Added libvasum-client's documentation [Feature] N/A [Cause] N/A [Solution] N/A [Verification] ./generate_documentation.sh and verify Change-Id: I9ec902cce2b29ca2d81fa8ca40db11977e0f3c3f --- client/vasum-client.h | 206 +++++++++++++++++++++++++------------------------ doc/doxygen.cfg | 2 +- libs/logger/logger.hpp | 2 +- 3 files changed, 106 insertions(+), 104 deletions(-) diff --git a/client/vasum-client.h b/client/vasum-client.h index 06ad043..0c65d17 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -19,13 +19,23 @@ /** * @file - * @author Mateusz Malicki (m.malicki2@samsung.com) - * @brief This file contains the public API for Vasum Client + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief This file contains the public API for Vasum Client + * @defgroup libvasum-client libvasum-client + * @brief C library for interfacing Vasum + * + * All functionalities that are possible using the Vasum's Command Line Interface can also be done with libvasum-client's calls. + * + * @par Simple usage: + * Basic usage: + * - Create VsmClient with vsm_client_create(). It'll be needed for all communication with Vasum. + * - Establish the connection with the daemon using vsm_connect() + * - Do what you need to do with the zones + * - Free the client with vsm_client_free() * - * @par Example usage: * @code #include -#include "client/vasum-client.h" +#include int main(int argc, char** argv) { @@ -34,14 +44,16 @@ int main(int argc, char** argv) VsmArrayString values = NULL; int ret = 0; - client = vsm_client_create(); // create client handle + // Create client handle + client = vsm_client_create(); if (NULL == client) { // error! ret = 1; goto finish; } - status = vsm_connect(client); // connect to dbus + // Connect to Vasum + status = vsm_connect(client); if (VSMCLIENT_SUCCESS != status) { // error! ret = 1; @@ -66,8 +78,82 @@ finish: return ret; } @endcode - */ + * @par Polling loop + * + * By default libVasum will create a separate thread for his communication with Vasum. Most of the time it'll sleep so it shouldn't be a concern. + * It's also possible to connect to an existing polling loop. To do this you'll need to: + * - Get the poll file descriptor with vsm_get_poll_fd() + * - Use epoll/poll/select to wait for events on the file descriptor + * - Call vsm_enter_eventloop() every time there's an event + * + * For example: + * @code +#include +#include +#include +#include +#include +#include + +volatile static sig_atomic_t running; +static int LOOP_INTERVAL = 1000; // ms + +void* main_loop(void* client) +{ + int fd = -1; + VsmStatus status = vsm_get_poll_fd(client, &fd); + assert(VSMCLIENT_SUCCESS == status); + + while (running) { + struct epoll_event event; + int num = epoll_wait(fd, &event, 1, LOOP_INTERVAL); + if (num > 0) { + status = vsm_enter_eventloop(client, 0 , 0); + assert(VSMCLIENT_SUCCESS == status); + } + } + return NULL; +} + +int main(int argc, char** argv) +{ + pthread_t loop; + VsmStatus status; + VsmClient client; + int ret = 0; + + client = vsm_client_create(); + assert(client); + + status = vsm_set_dispatcher_type(client, VSMDISPATCHER_EXTERNAL); + assert(VSMCLIENT_SUCCESS == status); + + status = vsm_connect(client); + assert(VSMCLIENT_SUCCESS == status); + + // start event loop + running = 1; + ret = pthread_create(&loop, NULL, main_loop, client); + assert(ret == 0); + + // make vsm_* calls on client + // ... + + status = vsm_disconnect(client); + assert(VSMCLIENT_SUCCESS == status); + + //stop event loop + running = 0; + ret = pthread_join(loop, NULL); + assert(ret == 0); + + vsm_client_free(client); // destroy client handle + return ret; +} + @endcode + */ +/*@{*/ #ifndef VASUM_CLIENT_H #define VASUM_CLIENT_H @@ -82,34 +168,34 @@ extern "C" #endif /** - * vasum-server's client pointer. + * vasum-server's opaque client pointer. */ typedef void* VsmClient; /** * NULL-terminated string type. * - * @sa vsm_array_string_free + * @sa vsm_string_free */ typedef char* VsmString; /** * NULL-terminated array of strings type. * - * @sa vsm_string_free + * @sa vsm_array_string_free */ typedef VsmString* VsmArrayString; /** - * Completion status of communication function. + * Completion status of libvasum-client's functions */ typedef enum { - VSMCLIENT_CUSTOM_ERROR, /**< User specified error */ - VSMCLIENT_IO_ERROR, /**< Input/Output error */ - VSMCLIENT_OPERATION_FAILED, /**< Operation failed */ - VSMCLIENT_INVALID_ARGUMENT, /**< Invalid argument */ - VSMCLIENT_OTHER_ERROR, /**< Other error */ - VSMCLIENT_SUCCESS /**< Success */ + VSMCLIENT_CUSTOM_ERROR, ///< User specified error + VSMCLIENT_IO_ERROR, ///< Input/Output error + VSMCLIENT_OPERATION_FAILED, ///< Operation failed + VSMCLIENT_INVALID_ARGUMENT, ///< Invalid argument + VSMCLIENT_OTHER_ERROR, ///< Other error + VSMCLIENT_SUCCESS ///< Success } VsmStatus; /** @@ -182,72 +268,6 @@ typedef enum { /** * Event dispacher types. - * - * @par Example usage: - * @code -#include -#include -#include -#include -#include -#include - -volatile static sig_atomic_t running; -static int LOOP_INTERVAL = 1000; // ms - -void* main_loop(void* client) -{ - int fd = -1; - VsmStatus status = vsm_get_poll_fd(client, &fd); - assert(VSMCLIENT_SUCCESS == status); - - while (running) { - struct epoll_event event; - int num = epoll_wait(fd, &event, 1, LOOP_INTERVAL); - if (num > 0) { - status = vsm_enter_eventloop(client, 0 , 0); - assert(VSMCLIENT_SUCCESS == status); - } - } - return NULL; -} - -int main(int argc, char** argv) -{ - pthread_t loop; - VsmStatus status; - VsmClient client; - int ret = 0; - - client = vsm_client_create(); - assert(client); - - status = vsm_set_dispatcher_type(client, VSMDISPATCHER_EXTERNAL); - assert(VSMCLIENT_SUCCESS == status); - - status = vsm_connect(client); - assert(VSMCLIENT_SUCCESS == status); - - // start event loop - running = 1; - ret = pthread_create(&loop, NULL, main_loop, client); - assert(ret == 0); - - // make vsm_* calls on client - // ... - - status = vsm_disconnect(client); - assert(VSMCLIENT_SUCCESS == status); - - //stop event loop - running = 0; - ret = pthread_join(loop, NULL); - assert(ret == 0); - - vsm_client_free(client); // destroy client handle - return ret; -} - @endcode */ typedef enum { VSMDISPATCHER_EXTERNAL, /**< User must handle dispatching messages */ @@ -385,14 +405,6 @@ void vsm_zone_free(VsmZone zone); void vsm_netdev_free(VsmNetdev netdev); /** - * @name Host API - * - * Functions using org.tizen.vasum.host.manager D-Bus interface. - * - * @{ - */ - -/** * Zone's D-Bus state change callback function signature. * * @param[in] zoneId affected zone id @@ -894,17 +906,6 @@ VsmStatus vsm_remove_declaration(VsmClient client, const char* zone, VsmString declaration); -/** - * Clean up zones root directory - * - * Removes all unknown zones root directory entry - * @return status of this function call - */ -VsmStatus vsm_clean_up_zones_root(VsmClient client); - -/** @} Host API */ - - #endif /* __VASUM_WRAPPER_SOURCE__ */ #ifdef __cplusplus @@ -912,3 +913,4 @@ VsmStatus vsm_clean_up_zones_root(VsmClient client); #endif #endif /* VASUM_CLIENT_H */ +/*@}*/ \ No newline at end of file diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg index 8800673..1fb18aa 100644 --- a/doc/doxygen.cfg +++ b/doc/doxygen.cfg @@ -169,7 +169,7 @@ SHORT_NAMES = NO # description.) # The default value is: NO. -JAVADOC_AUTOBRIEF = NO +JAVADOC_AUTOBRIEF = YES # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If diff --git a/libs/logger/logger.hpp b/libs/logger/logger.hpp index 328bd05..e27d3dd 100644 --- a/libs/logger/logger.hpp +++ b/libs/logger/logger.hpp @@ -92,7 +92,7 @@ public: } // namespace logger /*@{*/ -/// @brief Generic logging macro +/// Generic logging macro #define LOG(SEVERITY, MESSAGE) \ do { \ if (logger::Logger::getLogLevel() <= logger::LogLevel::SEVERITY) { \ -- 2.7.4 From dcc8a62a9d61b5e7a608e911fe48f5aa57e843d9 Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Fri, 24 Jul 2015 14:28:35 +0200 Subject: [PATCH 08/16] Fix build break in clang [Feature] N/A [Cause] No new line in vasum-client.h [Solution] N/A [Verification] N/A Change-Id: Ic4cf72d42a173edeb0a6d450c1f2aad12bb22a59 --- client/vasum-client.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/vasum-client.h b/client/vasum-client.h index 0c65d17..156bbf1 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -906,6 +906,14 @@ VsmStatus vsm_remove_declaration(VsmClient client, const char* zone, VsmString declaration); +/** + * Clean up zones root directory + * + * Removes all unknown zones root directory entry + * @return status of this function call + */ +VsmStatus vsm_clean_up_zones_root(VsmClient client); + #endif /* __VASUM_WRAPPER_SOURCE__ */ #ifdef __cplusplus @@ -913,4 +921,4 @@ VsmStatus vsm_remove_declaration(VsmClient client, #endif #endif /* VASUM_CLIENT_H */ -/*@}*/ \ No newline at end of file +/*@}*/ -- 2.7.4 From 96bec66aef183cf28a99e15a29cbcf7b1ba61332 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 27 Jul 2015 09:41:42 +0200 Subject: [PATCH 09/16] Fix build break [Bug] C++ style comments are not allowed in ISO C90 [Cause] N/A [Solution] N/A [Verification] Build Change-Id: Iab690af9fc085c0707aacb83b901c3efde5ae638 --- client/vasum-client.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/vasum-client.h b/client/vasum-client.h index 156bbf1..fbdd3b1 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -190,12 +190,12 @@ typedef VsmString* VsmArrayString; * Completion status of libvasum-client's functions */ typedef enum { - VSMCLIENT_CUSTOM_ERROR, ///< User specified error - VSMCLIENT_IO_ERROR, ///< Input/Output error - VSMCLIENT_OPERATION_FAILED, ///< Operation failed - VSMCLIENT_INVALID_ARGUMENT, ///< Invalid argument - VSMCLIENT_OTHER_ERROR, ///< Other error - VSMCLIENT_SUCCESS ///< Success + VSMCLIENT_CUSTOM_ERROR, /**< User specified error */ + VSMCLIENT_IO_ERROR, /**< Input/Output error */ + VSMCLIENT_OPERATION_FAILED, /**< Operation failed */ + VSMCLIENT_INVALID_ARGUMENT, /**< Invalid argument */ + VSMCLIENT_OTHER_ERROR, /**< Other error */ + VSMCLIENT_SUCCESS /**< Success */ } VsmStatus; /** -- 2.7.4 From be7eb71996c2aaeadfa31372accf75c00a314a9f Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Thu, 23 Jul 2015 15:48:09 +0200 Subject: [PATCH 10/16] lxcpp skeleton [Feature] N/A [Cause] N/A [Solution] N/A [Verification] N/A Change-Id: I1950967edc720ad9b81301daa4e1b60ff8c3b41d --- CMakeLists.txt | 2 + libs/lxcpp/CMakeLists.txt | 53 +++++++++++++++++++++++ libs/lxcpp/container-impl.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++ libs/lxcpp/container-impl.hpp | 57 +++++++++++++++++++++++++ libs/lxcpp/container.hpp | 56 +++++++++++++++++++++++++ libs/lxcpp/exception.hpp | 46 ++++++++++++++++++++ libs/lxcpp/liblxcpp.pc.in | 12 ++++++ libs/lxcpp/lxcpp.cpp | 34 +++++++++++++++ libs/lxcpp/lxcpp.hpp | 36 ++++++++++++++++ packaging/vasum.spec | 33 +++++++++++++++ 10 files changed, 427 insertions(+) create mode 100644 libs/lxcpp/CMakeLists.txt create mode 100644 libs/lxcpp/container-impl.cpp create mode 100644 libs/lxcpp/container-impl.hpp create mode 100644 libs/lxcpp/container.hpp create mode 100644 libs/lxcpp/exception.hpp create mode 100644 libs/lxcpp/liblxcpp.pc.in create mode 100644 libs/lxcpp/lxcpp.cpp create mode 100644 libs/lxcpp/lxcpp.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 76a2344..4e9e4d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,7 @@ ENDIF(NOT DEFINED PYTHON_SITELIB) SET(COMMON_FOLDER ${PROJECT_SOURCE_DIR}/common) SET(LIBS_FOLDER ${PROJECT_SOURCE_DIR}/libs) SET(LOGGER_FOLDER ${PROJECT_SOURCE_DIR}/libs/logger) +SET(LXCPP_FOLDER ${PROJECT_SOURCE_DIR}/libs/lxcpp) SET(DBUS_FOLDER ${PROJECT_SOURCE_DIR}/libs/dbus) SET(CONFIG_FOLDER ${PROJECT_SOURCE_DIR}/libs/config) SET(IPC_FOLDER ${PROJECT_SOURCE_DIR}/libs/ipc) @@ -190,6 +191,7 @@ SET(VSM_SERVER_IPC_SOCKET_PATH ${RUN_DIR}/vasum.socket) SET(VSM_UNIT_TESTS_IPC_SOCKET_PATH ${RUN_DIR}/vasum-ipc-unit-tests.socket) ADD_SUBDIRECTORY(${LOGGER_FOLDER}) +ADD_SUBDIRECTORY(${LXCPP_FOLDER}) ADD_SUBDIRECTORY(${DBUS_FOLDER}) ADD_SUBDIRECTORY(${CONFIG_FOLDER}) ADD_SUBDIRECTORY(${IPC_FOLDER}) diff --git a/libs/lxcpp/CMakeLists.txt b/libs/lxcpp/CMakeLists.txt new file mode 100644 index 0000000..fa63074 --- /dev/null +++ b/libs/lxcpp/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright (c) 2015 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. +# +# +# @file CMakeLists.txt +# @author Mateusz Malicki (m.malicki2@samsung.com) +# + +PROJECT(lxcpp) + +MESSAGE(STATUS "") +MESSAGE(STATUS "Generating makefile for the liblxcpp...") +FILE(GLOB HEADERS *.hpp) +FILE(GLOB SRCS *.cpp *.hpp) + +SET(_LIB_VERSION_ "${VERSION}") +SET(_LIB_SOVERSION_ "0") +SET(PC_FILE "lib${PROJECT_NAME}.pc") + +## Setup target ################################################################ +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES + SOVERSION ${_LIB_SOVERSION_} + VERSION ${_LIB_VERSION_} +) + +## Link libraries ############################################################## +INCLUDE_DIRECTORIES(${LIBS_FOLDER}) + +## Generate the pc file ######################################################## +CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} @ONLY) + +## Install ##################################################################### +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} + DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +INSTALL(TARGETS ${PROJECT_NAME} + DESTINATION ${LIB_INSTALL_DIR} + COMPONENT RuntimeLibraries) + +INSTALL(FILES ${HEADERS} + DESTINATION ${INCLUDE_INSTALL_DIR}/lxcpp) diff --git a/libs/lxcpp/container-impl.cpp b/libs/lxcpp/container-impl.cpp new file mode 100644 index 0000000..c0fd907 --- /dev/null +++ b/libs/lxcpp/container-impl.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 + */ + +/** + * @file + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief ContainerImpl definition + */ + +#include +#include + +namespace lxcpp { + +ContainerImpl::ContainerImpl() +{ +} + +ContainerImpl::~ContainerImpl() +{ +} + +std::string ContainerImpl::getName() +{ + throw NotImplemented(); +} + +void ContainerImpl::setName(const std::string& /* name */) +{ + throw NotImplemented(); +} + +void ContainerImpl::start() +{ + throw NotImplemented(); +} + +void ContainerImpl::stop() +{ + throw NotImplemented(); +} + +void ContainerImpl::freeze() +{ + throw NotImplemented(); +} + +void ContainerImpl::unfreeze() +{ + throw NotImplemented(); +} + +void ContainerImpl::reboot() +{ + throw NotImplemented(); +} + +int ContainerImpl::getInitPid() +{ + throw NotImplemented(); +} + +void ContainerImpl::create() +{ + throw NotImplemented(); +} + +void ContainerImpl::destroy() +{ + throw NotImplemented(); +} + +void ContainerImpl::setRootPath(const std::string& /* path */) +{ + throw NotImplemented(); +} + +std::string getRootPath() +{ + throw NotImplemented(); +} + +} // namespace lxcpp diff --git a/libs/lxcpp/container-impl.hpp b/libs/lxcpp/container-impl.hpp new file mode 100644 index 0000000..e53684e --- /dev/null +++ b/libs/lxcpp/container-impl.hpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 + */ + +/** + * @file + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief ContainerImpl main class + */ + +#ifndef LXCPP_CONTAINER_IMPL_HPP +#define LXCPP_CONTAINER_IMPL_HPP + +#include + +namespace lxcpp { + +class ContainerImpl : public virtual Container { +public: + ContainerImpl(); + ~ContainerImpl(); + + std::string getName(); + void setName(const std::string& name); + + //Execution actions + void start(); + void stop(); + void freeze(); + void unfreeze(); + void reboot(); + int getInitPid(); + + //Filesystem actions + void create(); + void destroy(); + void setRootPath(const std::string& path); + std::string getRootPath(); +}; + +} // namespace lxcpp + +#endif // LXCPP_CONTAINER_IMPL_HPP diff --git a/libs/lxcpp/container.hpp b/libs/lxcpp/container.hpp new file mode 100644 index 0000000..b3ce50a --- /dev/null +++ b/libs/lxcpp/container.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 + */ + +/** + * @file + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief Container interface + */ + +#ifndef LXCPP_CONTAINER_HPP +#define LXCPP_CONTAINER_HPP + +#include + +namespace lxcpp { + +class Container { +public: + virtual ~Container(); + + virtual std::string getName() = 0; + virtual void setName(const std::string& name) = 0; + + //Execution actions + virtual void start() = 0; + virtual void stop() = 0; + virtual void freeze() = 0; + virtual void unfreeze() = 0; + virtual void reboot() = 0; + virtual int getInitPid() = 0; + + //Filesystem actions + virtual void create() = 0; + virtual void destroy() = 0; + virtual void setRootPath(const std::string& path) = 0; + virtual std::string getRootPath() = 0; +}; + +} // namespace lxcpp + +#endif // LXCPP_CONTAINER_HPP diff --git a/libs/lxcpp/exception.hpp b/libs/lxcpp/exception.hpp new file mode 100644 index 0000000..e841c0b --- /dev/null +++ b/libs/lxcpp/exception.hpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 + */ + +/** + * @file + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief lxcpp's exceptions definitions + */ + +#ifndef LXCPP_EXCEPTION_HPP +#define LXCPP_EXCEPTION_HPP + +#include + +namespace lxcpp { + +class ContainerException : std::runtime_error +{ +public: + ContainerException(const std::string& what) : std::runtime_error(what) {} +}; + +class NotImplemented : ContainerException +{ +public: + NotImplemented() : ContainerException(std::string()) {} +}; + +} // namespace lxcpp + +#endif // LXCPP_EXCEPTION_HPP diff --git a/libs/lxcpp/liblxcpp.pc.in b/libs/lxcpp/liblxcpp.pc.in new file mode 100644 index 0000000..812e495 --- /dev/null +++ b/libs/lxcpp/liblxcpp.pc.in @@ -0,0 +1,12 @@ +# Package Information for pkg-config + +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDE_INSTALL_DIR@ + +Name: liblxcpp +Description: Lxc library +Version: @_LIB_VERSION_@ +Libs: -L${libdir} -llxcpp +Cflags: -I${includedir} diff --git a/libs/lxcpp/lxcpp.cpp b/libs/lxcpp/lxcpp.cpp new file mode 100644 index 0000000..a81f8f9 --- /dev/null +++ b/libs/lxcpp/lxcpp.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 + */ + +/** + * @file + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief lxcpp container factory definition + */ + +#include + +namespace lxcpp { + +Container* createContainer() +{ + return new ContainerImpl(); +} + +} // namespace lxcpp diff --git a/libs/lxcpp/lxcpp.hpp b/libs/lxcpp/lxcpp.hpp new file mode 100644 index 0000000..a6b8437 --- /dev/null +++ b/libs/lxcpp/lxcpp.hpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * 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 + */ + +/** + * @file + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief LXCpp factory declaration + */ + +#ifndef LXCPP_LXCPP_HPP +#define LXCPP_LXCPP_HPP + +#include + +namespace lxcpp { + +Container* createContainer(); + +} // namespace lxcpp + +#endif // LXCPP_LXCPP_HPP diff --git a/packaging/vasum.spec b/packaging/vasum.spec index acb7ada..f1991d4 100644 --- a/packaging/vasum.spec +++ b/packaging/vasum.spec @@ -433,3 +433,36 @@ The package provides libIpc development tools and libs. %{_libdir}/libIpc.so %{_includedir}/vasum-tools/ipc %{_libdir}/pkgconfig/libIpc.pc + +## liblxcpp Package ########################################################### +%package -n liblxcpp +Summary: lxcpp library +Group: Security/Other +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description -n liblxcpp +The package provides liblxcpp library. + +%post -n liblxcpp -p /sbin/ldconfig + +%postun -n liblxcpp -p /sbin/ldconfig + +%files -n liblxcpp +%defattr(644,root,root,755) +%{_libdir}/liblxcpp.so.0 +%attr(755,root,root) %{_libdir}/liblxcpp.so.%{version} + +%package -n liblxcpp-devel +Summary: Development lxcpp library +Group: Development/Libraries +Requires: liblxcpp = %{epoch}:%{version}-%{release} + +%description -n liblxcpp-devel +The package provides liblxcpp development tools and libs. + +%files -n liblxcpp-devel +%defattr(644,root,root,755) +%{_libdir}/liblxcpp.so +%{_includedir}/lxcpp +%{_libdir}/pkgconfig/liblxcpp.pc -- 2.7.4 From e9075f02736cde33732de9dd26fac1aa0eaeb56b Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 17 Jul 2015 15:27:57 +0200 Subject: [PATCH 11/16] Various changes relating to build on Ubuntu and Fedora Linux. [Bug/Feature] Various changes relating to build on Ubuntu and Fedora Linux. [Cause] N/A [Solution] N/A Verification] Build, run server, run tests. Change-Id: Ie9f8c05a0de96b0dc07d506657a48f6dd1b074b4 --- CMakeLists.txt | 14 ++-- client/CMakeLists.txt | 9 ++- libs/config/CMakeLists.txt | 2 +- libs/config/from-json-visitor.hpp | 7 +- libs/config/from-kvjson-visitor.hpp | 6 +- libs/config/to-json-visitor.hpp | 13 ++-- libs/ipc/CMakeLists.txt | 4 +- libs/ipc/internals/socket.cpp | 9 ++- libs/logger/CMakeLists.txt | 10 ++- libs/logger/backend-journal.cpp | 5 +- packaging/vasum.spec | 64 +++++++++++++---- server/CMakeLists.txt | 8 ++- server/configs/CMakeLists.txt | 19 +++-- server/configs/templates/ubuntu.conf | 19 +++++ server/configs/templates/ubuntu.sh | 84 ++++++++++++++++++++++ server/host-dbus-connection.cpp | 2 + server/main.cpp | 5 +- tests/unit_tests/CMakeLists.txt | 28 ++++++-- tests/unit_tests/configs/CMakeLists.txt | 13 +++- .../configs/templates/buggy-template.conf | 2 +- .../configs/templates/console-dbus.conf.in | 2 +- .../configs/templates/console-ipc.conf.in | 2 +- tests/unit_tests/configs/templates/default.conf | 2 +- tests/unit_tests/configs/templates/missing.conf | 2 +- .../configs/templates/test-no-shutdown.conf | 2 +- tests/unit_tests/dbus/test-client.cpp | 2 + tests/unit_tests/dbus/test-server.cpp | 2 + tests/unit_tests/dbus/ut-connection.cpp | 4 +- tests/unit_tests/ipc/ut-socket.cpp | 2 + tests/unit_tests/lxc/ut-zone.cpp | 14 ++-- tests/unit_tests/server/ut-zone.cpp | 3 +- wrapper/CMakeLists.txt | 9 ++- zone-daemon/main.cpp | 6 +- 33 files changed, 282 insertions(+), 93 deletions(-) create mode 100644 server/configs/templates/ubuntu.conf create mode 100755 server/configs/templates/ubuntu.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e9e4d4..5203a6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ INCLUDE(FindPkgConfig) INCLUDE(GNUInstallDirs) ## Color output if it's possible: -IF (( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.3)) +IF (( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )) ADD_DEFINITIONS("-fdiagnostics-color=always") @@ -91,11 +91,6 @@ ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}") ADD_DEFINITIONS(-DUSE_EXEC) ADD_DEFINITIONS(-D__STDC_LIMIT_MACROS) -PKG_SEARCH_MODULE(JSON_C REQUIRED json json-c) -IF(JSON_C_VERSION GREATER 0.11) - ADD_DEFINITIONS(-DJSON_C_VERSION_NEW) -ENDIF(JSON_C_VERSION GREATER 0.11) - IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # Warn about documentation problems ADD_DEFINITIONS("-Wdocumentation") @@ -133,6 +128,9 @@ ADD_DEFINITIONS(-DTTY_GROUP="${TTY_GROUP}") IF(NOT WITHOUT_DBUS) ADD_DEFINITIONS(-DDBUS_CONNECTION) ENDIF(NOT WITHOUT_DBUS) +IF(NOT WITHOUT_SYSTEMD) + ADD_DEFINITIONS(-DHAVE_SYSTEMD) +ENDIF(NOT WITHOUT_SYSTEMD) ## Python packages directory ################################################### IF(NOT DEFINED PYTHON_SITELIB) @@ -192,13 +190,17 @@ SET(VSM_UNIT_TESTS_IPC_SOCKET_PATH ${RUN_DIR}/vasum-ipc-unit-tests.socket) ADD_SUBDIRECTORY(${LOGGER_FOLDER}) ADD_SUBDIRECTORY(${LXCPP_FOLDER}) +IF(NOT WITHOUT_DBUS) ADD_SUBDIRECTORY(${DBUS_FOLDER}) +ENDIF(NOT WITHOUT_DBUS) ADD_SUBDIRECTORY(${CONFIG_FOLDER}) ADD_SUBDIRECTORY(${IPC_FOLDER}) ADD_SUBDIRECTORY(${CLIENT_FOLDER}) ADD_SUBDIRECTORY(${SERVER_FOLDER}) +IF(NOT WITHOUT_DBUS) ADD_SUBDIRECTORY(${ZONE_SUPPORT_FOLDER}) ADD_SUBDIRECTORY(${ZONE_DAEMON_FOLDER}) +ENDIF(NOT WITHOUT_DBUS) ADD_SUBDIRECTORY(${TESTS_FOLDER}) ADD_SUBDIRECTORY(${CLI_FOLDER}) ADD_SUBDIRECTORY(${WRAPPER_FOLDER}) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 3fa44fd..f0d1828 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -45,13 +45,16 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ## Link libraries ############################################################## FIND_PACKAGE(Boost COMPONENTS system filesystem) PKG_CHECK_MODULES(LIB_DEPS REQUIRED gio-2.0) -INCLUDE_DIRECTORIES(SYSTEM ${LIB_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(SYSTEM ${LIB_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${JSON_C_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) INCLUDE_DIRECTORIES(${LIBS_FOLDER}) INCLUDE_DIRECTORIES(${IPC_FOLDER}) INCLUDE_DIRECTORIES(${SERVER_FOLDER}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIB_DEPS_LIBRARIES} ${Boost_LIBRARIES} - Config SimpleDbus Ipc) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIB_DEPS_LIBRARIES} ${Boost_LIBRARIES} Config Ipc) +IF(NOT WITHOUT_DBUS) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} SimpleDbus) +ENDIF(NOT WITHOUT_DBUS) ## Generate the pc file ######################################################## CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY) diff --git a/libs/config/CMakeLists.txt b/libs/config/CMakeLists.txt index fcc5e23..160cb09 100644 --- a/libs/config/CMakeLists.txt +++ b/libs/config/CMakeLists.txt @@ -38,7 +38,7 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ## Link libraries ############################################################## PKG_CHECK_MODULES(CONFIG_DEPS REQUIRED sqlite3 glib-2.0) -PKG_SEARCH_MODULE(JSON_C json json-c) +PKG_SEARCH_MODULE(JSON_C REQUIRED json json-c) INCLUDE_DIRECTORIES(${LIBS_FOLDER}) INCLUDE_DIRECTORIES(SYSTEM ${CONFIG_DEPS_INCLUDE_DIRS} ${JSON_C_INCLUDE_DIRS}) diff --git a/libs/config/from-json-visitor.hpp b/libs/config/from-json-visitor.hpp index 8831ef6..74d309b 100644 --- a/libs/config/from-json-visitor.hpp +++ b/libs/config/from-json-visitor.hpp @@ -28,12 +28,7 @@ #include "config/is-visitable.hpp" #include "config/exception.hpp" -#ifdef JSON_C_VERSION_NEW -#include -#else //JSON_C_VERSION_NEW -#include -#endif //JSON_C_VERSION_NEW - +#include #include #include diff --git a/libs/config/from-kvjson-visitor.hpp b/libs/config/from-kvjson-visitor.hpp index 943dbb8..eea975c 100644 --- a/libs/config/from-kvjson-visitor.hpp +++ b/libs/config/from-kvjson-visitor.hpp @@ -29,11 +29,7 @@ #include "config/from-kvstore-visitor.hpp" #include "config/is-union.hpp" -#ifdef JSON_C_VERSION_NEW -#include -#else //JSON_C_VERSION_NEW -#include -#endif //JSON_C_VERSION_NEW +#include namespace config { diff --git a/libs/config/to-json-visitor.hpp b/libs/config/to-json-visitor.hpp index 1b68438..4ab4a4b 100644 --- a/libs/config/to-json-visitor.hpp +++ b/libs/config/to-json-visitor.hpp @@ -28,12 +28,7 @@ #include "config/is-visitable.hpp" #include "config/exception.hpp" -#ifdef JSON_C_VERSION_NEW -#include -#else //JSON_C_VERSION_NEW -#include -#endif //JSON_C_VERSION_NEW - +#include #include #include @@ -113,11 +108,11 @@ private: static json_object* toJsonObject(double value) { -#ifdef JSON_C_VERSION_NEW +#if JSON_C_MINOR_VERSION >= 12 return json_object_new_double_s(value, std::to_string(value).c_str()); -#else //JSON_C_VERSION_NEW +#else return json_object_new_double(value); -#endif //JSON_C_VERSION_NEW +#endif } static json_object* toJsonObject(const std::string& value) diff --git a/libs/ipc/CMakeLists.txt b/libs/ipc/CMakeLists.txt index 84bb812..2fce8cb 100644 --- a/libs/ipc/CMakeLists.txt +++ b/libs/ipc/CMakeLists.txt @@ -49,11 +49,13 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ) ## Link libraries ############################################################## +IF(NOT WITHOUT_SYSTEMD) PKG_CHECK_MODULES(IPC_DEPS REQUIRED libsystemd-daemon) +ENDIF(NOT WITHOUT_SYSTEMD) INCLUDE_DIRECTORIES(${LIBS_FOLDER}) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) -INCLUDE_DIRECTORIES(SYSTEM ${DBUS_DEPS_INCLUDE_DIRS} ${IPC_DEPS_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(SYSTEM ${DBUS_DEPS_INCLUDE_DIRS} ${IPC_DEPS_INCLUDE_DIRS} ${CONFIG_DEPS_INCLUDE_DIRS} ${JSON_C_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${IPC_DEPS_LIBRARIES} Logger Config) ## Generate the pc file ######################################################## diff --git a/libs/ipc/internals/socket.cpp b/libs/ipc/internals/socket.cpp index 690bd43..1961a52 100644 --- a/libs/ipc/internals/socket.cpp +++ b/libs/ipc/internals/socket.cpp @@ -30,7 +30,9 @@ #include "utils/exception.hpp" #include "logger/logger.hpp" +#ifdef HAVE_SYSTEMD #include +#endif // HAVE_SYSTEMD #include #include #include @@ -112,6 +114,7 @@ void Socket::read(void* bufferPtr, const size_t size) const utils::read(mFD, bufferPtr, size); } +#ifdef HAVE_SYSTEMD int Socket::getSystemdSocketInternal(const std::string& path) { int n = ::sd_listen_fds(-1 /*Block further calls to sd_listen_fds*/); @@ -131,6 +134,7 @@ int Socket::getSystemdSocketInternal(const std::string& path) LOGW("No usable sockets were passed by systemd."); return -1; } +#endif // HAVE_SYSTEMD int Socket::createSocketInternal(const std::string& path) { @@ -178,7 +182,10 @@ int Socket::createSocketInternal(const std::string& path) Socket Socket::createSocket(const std::string& path) { // Initialize a socket - int fd = getSystemdSocketInternal(path); + int fd = -1; +#ifdef HAVE_SYSTEMD + fd = getSystemdSocketInternal(path); +#endif // HAVE_SYSTEMD fd = fd != -1 ? fd : createSocketInternal(path); return Socket(fd); diff --git a/libs/logger/CMakeLists.txt b/libs/logger/CMakeLists.txt index d1e82eb..61027c2 100644 --- a/libs/logger/CMakeLists.txt +++ b/libs/logger/CMakeLists.txt @@ -36,16 +36,14 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ) ## Link libraries ############################################################## -PKG_CHECK_MODULES(LOGGER_DEPS libsystemd-journal QUIET) +IF(NOT WITHOUT_SYSTEMD) +PKG_CHECK_MODULES(LOGGER_DEPS REQUIRED libsystemd-journal) +ENDIF(NOT WITHOUT_SYSTEMD) + INCLUDE_DIRECTORIES(${LIBS_FOLDER}) INCLUDE_DIRECTORIES(SYSTEM ${LOGGER_DEPS_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${LOGGER_DEPS_LIBRARIES}) -## Add constants ############################################################### -if(LOGGER_DEPS_FOUND) - ADD_DEFINITIONS(-DHAVE_SYSTEMD_JOURNAL=${LOGGER_DEPS_FOUND}) -endif() - ## Generate the pc file ######################################################## CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} @ONLY) diff --git a/libs/logger/backend-journal.cpp b/libs/logger/backend-journal.cpp index af147cd..769e6d7 100644 --- a/libs/logger/backend-journal.cpp +++ b/libs/logger/backend-journal.cpp @@ -21,7 +21,8 @@ * @author Dariusz Michaluk (d.michaluk@samsung.com) * @brief Systemd journal backend for logger */ -#ifdef HAVE_SYSTEMD_JOURNAL + +#ifdef HAVE_SYSTEMD #include "logger/config.hpp" #include "logger/backend-journal.hpp" @@ -69,4 +70,4 @@ void SystemdJournalBackend::log(LogLevel logLevel, } } // namespace logger -#endif // HAVE_SYSTEMD_JOURNAL +#endif // HAVE_SYSTEMD diff --git a/packaging/vasum.spec b/packaging/vasum.spec index f1991d4..0ec93da 100644 --- a/packaging/vasum.spec +++ b/packaging/vasum.spec @@ -10,6 +10,10 @@ %define tty_group tty # Default platform is Tizen, setup Fedora with --define 'platform_type FEDORA' %{!?platform_type:%define platform_type "TIZEN"} +# Default build with dbus +%{!?without_dbus:%define without_dbus 0} +# Default build with systemd +%{!?without_systemd:%define without_systemd 0} Name: vasum Epoch: 1 @@ -24,11 +28,18 @@ BuildRequires: boost-devel BuildRequires: pkgconfig(glib-2.0) BuildRequires: lxc-devel BuildRequires: readline-devel +BuildRequires: pkgconfig(sqlite3) Requires: lxc +%if !%{without_systemd} +BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(libsystemd-journal) +%endif %if %{platform_type} == "TIZEN" +BuildRequires: libjson-devel >= 0.10 Requires: iproute2 Requires(post): libcap-tools %else +BuildRequires: json-c-devel Requires: lxc-templates Requires: iproute Requires(post): libcap @@ -52,10 +63,14 @@ between them. A process from inside a zone can request a switch of context %config /etc/vasum/daemon.conf %attr(755,root,root) /etc/vasum/templates/*.sh %config /etc/vasum/templates/*.conf +%if !%{without_systemd} %{_unitdir}/vasum.service %{_unitdir}/vasum.socket %{_unitdir}/multi-user.target.wants/vasum.service +%endif +%if !%{without_dbus} %config /etc/dbus-1/system.d/org.tizen.vasum.host.conf +%endif %dir %{_datadir}/zones %prep @@ -79,13 +94,16 @@ between them. A process from inside a zone can request a switch of context -DINPUT_EVENT_GROUP=%{input_event_group} \ -DDISK_GROUP=%{disk_group} \ -DTTY_GROUP=%{tty_group} \ - -DWITHOUT_DBUS=%{?without_dbus} + -DWITHOUT_DBUS=%{?without_dbus} \ + -DWITHOUT_SYSTEMD=%{?without_systemd} make -k %{?jobs:-j%jobs} %install %make_install +%if !%{without_systemd} mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants ln -s ../vasum.service %{buildroot}/%{_unitdir}/multi-user.target.wants/vasum.service +%endif mkdir -p %{buildroot}/%{_datadir}/zones %if %{platform_type} == "TIZEN" ln -s tizen.conf %{buildroot}/etc/vasum/templates/default.conf @@ -97,20 +115,26 @@ ln -s fedora.conf %{buildroot}/etc/vasum/templates/default.conf rm -rf %{buildroot} %post +%if !%{without_systemd} # Refresh systemd services list after installation if [ $1 == 1 ]; then systemctl daemon-reload || : fi +%endif + # set needed caps on the binary to allow restart without loosing them setcap CAP_SYS_ADMIN,CAP_MAC_OVERRIDE,CAP_SYS_TTY_CONFIG+ei %{_bindir}/vasum-server %preun +%if !%{without_systemd} # Stop the service before uninstall if [ $1 == 0 ]; then systemctl stop vasum.service || : fi +%endif %postun +%if !%{without_systemd} # Refresh systemd services list after uninstall/upgrade systemctl daemon-reload || : if [ $1 -ge 1 ]; then @@ -123,6 +147,7 @@ if [ $1 -ge 1 ]; then else echo "Vasum removed. Reboot is required for the changes to take effect..." fi +%endif ## Client Package ############################################################## %package client @@ -172,7 +197,7 @@ Development package including the header files for the client library %{_libdir}/pkgconfig/vasum-client.pc %{_libdir}/pkgconfig/vasum.pc - +%if !%{without_dbus} ## Zone Support Package ################################################### %package zone-support Summary: Vasum Support @@ -205,7 +230,7 @@ Daemon running inside every zone. %defattr(644,root,root,755) %attr(755,root,root) %{_bindir}/vasum-zone-daemon %config /etc/dbus-1/system.d/org.tizen.vasum.zone.daemon.conf - +%endif ## Command Line Interface ###################################################### %package cli @@ -248,16 +273,22 @@ Requires: boost-test Unit tests for both: server and client and integration tests. %post tests -systemctl daemon-reload -systemctl enable vasum-socket-test.socket -systemctl start vasum-socket-test.socket +%if !%{without_systemd} +systemctl daemon-reload || : +systemctl enable vasum-socket-test.socket || : +systemctl start vasum-socket-test.socket || : +%endif %preun tests -systemctl stop vasum-socket-test.socket -systemctl disable vasum-socket-test.socket +%if !%{without_systemd} +systemctl stop vasum-socket-test.socket || : +systemctl disable vasum-socket-test.socket || : +%endif %postun tests -systemctl daemon-reload +%if !%{without_systemd} +systemctl daemon-reload || : +%endif %files tests %if %{platform_type} == "TIZEN" @@ -265,27 +296,32 @@ systemctl daemon-reload %endif %defattr(644,root,root,755) %attr(755,root,root) %{_bindir}/vasum-server-unit-tests +%if !%{without_systemd} %attr(755,root,root) %{_bindir}/vasum-socket-test +%endif %attr(755,root,root) %{script_dir}/vsm_all_tests.py %attr(755,root,root) %{script_dir}/vsm_int_tests.py %attr(755,root,root) %{script_dir}/vsm_launch_test.py %{script_dir}/vsm_test_parser.py %config /etc/vasum/tests/*.conf +%if !%{without_dbus} %config /etc/vasum/tests/dbus/*.conf +%config /etc/dbus-1/system.d/org.tizen.vasum.tests.conf +%endif %config /etc/vasum/tests/provision/*.conf %config /etc/vasum/tests/templates/*.conf %attr(755,root,root) /etc/vasum/tests/templates/*.sh %config /etc/vasum/tests/utils/*.txt %{python_sitelib}/vsm_integration_tests -%config /etc/dbus-1/system.d/org.tizen.vasum.tests.conf +%if !%{without_systemd} %{_unitdir}/vasum-socket-test.socket %{_unitdir}/vasum-socket-test.service +%endif ## libLogger Package ########################################################### %package -n libLogger Summary: Logger library Group: Security/Other -BuildRequires: pkgconfig(libsystemd-journal) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -315,6 +351,7 @@ The package provides libLogger development tools and libs. %{_includedir}/vasum-tools/logger %{_libdir}/pkgconfig/libLogger.pc +%if !%{without_dbus} ## libSimpleDbus Package ####################################################### %package -n libSimpleDbus Summary: Simple dbus library @@ -348,17 +385,15 @@ The package provides libSimpleDbus development tools and libs. %{_libdir}/libSimpleDbus.so %{_includedir}/vasum-tools/dbus %{_libdir}/pkgconfig/libSimpleDbus.pc +%endif ## libConfig Package ########################################################## %package -n libConfig Summary: Config library Group: Security/Other -BuildRequires: pkgconfig(sqlite3) %if %{platform_type} == "TIZEN" -BuildRequires: libjson-devel >= 0.10 Requires: libjson >= 0.10 %else -BuildRequires: json-c-devel Requires: json-c %endif Requires(post): /sbin/ldconfig @@ -401,7 +436,6 @@ The package provides libConfig development tools and libs. %package -n libIpc Summary: IPC library Group: Security/Other -BuildRequires: pkgconfig(libsystemd-daemon) Requires: libConfig Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index b301d00..58c50f6 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -35,7 +35,7 @@ PKG_CHECK_MODULES(SERVER_DEPS REQUIRED lxc glib-2.0 gio-2.0) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) INCLUDE_DIRECTORIES(${LIBS_FOLDER}) INCLUDE_DIRECTORIES(${CLIENT_FOLDER}) -INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${JSON_C_INCLUDE_DIRS}) SET_TARGET_PROPERTIES(${SERVER_CODENAME} PROPERTIES COMPILE_FLAGS "-pthread" @@ -43,8 +43,10 @@ SET_TARGET_PROPERTIES(${SERVER_CODENAME} PROPERTIES LINK_FLAGS "-pthread" ) -TARGET_LINK_LIBRARIES(${SERVER_CODENAME} ${SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES} - Logger Config SimpleDbus Ipc) +TARGET_LINK_LIBRARIES(${SERVER_CODENAME} ${SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES} Logger Config Ipc) +IF(NOT WITHOUT_DBUS) +TARGET_LINK_LIBRARIES(${SERVER_CODENAME} SimpleDbus) +ENDIF(NOT WITHOUT_DBUS) ## Subdirectories ############################################################## ADD_SUBDIRECTORY(configs) diff --git a/server/configs/CMakeLists.txt b/server/configs/CMakeLists.txt index 09254a5..c91b3e4 100644 --- a/server/configs/CMakeLists.txt +++ b/server/configs/CMakeLists.txt @@ -23,25 +23,29 @@ FILE(GLOB zone_templates_CONF templates/*.conf) FILE(GLOB lxc_templates_CONF templates/*.sh) ## Generate #################################################################### +IF(NOT WITHOUT_SYSTEMD) CONFIGURE_FILE(systemd/vasum.service.in ${CMAKE_BINARY_DIR}/systemd/vasum.service) CONFIGURE_FILE(systemd/vasum.socket.in ${CMAKE_BINARY_DIR}/systemd/vasum.socket) +ENDIF(NOT WITHOUT_SYSTEMD) - -## Install ##################################################################### CONFIGURE_FILE(daemon.conf.in ${CMAKE_BINARY_DIR}/daemon.conf) -INSTALL(FILES ${CMAKE_BINARY_DIR}/daemon.conf - DESTINATION ${VSM_CONFIG_INSTALL_DIR}) - -# preprocess d-bus configs +IF(NOT WITHOUT_DBUS) CONFIGURE_FILE(dbus-1/system.d/org.tizen.vasum.host.conf.in ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.vasum.host.conf) +ENDIF(NOT WITHOUT_DBUS) +## Install ##################################################################### +INSTALL(FILES ${CMAKE_BINARY_DIR}/daemon.conf + DESTINATION ${VSM_CONFIG_INSTALL_DIR}) + +IF(NOT WITHOUT_DBUS) INSTALL(FILES ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.vasum.host.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) +ENDIF(NOT WITHOUT_DBUS) INSTALL(DIRECTORY DESTINATION ${DATA_DIR}/zones) @@ -51,7 +55,10 @@ INSTALL(FILES ${zone_templates_CONF} INSTALL(PROGRAMS ${lxc_templates_CONF} DESTINATION ${VSM_CONFIG_INSTALL_DIR}/templates) +IF(NOT WITHOUT_SYSTEMD) INSTALL(FILES ${CMAKE_BINARY_DIR}/systemd/vasum.service ${CMAKE_BINARY_DIR}/systemd/vasum.socket DESTINATION ${SYSTEMD_UNIT_DIR}) +ENDIF(NOT WITHOUT_SYSTEMD) + diff --git a/server/configs/templates/ubuntu.conf b/server/configs/templates/ubuntu.conf new file mode 100644 index 0000000..baa9a75 --- /dev/null +++ b/server/configs/templates/ubuntu.conf @@ -0,0 +1,19 @@ +{ + "zoneTemplate" : "ubuntu.sh", + "initWithArgs" : [], + "requestedState" : "stopped", + "ipv4Gateway" : "", + "ipv4" : "", + "cpuQuotaForeground" : -1, + "cpuQuotaBackground" : 1000, + "privilege" : 10, + "vt" : -1, + "shutdownTimeout" : 10, + "switchToDefaultAfterTimeout" : true, + "runMountPoint" : "~NAME~/run", + "provisions" : [], + "validLinkPrefixes" : [ "/tmp/", + "/run/", + "/opt/usr/data/", + "/opt/usr/dbsapce/" ] +} diff --git a/server/configs/templates/ubuntu.sh b/server/configs/templates/ubuntu.sh new file mode 100755 index 0000000..edcf649 --- /dev/null +++ b/server/configs/templates/ubuntu.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# template script for creating Ubuntu LXC container +# This script is a wrapper for the lxc-ubuntu template +# +# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +# +# Contact: Dariusz Michaluk +# +# 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. + +usage() +{ + cat < + [-p|--path=] [--rootfs=] [--vt=] + [--ipv4=] [--ipv4-gateway=] [-h|--help] +Mandatory args: + -n,--name zone name + -p,--path path to zone config files + --rootfs path to zone rootfs +Optional args: + --vt zone virtual terminal + --ipv4 zone IP address + --ipv4-gateway zone gateway + -h,--help print help +EOF + return 0 +} + +options=$(getopt -o hp:n: -l help,rootfs:,path:,vt:,name:,ipv4:,ipv4-gateway: -- "$@") +if [ $? -ne 0 ]; then + usage $(basename $0) + exit 1 +fi +eval set -- "$options" + +while true +do + case "$1" in + -h|--help) usage $0 && exit 0;; + --rootfs) rootfs=$2; shift 2;; + -p|--path) path=$2; shift 2;; + --vt) vt=$2; shift 2;; + -n|--name) name=$2; shift 2;; + --ipv4) ipv4=$2; shift 2;; + --ipv4-gateway) ipv4_gateway=$2; shift 2;; + --) shift 1; break ;; + *) break ;; + esac +done + +if [ "$(id -u)" != "0" ]; then + echo "This script should be run as 'root'" + exit 1 +fi + +if [ -z $name ]; then + echo "Zone name must be given" + exit 1 +fi + +if [ -z "$path" ]; then + echo "'path' parameter is required" + exit 1 +fi + +if [ -z "$rootfs" ]; then + echo "'rootfs' parameter is required" + exit 1 +fi + +/usr/share/lxc/templates/lxc-ubuntu --name="$name" --path="$path" --rootfs="$rootfs" diff --git a/server/host-dbus-connection.cpp b/server/host-dbus-connection.cpp index 90a248b..1229acb 100644 --- a/server/host-dbus-connection.cpp +++ b/server/host-dbus-connection.cpp @@ -22,6 +22,7 @@ * @brief Implementation of a class for communication with server */ +#ifdef DBUS_CONNECTION #include "config.hpp" #include "host-dbus-connection.hpp" @@ -447,3 +448,4 @@ void HostDbusConnection::proxyCallAsync(const std::string& busName, } } // namespace vasum +#endif //DBUS_CONNECTION diff --git a/server/main.cpp b/server/main.cpp index fafa788..707eb50 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -36,6 +36,7 @@ #include "logger/logger.hpp" #include "logger/backend-stderr.hpp" #include "logger/backend-journal.hpp" +#include "logger/backend-syslog.hpp" #include "utils/typeinfo.hpp" #include "utils/signal.hpp" @@ -110,8 +111,10 @@ int main(int argc, char* argv[]) Logger::setLogLevel(vm["log-level"].as()); #ifdef LOG_TO_CONSOLE Logger::setLogBackend(new StderrBackend()); -#else +#elif HAVE_SYSTEMD Logger::setLogBackend(new SystemdJournalBackend()); +#else + Logger::setLogBackend(new SyslogBackend()); #endif runAsRoot = vm.count("root") > 0; diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 46a9a3b..aa652c7 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -34,15 +34,17 @@ LIST(REMOVE_ITEM project_SRCS ${socket_test_SRCS}) ## Setup target ################################################################ SET(UT_SERVER_CODENAME "${PROJECT_NAME}-server-unit-tests") -SET(SOCKET_TEST_CODENAME "${PROJECT_NAME}-socket-test") ADD_EXECUTABLE(${UT_SERVER_CODENAME} ${project_SRCS} ${common_SRCS} ${server_SRCS} ${client_SRCS}) ## A fake target to test vasum-client C API ADD_EXECUTABLE("vasum-client-c-api-compile-test" client/client-c-api-compile-test.c) +IF(NOT WITHOUT_SYSTEMD) +SET(SOCKET_TEST_CODENAME "${PROJECT_NAME}-socket-test") + ## A stub mini-service to test socket functionality ADD_EXECUTABLE(${SOCKET_TEST_CODENAME} ${socket_test_SRCS} ${common_SRCS} ${client_SRCS}) - +ENDIF(NOT WITHOUT_SYSTEMD) ## Link libraries ############################################################## FIND_PACKAGE (Boost COMPONENTS unit_test_framework system filesystem regex) @@ -50,7 +52,7 @@ FIND_PACKAGE (Boost COMPONENTS unit_test_framework system filesystem regex) PKG_CHECK_MODULES(UT_SERVER_DEPS REQUIRED lxc gio-2.0) INCLUDE_DIRECTORIES(${COMMON_FOLDER} ${SERVER_FOLDER} ${UNIT_TESTS_FOLDER} ${CLIENT_FOLDER} ${LIBS_FOLDER} ${SOCKET_TEST_FOLDER}) -INCLUDE_DIRECTORIES(SYSTEM ${UT_SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(SYSTEM ${UT_SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${JSON_C_INCLUDE_DIRS}) SET_TARGET_PROPERTIES(${UT_SERVER_CODENAME} PROPERTIES COMPILE_FLAGS "-pthread" @@ -58,16 +60,26 @@ SET_TARGET_PROPERTIES(${UT_SERVER_CODENAME} PROPERTIES LINK_FLAGS "-pthread" ) +TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES} + Logger Config Ipc) +IF(NOT WITHOUT_DBUS) +TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} SimpleDbus) +ENDIF(NOT WITHOUT_DBUS) + +IF(NOT WITHOUT_SYSTEMD) SET_TARGET_PROPERTIES(${SOCKET_TEST_CODENAME} PROPERTIES COMPILE_FLAGS "-pthread" COMPILE_DEFINITIONS HOST_IPC_SOCKET="${VSM_UNIT_TESTS_IPC_SOCKET_PATH}" LINK_FLAGS "-pthread" ) -TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES} - Logger Config SimpleDbus Ipc) TARGET_LINK_LIBRARIES(${SOCKET_TEST_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES} - Logger Config SimpleDbus Ipc) + Logger Config Ipc) +IF(NOT WITHOUT_DBUS) +TARGET_LINK_LIBRARIES(${SOCKET_TEST_CODENAME} SimpleDbus) +ENDIF(NOT WITHOUT_DBUS) + +ENDIF(NOT WITHOUT_SYSTEMD) ## Subdirectories ############################################################## SET(VSM_TEST_CONFIG_INSTALL_DIR ${VSM_CONFIG_INSTALL_DIR}/tests) @@ -79,4 +91,8 @@ ADD_SUBDIRECTORY(configs) ## Install ##################################################################### INSTALL(TARGETS ${UT_SERVER_CODENAME} DESTINATION bin) + +IF(NOT WITHOUT_SYSTEMD) INSTALL(TARGETS ${SOCKET_TEST_CODENAME} DESTINATION bin) +ENDIF(NOT WITHOUT_SYSTEMD) + diff --git a/tests/unit_tests/configs/CMakeLists.txt b/tests/unit_tests/configs/CMakeLists.txt index 6bffac4..a6fcbac 100644 --- a/tests/unit_tests/configs/CMakeLists.txt +++ b/tests/unit_tests/configs/CMakeLists.txt @@ -28,15 +28,18 @@ CONFIGURE_FILE(test-daemon.conf.in ${CMAKE_BINARY_DIR}/test-daemon.conf @ONLY) FILE(GLOB ut_zone_CONF_GEN ${CMAKE_BINARY_DIR}/*.conf) +IF(NOT WITHOUT_DBUS) CONFIGURE_FILE(templates/console-dbus.conf.in ${CMAKE_BINARY_DIR}/templates/console-dbus.conf @ONLY) +ENDIF(NOT WITHOUT_DBUS) CONFIGURE_FILE(templates/console-ipc.conf.in ${CMAKE_BINARY_DIR}/templates/console-ipc.conf @ONLY) FILE(GLOB ut_zone_templates_CONF_GEN ${CMAKE_BINARY_DIR}/templates/*.conf) +IF(NOT WITHOUT_SYSTEMD) CONFIGURE_FILE(systemd/vasum-socket-test.service.in ${CMAKE_BINARY_DIR}/systemd/vasum-socket-test.service) - +ENDIF(NOT WITHOUT_SYSTEMD) ## Install ##################################################################### INSTALL(FILES ${ut_zone_CONF} @@ -50,9 +53,11 @@ INSTALL(FILES ${ut_zone_templates_CONF} INSTALL(PROGRAMS ${ut_lxc_templates_CONF} DESTINATION ${VSM_TEST_TEMPLATES_INSTALL_DIR}) +IF(NOT WITHOUT_DBUS) INSTALL(FILES dbus/ut-dbus.conf dbus/ut-dbus-system.conf DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/dbus) +ENDIF(NOT WITHOUT_DBUS) INSTALL(FILES provision/test-provision.conf DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/provision) @@ -60,10 +65,14 @@ INSTALL(FILES provision/test-provision.conf INSTALL(FILES utils/file.txt DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/utils) + +IF(NOT WITHOUT_SYSTEMD) INSTALL(FILES systemd/vasum-socket-test.socket ${CMAKE_BINARY_DIR}/systemd/vasum-socket-test.service DESTINATION ${SYSTEMD_UNIT_DIR}) +ENDIF(NOT WITHOUT_SYSTEMD) +IF(NOT WITHOUT_DBUS) INSTALL(FILES dbus-1/system.d/org.tizen.vasum.tests.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) - +ENDIF(NOT WITHOUT_DBUS) diff --git a/tests/unit_tests/configs/templates/buggy-template.conf b/tests/unit_tests/configs/templates/buggy-template.conf index 23b77a6..2ce4024 100644 --- a/tests/unit_tests/configs/templates/buggy-template.conf +++ b/tests/unit_tests/configs/templates/buggy-template.conf @@ -1,6 +1,6 @@ { "zoneTemplate" : "/buggy/path", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], + "initWithArgs" : ["/bin/bash", "-c", "trap exit SIGTERM; read"], "requestedState" : "running", "ipv4Gateway" : "", "ipv4" : "", diff --git a/tests/unit_tests/configs/templates/console-dbus.conf.in b/tests/unit_tests/configs/templates/console-dbus.conf.in index 4daff1d..1ef567f 100644 --- a/tests/unit_tests/configs/templates/console-dbus.conf.in +++ b/tests/unit_tests/configs/templates/console-dbus.conf.in @@ -1,6 +1,6 @@ { "zoneTemplate" : "minimal.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/dbus/ut-dbus-system.conf --fork; read"], + "initWithArgs" : ["/bin/bash", "-c", "trap exit SIGTERM; /bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/dbus/ut-dbus-system.conf --fork; read"], "requestedState" : "running", "ipv4Gateway" : "", "ipv4" : "", diff --git a/tests/unit_tests/configs/templates/console-ipc.conf.in b/tests/unit_tests/configs/templates/console-ipc.conf.in index cefd3e7..dce9410 100644 --- a/tests/unit_tests/configs/templates/console-ipc.conf.in +++ b/tests/unit_tests/configs/templates/console-ipc.conf.in @@ -1,6 +1,6 @@ { "zoneTemplate" : "minimal.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], + "initWithArgs" : ["/bin/bash", "-c", "trap exit SIGTERM; read"], "requestedState" : "running", "ipv4Gateway" : "", "ipv4" : "", diff --git a/tests/unit_tests/configs/templates/default.conf b/tests/unit_tests/configs/templates/default.conf index cd9ae0b..276adc9 100644 --- a/tests/unit_tests/configs/templates/default.conf +++ b/tests/unit_tests/configs/templates/default.conf @@ -1,6 +1,6 @@ { "zoneTemplate" : "minimal.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], + "initWithArgs" : ["/bin/bash", "-c", "trap exit SIGTERM; read"], "requestedState" : "running", "ipv4Gateway" : "", "ipv4" : "", diff --git a/tests/unit_tests/configs/templates/missing.conf b/tests/unit_tests/configs/templates/missing.conf index 1d19915..4d5abd6 100644 --- a/tests/unit_tests/configs/templates/missing.conf +++ b/tests/unit_tests/configs/templates/missing.conf @@ -1,6 +1,6 @@ { "zoneTemplate" : "missing.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], + "initWithArgs" : ["/bin/bash", "-c", "trap exit SIGTERM; read"], "requestedState" : "running", "ipv4Gateway" : "", "ipv4" : "", diff --git a/tests/unit_tests/configs/templates/test-no-shutdown.conf b/tests/unit_tests/configs/templates/test-no-shutdown.conf index f8ab796..026c3e7 100644 --- a/tests/unit_tests/configs/templates/test-no-shutdown.conf +++ b/tests/unit_tests/configs/templates/test-no-shutdown.conf @@ -1,6 +1,6 @@ { "zoneTemplate" : "minimal.sh", - "initWithArgs" : ["/bin/sh"], + "initWithArgs" : ["/bin/bash"], "requestedState" : "running", "ipv4Gateway" : "", "ipv4" : "", diff --git a/tests/unit_tests/dbus/test-client.cpp b/tests/unit_tests/dbus/test-client.cpp index f1a9c25..eb6b6fe 100644 --- a/tests/unit_tests/dbus/test-client.cpp +++ b/tests/unit_tests/dbus/test-client.cpp @@ -22,6 +22,7 @@ * @brief Example dbus api client */ +#ifdef DBUS_CONNECTION #include "config.hpp" #include "dbus/test-client.hpp" @@ -101,3 +102,4 @@ void DbusTestClient::throwException(int arg) } // namespace vasum +#endif //DBUS_CONNECTION diff --git a/tests/unit_tests/dbus/test-server.cpp b/tests/unit_tests/dbus/test-server.cpp index 03a4046..1d9fd43 100644 --- a/tests/unit_tests/dbus/test-server.cpp +++ b/tests/unit_tests/dbus/test-server.cpp @@ -22,6 +22,7 @@ * @brief Example dbus api server */ +#ifdef DBUS_CONNECTION #include "config.hpp" #include "dbus/test-server.hpp" @@ -149,3 +150,4 @@ void DbusTestServer::onMessageCall(const std::string& objectPath, } // namespace vasum +#endif //DBUS_CONNECTION diff --git a/tests/unit_tests/dbus/ut-connection.cpp b/tests/unit_tests/dbus/ut-connection.cpp index 6cefb1c..cfc5efd 100644 --- a/tests/unit_tests/dbus/ut-connection.cpp +++ b/tests/unit_tests/dbus/ut-connection.cpp @@ -22,6 +22,7 @@ * @brief Dbus connection unit tests */ +#ifdef DBUS_CONNECTION #include "config.hpp" #include "ut.hpp" #include "dbus/test-server.hpp" @@ -52,7 +53,7 @@ using namespace dbus; namespace { -const char* DBUS_DAEMON_PROC = "/usr/bin/dbus-daemon"; +const char* DBUS_DAEMON_PROC = "/bin/dbus-daemon"; const char* const DBUS_DAEMON_ARGS[] = { DBUS_DAEMON_PROC, "--config-file=" VSM_TEST_CONFIG_INSTALL_DIR "/dbus/ut-dbus.conf", @@ -642,3 +643,4 @@ BOOST_AUTO_TEST_CASE(DbusApiConnectionLostDelayedCallbackSet) } BOOST_AUTO_TEST_SUITE_END() +#endif //DBUS_CONNECTION diff --git a/tests/unit_tests/ipc/ut-socket.cpp b/tests/unit_tests/ipc/ut-socket.cpp index 1aacd22..d2337d1 100644 --- a/tests/unit_tests/ipc/ut-socket.cpp +++ b/tests/unit_tests/ipc/ut-socket.cpp @@ -22,6 +22,7 @@ * @brief Socket IPC module tests */ +#ifdef HAVE_SYSTEMD #include "config.hpp" #include "ut.hpp" #include "ipc/internals/socket.hpp" @@ -47,3 +48,4 @@ BOOST_AUTO_TEST_CASE(SystemdSocket) } BOOST_AUTO_TEST_SUITE_END() +#endif // HAVE_SYSTEMD diff --git a/tests/unit_tests/lxc/ut-zone.cpp b/tests/unit_tests/lxc/ut-zone.cpp index ba839c9..6702773 100644 --- a/tests/unit_tests/lxc/ut-zone.cpp +++ b/tests/unit_tests/lxc/ut-zone.cpp @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(StartShutdown) LxcZone lxc(ZONE_PATH, ZONE_NAME); BOOST_CHECK(lxc.getState() == LxcZone::State::STOPPED); const char* argv[] = { - "/bin/sh", + "/bin/bash", "-c", "trap exit SIGTERM; read", NULL @@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(StartStop) LxcZone lxc(ZONE_PATH, ZONE_NAME); BOOST_CHECK(lxc.getState() == LxcZone::State::STOPPED); const char* argv[] = { - "/bin/sh", + "/bin/bash", NULL }; BOOST_CHECK(lxc.start(argv)); @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(StartHasStopped) LxcZone lxc(ZONE_PATH, ZONE_NAME); BOOST_CHECK(lxc.getState() == LxcZone::State::STOPPED); const char* argv[] = { - "/bin/sh", + "/bin/bash", "-c", "echo", NULL @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(FreezeUnfreeze) LxcZone lxc(ZONE_PATH, ZONE_NAME); BOOST_CHECK(lxc.create(ZONE_TEMPLATE, TEMPLATE_ARGS)); const char* argv[] = { - "/bin/sh", + "/bin/bash", "-c", "trap exit SIGTERM; read", NULL @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(FreezeStop) LxcZone lxc(ZONE_PATH, ZONE_NAME); BOOST_CHECK(lxc.create(ZONE_TEMPLATE, TEMPLATE_ARGS)); const char* argv[] = { - "/bin/sh", + "/bin/bash", "-c", "trap exit SIGTERM; read", NULL @@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(Repeat) BOOST_CHECK(lxc.create(ZONE_TEMPLATE, TEMPLATE_ARGS)); BOOST_CHECK(!lxc.create(ZONE_TEMPLATE, TEMPLATE_ARGS));// forbidden const char* argv[] = { - "/bin/sh", + "/bin/bash", "-c", "trap exit SIGTERM; read", NULL @@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE(CreateFile) LxcZone lxc(ZONE_PATH, ZONE_NAME); BOOST_REQUIRE(lxc.create(ZONE_TEMPLATE, TEMPLATE_ARGS)); const char* argv[] = { - "/bin/sh", + "/bin/bash", "-c", "trap exit SIGTERM; read", NULL diff --git a/tests/unit_tests/server/ut-zone.cpp b/tests/unit_tests/server/ut-zone.cpp index 1da6190..e492c37 100644 --- a/tests/unit_tests/server/ut-zone.cpp +++ b/tests/unit_tests/server/ut-zone.cpp @@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE(ForegroundBackgroundSchedulerLevel) c->setSchedulerLevel(SchedulerLevel::BACKGROUND); BOOST_CHECK_EQUAL(c->getSchedulerQuota(), refConfig.cpuQuotaBackground); } - +#ifdef DBUS_CONNECTION BOOST_AUTO_TEST_CASE(DbusConnection) { mRunGuard.create("/tmp/ut-run"); // the same path as in zone template @@ -230,6 +230,7 @@ BOOST_AUTO_TEST_CASE(DbusConnection) } // TODO: DbusReconnection +#endif //DBUS_CONNECTION BOOST_AUTO_TEST_CASE(ListNetdev) { diff --git a/wrapper/CMakeLists.txt b/wrapper/CMakeLists.txt index 23fdba6..3346df8 100644 --- a/wrapper/CMakeLists.txt +++ b/wrapper/CMakeLists.txt @@ -53,13 +53,16 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ## Link libraries ############################################################## FIND_PACKAGE(Boost COMPONENTS system filesystem) PKG_CHECK_MODULES(LIB_DEPS REQUIRED gio-2.0) -INCLUDE_DIRECTORIES(SYSTEM ${LIB_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(SYSTEM ${LIB_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${JSON_C_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) INCLUDE_DIRECTORIES(${LIBS_FOLDER}) INCLUDE_DIRECTORIES(${SERVER_FOLDER}) INCLUDE_DIRECTORIES(${CLIENT_FOLDER}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIB_DEPS_LIBRARIES} ${Boost_LIBRARIES} - Config SimpleDbus Ipc) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIB_DEPS_LIBRARIES} ${Boost_LIBRARIES} Config Ipc) +IF(NOT WITHOUT_DBUS) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} SimpleDbus) +ENDIF(NOT WITHOUT_DBUS) ## Generate the pc file ######################################################## CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY) diff --git a/zone-daemon/main.cpp b/zone-daemon/main.cpp index f0c00c6..0cfe21f 100644 --- a/zone-daemon/main.cpp +++ b/zone-daemon/main.cpp @@ -36,6 +36,7 @@ #include "logger/logger.hpp" #include "logger/backend-stderr.hpp" #include "logger/backend-journal.hpp" +#include "logger/backend-syslog.hpp" #include "utils/typeinfo.hpp" #include @@ -100,11 +101,12 @@ int main(int argc, char* argv[]) Logger::setLogLevel(vm["log-level"].as()); #ifdef LOG_TO_CONSOLE Logger::setLogBackend(new StderrBackend()); -#else +#elif HAVE_SYSTEMD Logger::setLogBackend(new SystemdJournalBackend()); +#else + Logger::setLogBackend(new SyslogBackend()); #endif - } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; -- 2.7.4 From 2d6dff014e5ee531da341584f98d1ea8121c55a2 Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Mon, 27 Jul 2015 15:23:38 +0200 Subject: [PATCH 12/16] Added lxcpp's license [Feature] lxcpp is on LGPL 2.1 license [Cause] N/A [Solution] N/A [Verification] N/A Change-Id: Ia1916f4ba8ea815467ea958020db401f46cfa5cb --- libs/lxcpp/CMakeLists.txt | 22 +- libs/lxcpp/LICENSE | 458 ++++++++++++++++++++++++++++++++++++++++++ libs/lxcpp/container-impl.cpp | 23 +-- libs/lxcpp/container-impl.hpp | 23 +-- libs/lxcpp/container.hpp | 23 +-- libs/lxcpp/exception.hpp | 23 +-- libs/lxcpp/lxcpp.cpp | 23 +-- libs/lxcpp/lxcpp.hpp | 23 +-- 8 files changed, 535 insertions(+), 83 deletions(-) create mode 100644 libs/lxcpp/LICENSE diff --git a/libs/lxcpp/CMakeLists.txt b/libs/lxcpp/CMakeLists.txt index fa63074..74522a3 100644 --- a/libs/lxcpp/CMakeLists.txt +++ b/libs/lxcpp/CMakeLists.txt @@ -1,17 +1,17 @@ -# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (C) 2015 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 +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. # -# 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. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # @file CMakeLists.txt # @author Mateusz Malicki (m.malicki2@samsung.com) diff --git a/libs/lxcpp/LICENSE b/libs/lxcpp/LICENSE new file mode 100644 index 0000000..fe17b67 --- /dev/null +++ b/libs/lxcpp/LICENSE @@ -0,0 +1,458 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/libs/lxcpp/container-impl.cpp b/libs/lxcpp/container-impl.cpp index c0fd907..a7f404e 100644 --- a/libs/lxcpp/container-impl.cpp +++ b/libs/lxcpp/container-impl.cpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Mateusz Malicki + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. * - * 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 + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * 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 + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** diff --git a/libs/lxcpp/container-impl.hpp b/libs/lxcpp/container-impl.hpp index e53684e..9b9b1ea 100644 --- a/libs/lxcpp/container-impl.hpp +++ b/libs/lxcpp/container-impl.hpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Mateusz Malicki + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. * - * 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 + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * 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 + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** diff --git a/libs/lxcpp/container.hpp b/libs/lxcpp/container.hpp index b3ce50a..36e877e 100644 --- a/libs/lxcpp/container.hpp +++ b/libs/lxcpp/container.hpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Mateusz Malicki + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. * - * 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 + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * 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 + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** diff --git a/libs/lxcpp/exception.hpp b/libs/lxcpp/exception.hpp index e841c0b..1e3ce4c 100644 --- a/libs/lxcpp/exception.hpp +++ b/libs/lxcpp/exception.hpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Mateusz Malicki + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. * - * 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 + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * 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 + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** diff --git a/libs/lxcpp/lxcpp.cpp b/libs/lxcpp/lxcpp.cpp index a81f8f9..3cb906c 100644 --- a/libs/lxcpp/lxcpp.cpp +++ b/libs/lxcpp/lxcpp.cpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Mateusz Malicki + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. * - * 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 + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * 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 + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** diff --git a/libs/lxcpp/lxcpp.hpp b/libs/lxcpp/lxcpp.hpp index a6b8437..8037d3c 100644 --- a/libs/lxcpp/lxcpp.hpp +++ b/libs/lxcpp/lxcpp.hpp @@ -1,19 +1,18 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved * - * Contact: Mateusz Malicki + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. * - * 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 + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * 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 + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** -- 2.7.4 From d58f1b9ef9e764daae6079beb920f3570081c06e Mon Sep 17 00:00:00 2001 From: Lukasz Pawelczyk Date: Mon, 27 Jul 2015 11:20:37 +0200 Subject: [PATCH 13/16] Hide VsmZone and VsmNetdevType structs from API [Feature] N/A [Cause] Make it easier to change them in the future without breaking the ABI. Also remove duplicate related API function from the code. [Solution] N/A [Verification] N/A Change-Id: Ib0ec7374ee0f94cd88e2998e9d10f18ae094ee98 --- cli/command-line-interface.cpp | 68 +++++++++++++---------------- client/vasum-client-impl.cpp | 23 +++------- client/vasum-client-impl.hpp | 27 +++++++++--- client/vasum-client.cpp | 59 +++++++++++++++++++------ client/vasum-client.h | 81 +++++++++++++++++++++-------------- tests/unit_tests/client/ut-client.cpp | 25 ++--------- wrapper/wrapper.cpp | 20 +++++---- 7 files changed, 167 insertions(+), 136 deletions(-) diff --git a/cli/command-line-interface.cpp b/cli/command-line-interface.cpp index 29dd4a3..1338afe 100644 --- a/cli/command-line-interface.cpp +++ b/cli/command-line-interface.cpp @@ -51,17 +51,9 @@ VsmClient CommandLineInterface::client = NULL; namespace { -template -string stringAsInStream(const T& value) +std::string zoneStateToString(const VsmZoneState& state) { - std::ostringstream stream; - stream << value; - return stream.str(); -} - -ostream& operator<<(ostream& out, const VsmZoneState& state) -{ - const char* name; + std::string name; switch (state) { case STOPPED: name = "STOPPED"; break; case STARTING: name = "STARTING"; break; @@ -77,33 +69,33 @@ ostream& operator<<(ostream& out, const VsmZoneState& state) default: name = "MAX_STATE (ERROR)"; } - out << name; - return out; + return name; } -ostream& operator<<(ostream& out, const VsmZone& zone) +std::string zoneToString(const VsmZone& zone) { - out << "Name: " << zone->id - << "\nTerminal: " << zone->terminal - << "\nState: " << zone->state - << "\nRoot: " << zone->rootfs_path; + std::string out = std::string("Name: ") + vsm_zone_get_id(zone) + + std::string("\nTerminal: ") + std::to_string(vsm_zone_get_terminal(zone)) + + std::string("\nState: ") + zoneStateToString(vsm_zone_get_state(zone)) + + std::string("\nRoot: ") + vsm_zone_get_rootfs(zone); return out; } -ostream& operator<<(ostream& out, const VsmNetdevType& netdevType) +std::string netdevTypeToString(const VsmNetdevType& netdevType) { + std::string type; switch (netdevType) { - case VSMNETDEV_VETH: out << "VETH"; break; - case VSMNETDEV_PHYS: out << "PHYS"; break; - case VSMNETDEV_MACVLAN: out << "MACVLAN"; break; + case VSMNETDEV_VETH: type = "VETH"; break; + case VSMNETDEV_PHYS: type = "PHYS"; break; + case VSMNETDEV_MACVLAN: type = "MACVLAN"; break; } - return out; + return type; } -ostream& operator<<(ostream& out, const VsmNetdev& netdev) +std::string netdevToString(const VsmNetdev& netdev) { - out << "Name: " << netdev->name - << "\nType: " << netdev->type; + std::string out = std::string("Name: ") + vsm_netdev_get_name(netdev) + + std::string("\nType: ") + netdevTypeToString(vsm_netdev_get_type(netdev)); return out; } @@ -316,12 +308,12 @@ void console_zone(const Args& argv) VsmZone zone; CommandLineInterface::executeCallback(bind(vsm_lookup_zone_by_id, _1, argv[1].c_str(), &zone)); - if (stringAsInStream(zone->state) != "RUNNING") { + if (zoneStateToString(vsm_zone_get_state(zone)) != "RUNNING") { vsm_zone_free(zone); throw runtime_error("Zone is not running"); } - std::string zonesPath = zone->rootfs_path; + std::string zonesPath = vsm_zone_get_rootfs(zone); std::string zoneRootFs = argv[1] + "/rootfs"; zonesPath.erase(zonesPath.length()- zoneRootFs.length(), zoneRootFs.length()); @@ -374,12 +366,12 @@ void get_zones_status(const Args& /* argv */) for (VsmString* id = ids; *id; ++id) { VsmZone zone; CommandLineInterface::executeCallback(bind(vsm_lookup_zone_by_id, _1, *id, &zone)); - assert(string(zone->id) == string(*id)); - table.push_back({string(zone->id) == string(activeId) ? "*" : "", - zone->id, - stringAsInStream(zone->state), - to_string(zone->terminal), - zone->rootfs_path}); + assert(string(vsm_zone_get_id(zone)) == string(*id)); + table.push_back({string(vsm_zone_get_id(zone)) == string(activeId) ? "*" : "", + vsm_zone_get_id(zone), + zoneStateToString(vsm_zone_get_state(zone)), + to_string(vsm_zone_get_terminal(zone)), + vsm_zone_get_rootfs(zone)}); vsm_zone_free(zone); } vsm_string_free(activeId); @@ -421,7 +413,7 @@ void lookup_zone_by_id(const Args& argv) VsmZone zone; CommandLineInterface::executeCallback(bind(vsm_lookup_zone_by_id, _1, argv[1].c_str(), &zone)); - cout << zone << endl; + cout << zoneToString(zone) << endl; vsm_zone_free(zone); } @@ -497,14 +489,14 @@ void lookup_netdev_by_name(const Args& argv) if (argv.size() <= 2) { throw runtime_error("Not enough parameters"); } - VsmNetdev vsmNetdev = NULL; + VsmNetdev netdev = NULL; CommandLineInterface::executeCallback(bind(vsm_lookup_netdev_by_name, _1, argv[1].c_str(), argv[2].c_str(), - &vsmNetdev)); - cout << vsmNetdev << endl; - vsm_netdev_free(vsmNetdev); + &netdev)); + cout << netdevToString(netdev) << endl; + vsm_netdev_free(netdev); } diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index 78c2d8f..15cccf6 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -93,9 +93,9 @@ void convert(const api::VectorOfStrings& in, VsmArrayString& out) } } -void convert(const api::ZoneInfoOut& info, VsmZone& zone) +void convert(const api::ZoneInfoOut& info, Zone& zone) { - VsmZone vsmZone = reinterpret_cast(malloc(sizeof(*vsmZone))); + Zone vsmZone = static_cast(malloc(sizeof(*vsmZone))); vsmZone->id = ::strdup(info.id.c_str()); vsmZone->terminal = info.vt; vsmZone->state = getZoneState(info.state.c_str()); @@ -349,19 +349,6 @@ VsmStatus Client::vsm_get_active_zone_id(VsmString* id) noexcept }); } -VsmStatus Client::vsm_get_zone_rootpath(const char* id, VsmString* rootpath) noexcept -{ - return coverException([&] { - IS_SET(id); - IS_SET(rootpath); - - api::ZoneInfoOut info = *mClient->callSync( - api::ipc::METHOD_GET_ZONE_INFO, - std::make_shared(api::ZoneId{ id })); - *rootpath = ::strdup(info.rootPath.c_str()); - }); -} - VsmStatus Client::vsm_lookup_zone_by_pid(int pid, VsmString* id) noexcept { return coverException([&] { @@ -383,7 +370,7 @@ VsmStatus Client::vsm_lookup_zone_by_pid(int pid, VsmString* id) noexcept }); } -VsmStatus Client::vsm_lookup_zone_by_id(const char* id, VsmZone* zone) noexcept +VsmStatus Client::vsm_lookup_zone_by_id(const char* id, Zone* zone) noexcept { return coverException([&] { IS_SET(id); @@ -742,7 +729,7 @@ VsmStatus Client::vsm_create_netdev_phys(const char* id, const char* devId) noex VsmStatus Client::vsm_lookup_netdev_by_name(const char* id, const char* netdevId, - VsmNetdev* netdev) noexcept + Netdev* netdev) noexcept { using namespace boost::algorithm; @@ -772,7 +759,7 @@ VsmStatus Client::vsm_lookup_netdev_by_name(const char* id, throw InvalidResponseException("Unknown netdev type: " + it->second); } - *netdev = reinterpret_cast(malloc(sizeof(**netdev))); + *netdev = static_cast(malloc(sizeof(**netdev))); (*netdev)->name = ::strdup(id); (*netdev)->type = type; }); diff --git a/client/vasum-client-impl.hpp b/client/vasum-client-impl.hpp index 1195b66..4297c95 100644 --- a/client/vasum-client-impl.hpp +++ b/client/vasum-client-impl.hpp @@ -46,6 +46,24 @@ typedef std::function VsmZoneDbusStateFunction; /** + * Zone information structure + */ +typedef struct ZoneStructure { + char *id; + int terminal; + VsmZoneState state; + char *rootfs_path; +} *Zone; + +/** + * Network device information structure + */ +typedef struct NetdevStructure { + char *name; + VsmNetdevType type; +} *Netdev; + +/** * vasum's client definition. * * Client uses dbus API. @@ -131,11 +149,6 @@ public: VsmStatus vsm_get_active_zone_id(VsmString* id) noexcept; /** - * @see ::vsm_get_zone_rootpath - */ - VsmStatus vsm_get_zone_rootpath(const char* id, VsmString* rootpath) noexcept; - - /** * @see ::vsm_lookup_zone_by_pid */ VsmStatus vsm_lookup_zone_by_pid(int pid, VsmString* id) noexcept; @@ -143,7 +156,7 @@ public: /** * @see ::vsm_lookup_zone_by_id */ - VsmStatus vsm_lookup_zone_by_id(const char* id, VsmZone* zone) noexcept; + VsmStatus vsm_lookup_zone_by_id(const char* id, Zone* zone) noexcept; /** * @see ::vsm_lookup_zone_by_terminal_id @@ -295,7 +308,7 @@ public: */ VsmStatus vsm_lookup_netdev_by_name(const char* zone, const char* netdevId, - VsmNetdev* netdev) noexcept; + Netdev* netdev) noexcept; /** * @see ::vsm_destroy_netdev diff --git a/client/vasum-client.cpp b/client/vasum-client.cpp index 68496d5..ee3e6d4 100644 --- a/client/vasum-client.cpp +++ b/client/vasum-client.cpp @@ -112,17 +112,55 @@ API void vsm_string_free(VsmString string) free(string); } +API VsmString vsm_zone_get_id(VsmZone zone) +{ + Zone z = static_cast(zone); + return z->id; +} + +API int vsm_zone_get_terminal(VsmZone zone) +{ + Zone z = static_cast(zone); + return z->terminal; +} + +API VsmZoneState vsm_zone_get_state(VsmZone zone) +{ + Zone z = static_cast(zone); + return z->state; +} + +API VsmString vsm_zone_get_rootfs(VsmZone zone) +{ + Zone z = static_cast(zone); + return z->rootfs_path; +} + API void vsm_zone_free(VsmZone zone) { - free(zone->rootfs_path); - free(zone->id); - free(zone); + Zone z = static_cast(zone); + free(z->rootfs_path); + free(z->id); + free(z); +} + +API VsmString vsm_netdev_get_name(VsmNetdev netdev) +{ + Netdev n = static_cast(netdev); + return n->name; +} + +API VsmNetdevType vsm_netdev_get_type(VsmNetdev netdev) +{ + Netdev n = static_cast(netdev); + return n->type; } API void vsm_netdev_free(VsmNetdev netdev) { - free(netdev->name); - free(netdev); + Netdev n = static_cast(netdev); + free(n->name); + free(n); } API void vsm_client_free(VsmClient client) @@ -157,11 +195,6 @@ API VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id) return getClient(client).vsm_get_active_zone_id(id); } -API VsmStatus vsm_get_zone_rootpath(VsmClient client, const char* id, VsmString* rootpath) -{ - return getClient(client).vsm_get_zone_rootpath(id, rootpath); -} - API VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id) { return getClient(client).vsm_lookup_zone_by_pid(pid, id); @@ -169,7 +202,8 @@ API VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id) API VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone) { - return getClient(client).vsm_lookup_zone_by_id(id, zone); + Zone* z = reinterpret_cast(zone); + return getClient(client).vsm_lookup_zone_by_id(id, z); } API VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id) @@ -338,7 +372,8 @@ API VsmStatus vsm_lookup_netdev_by_name(VsmClient client, const char* netdevId, VsmNetdev* netdev) { - return getClient(client).vsm_lookup_netdev_by_name(zone, netdevId, netdev); + Netdev* n = reinterpret_cast(netdev); + return getClient(client).vsm_lookup_netdev_by_name(zone, netdevId, n); } API VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId) diff --git a/client/vasum-client.h b/client/vasum-client.h index fbdd3b1..b696dcf 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -221,19 +221,9 @@ typedef enum { } VsmZoneState; /** - * Zone information structure - */ -typedef struct { - char* id; - int terminal; - VsmZoneState state; - char *rootfs_path; -} VsmZoneStructure; - -/** * Zone information */ -typedef VsmZoneStructure* VsmZone; +typedef void* VsmZone; /** * Netowrk device type @@ -245,17 +235,9 @@ typedef enum { } VsmNetdevType; /** - * Network device information structure - */ -typedef struct { - char* name; - VsmNetdevType type; -} VsmNetdevStructure; - -/** * Network device information */ -typedef VsmNetdevStructure* VsmNetdev; +typedef void* VsmNetdev; /** * File type @@ -391,6 +373,38 @@ void vsm_array_string_free(VsmArrayString astring); void vsm_string_free(VsmString string); /** + * Get zone id (offline) + * + * @param zone VsmZone + * @return zone id + */ +VsmString vsm_zone_get_id(VsmZone zone); + +/** + * Get zone terminal (offline) + * + * @param zone VsmZone + * @return zone terminal + */ +int vsm_zone_get_terminal(VsmZone zone); + +/** + * Get zone state (offline) + * + * @param zone VsmZone + * @return zone state + */ +VsmZoneState vsm_zone_get_state(VsmZone zone); + +/** + * Get zone rootfs path (offline) + * + * @param zone VsmZone + * @return zone rootfs path + */ +VsmString vsm_zone_get_rootfs(VsmZone zone); + +/** * Release VsmZone * * @param zone VsmZone @@ -398,6 +412,22 @@ void vsm_string_free(VsmString string); void vsm_zone_free(VsmZone zone); /** + * Get netdev name (offline) + * + * @param netdev VsmNetdev + * @return netdev name + */ +VsmString vsm_netdev_get_name(VsmNetdev netdev); + +/** + * Get netdev type (offline) + * + * @param netdev VsmNetdev + * @return netdev type + */ +VsmNetdevType vsm_netdev_get_type(VsmNetdev netdev); + +/** * Release VsmNetdev * * @param netdev VsmNetdev @@ -464,17 +494,6 @@ VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array); VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id); /** - * Get zone rootfs path. - * - * @param[in] client vasum-server's client - * @param[in] id zone name - * @param[out] rootpath zone rootfs path - * @return status of this function call - * @remark Use @p vsm_string_free() to free memory occupied by @p rootpath. - */ -VsmStatus vsm_get_zone_rootpath(VsmClient client, const char* id, VsmString* rootpath); - -/** * Get zone name of process with given pid. * * @param[in] client vasum-server's client diff --git a/tests/unit_tests/client/ut-client.cpp b/tests/unit_tests/client/ut-client.cpp index 1681c36..8b1530f 100644 --- a/tests/unit_tests/client/ut-client.cpp +++ b/tests/unit_tests/client/ut-client.cpp @@ -252,23 +252,6 @@ BOOST_AUTO_TEST_CASE(GetActiveZoneId) vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(GetZoneRootPath) -{ - const std::string zoneId = "zone1"; - - VsmClient client = vsm_client_create(); - VsmStatus status = vsm_connect(client); - BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - VsmString rootpath; - status = vsm_get_zone_rootpath(client, zoneId.c_str(), &rootpath); - BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - - BOOST_CHECK_EQUAL(rootpath, "/tmp/ut-zones/" + zoneId + "/rootfs"); - - vsm_string_free(rootpath); - vsm_client_free(client); -} - BOOST_AUTO_TEST_CASE(LookupZoneById) { const std::string activeZoneId = "zone1"; @@ -280,10 +263,10 @@ BOOST_AUTO_TEST_CASE(LookupZoneById) status = vsm_lookup_zone_by_id(client, activeZoneId.c_str(), &info); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(info->id, activeZoneId); - BOOST_CHECK_EQUAL(info->state, RUNNING); - BOOST_CHECK_EQUAL(info->terminal, -1); - BOOST_CHECK_EQUAL(info->rootfs_path, "/tmp/ut-zones/" + activeZoneId + "/rootfs"); + BOOST_CHECK_EQUAL(vsm_zone_get_id(info), activeZoneId); + BOOST_CHECK_EQUAL(vsm_zone_get_state(info), RUNNING); + BOOST_CHECK_EQUAL(vsm_zone_get_terminal(info), -1); + BOOST_CHECK_EQUAL(vsm_zone_get_rootfs(info), "/tmp/ut-zones/" + activeZoneId + "/rootfs"); vsm_zone_free(info); vsm_client_free(client); diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index a975087..c3a071f 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -105,7 +105,7 @@ void init_wrapper() LOGS(""); } -static struct vsm_zone* wrap_vsm_zone(WrappedContext *w, VsmZone zone, bool create = false) +static struct vsm_zone* wrap_vsm_zone(WrappedContext *w, Zone zone, bool create = false) { if (zone == NULL) { return NULL; @@ -303,7 +303,9 @@ API int vsm_destroy_zone(struct vsm_context *ctx, const char *zone_name, int for if (!w->client) return VSM_ERROR_GENERIC; VsmStatus st = w->client->vsm_destroy_zone(zone_name); if (st == VSMCLIENT_SUCCESS) { - auto zonebyname = [zone_name](const WrappedZone& v) {return v.zone->id == zone_name;}; + auto zonebyname = [zone_name](const WrappedZone& v) { + return static_cast(v.zone)->id == zone_name; + }; auto zonelist = std::remove_if(w->zones.begin(), w->zones.end(), zonebyname); w->zones.erase(zonelist); } @@ -390,7 +392,7 @@ API int vsm_iterate_zone(struct vsm_context *ctx, void (*callback)(struct vsm_zo if (!w->client) return -VSM_ERROR_GENERIC; callback(ctx->root_zone, user_data); for (auto& z : w->zones) { - LOGI("iterate callback zone: " << z.zone->id); + LOGI("iterate callback zone: " << static_cast(z.zone)->id); callback(&z.vz, user_data); } return 0; @@ -401,7 +403,7 @@ API struct vsm_zone *vsm_lookup_zone_by_name(struct vsm_context *ctx, const char LOGS("name=" << path); callcheck(); WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx); - VsmZone zone; + Zone zone; if (!w->client) return NULL; //CHECK if path is same as zone_name if (w->client->vsm_lookup_zone_by_id(path, &zone) != VSMCLIENT_SUCCESS) @@ -415,7 +417,7 @@ API struct vsm_zone *vsm_lookup_zone_by_pid(struct vsm_context *ctx, pid_t pid) LOGS("pid=" << pid); callcheck(); WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx); - VsmZone zone; + Zone zone; VsmString id; VsmStatus st; if (!w->client) return NULL; @@ -440,7 +442,7 @@ API int vsm_add_state_changed_callback(struct vsm_context *ctx, vsm_zone_state_c auto dbus_cb = [=](const char* id, const char* dbusAddress, void* data) -> void { - VsmZone zone; + Zone zone; //TODO what are valid state, event vsm_zone_state_t t = VSM_ZONE_STATE_RUNNING; UNUSED(dbusAddress); @@ -467,7 +469,7 @@ API int vsm_grant_device(struct vsm_zone *dom, const char *name, uint32_t flags) callcheck(); WrappedZone *w = container_of(dom, WrappedZone, vz); const char *id = dom->name; - VsmZone zone; + Zone zone; w->client->vsm_lookup_zone_by_id(id, &zone); VsmStatus st = w->client->vsm_grant_device(id, name, flags); return wrap_error(st, w->client); @@ -542,7 +544,7 @@ API struct vsm_netdev *vsm_lookup_netdev_by_name(struct vsm_zone *zone, const ch LOGS(""); callcheck(); WrappedZone *w = container_of(zone, WrappedZone, vz); - VsmNetdev nd; + Netdev nd; VsmStatus st = w->client->vsm_lookup_netdev_by_name(zone->name, name, &nd); if (st == VSMCLIENT_SUCCESS) { auto devbyname = [name](const vsm_netdev& v) {return ::strcmp(v.name, name) == 0;}; @@ -695,7 +697,7 @@ API struct vsm_zone *vsm_lookup_zone_by_terminal_id(struct vsm_context *ctx, int LOGS("terminal=" << terminal); callcheck(); WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx); - VsmZone zone; + Zone zone; VsmString id; if (!w->client) return NULL; if (w->client->vsm_lookup_zone_by_terminal_id(terminal, &id) != VSMCLIENT_SUCCESS) -- 2.7.4 From 24894159f283d2d23012251da4851ed813229cb3 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 27 Jul 2015 16:45:35 +0200 Subject: [PATCH 14/16] Remove debug logs in release build. [Bug] Remove debug logs in release build. [Cause] N/A [Solution] N/A [Verification] Build release/debug, run server. Change-Id: Id34991a45e0fbee8edddfea10b64f69809141af3 --- common/utils/execute.cpp | 2 +- common/utils/fs.cpp | 7 +++++-- libs/dbus/connection.cpp | 4 ++-- libs/ipc/epoll/event-poll.cpp | 2 +- libs/ipc/internals/processor.cpp | 4 ++-- libs/logger/logger-scope.hpp | 4 ++++ libs/logger/logger.hpp | 9 ++++++++- server/main.cpp | 7 +------ tests/unit_tests/log/ut-logger.cpp | 2 ++ wrapper/wrapper-compatibility.cpp | 4 +++- zone-daemon/main.cpp | 7 +------ 11 files changed, 30 insertions(+), 22 deletions(-) diff --git a/common/utils/execute.cpp b/common/utils/execute.cpp index d030177..4b6d59d 100644 --- a/common/utils/execute.cpp +++ b/common/utils/execute.cpp @@ -35,7 +35,7 @@ namespace utils { namespace { -std::ostream& operator<< (std::ostream& out, const char* const* argv) +__attribute__((unused)) std::ostream& operator<< (std::ostream& out, const char* const* argv) { if (*argv) { argv++; //skip diff --git a/common/utils/fs.cpp b/common/utils/fs.cpp index a093c9e..a7a979a 100644 --- a/common/utils/fs.cpp +++ b/common/utils/fs.cpp @@ -201,10 +201,13 @@ bool isMountPoint(const std::string& path, bool& result) { std::string parentPath = dirName(path); bool newResult; - bool ret = hasSameMountPoint(path, parentPath, newResult); + if (!hasSameMountPoint(path, parentPath, newResult)) { + LOGE("Failed to check the files' mount points"); + return false; + } result = !newResult; - return ret; + return true; } bool hasSameMountPoint(const std::string& path1, const std::string& path2, bool& result) diff --git a/libs/dbus/connection.cpp b/libs/dbus/connection.cpp index ee4cea9..5851631 100644 --- a/libs/dbus/connection.cpp +++ b/libs/dbus/connection.cpp @@ -181,7 +181,7 @@ void DbusConnection::setName(const std::string& name, &deleteCallbackWrapper); } -void DbusConnection::onNameAcquired(GDBusConnection*, const gchar* name, gpointer userData) +void DbusConnection::onNameAcquired(GDBusConnection*, __attribute__((unused)) const gchar* name, gpointer userData) { LOGD("Name acquired " << name); const NameCallbacks& callbacks = getCallbackFromPointer(userData); @@ -190,7 +190,7 @@ void DbusConnection::onNameAcquired(GDBusConnection*, const gchar* name, gpointe } } -void DbusConnection::onNameLost(GDBusConnection*, const gchar* name, gpointer userData) +void DbusConnection::onNameLost(GDBusConnection*, __attribute__((unused)) const gchar* name, gpointer userData) { LOGD("Name lost " << name); const NameCallbacks& callbacks = getCallbackFromPointer(userData); diff --git a/libs/ipc/epoll/event-poll.cpp b/libs/ipc/epoll/event-poll.cpp index b6c4902..650e121 100644 --- a/libs/ipc/epoll/event-poll.cpp +++ b/libs/ipc/epoll/event-poll.cpp @@ -51,7 +51,7 @@ EventPoll::~EventPoll() { if (!mCallbacks.empty()) { LOGW("Not removed callbacks: " << mCallbacks.size()); - for (const auto& item : mCallbacks) { + for (__attribute__((unused)) const auto& item : mCallbacks) { LOGT("Not removed fd: " << item.first); } assert(0 && "Not removed callbacks left"); diff --git a/libs/ipc/internals/processor.cpp b/libs/ipc/internals/processor.cpp index 8f81b24..a8c671e 100644 --- a/libs/ipc/internals/processor.cpp +++ b/libs/ipc/internals/processor.cpp @@ -389,8 +389,8 @@ bool Processor::onReturnValue(Peers::iterator& peerIt, } bool Processor::onRemoteSignal(Peers::iterator& peerIt, - const MethodID methodID, - const MessageID messageID, + __attribute__((unused)) const MethodID methodID, + __attribute__((unused)) const MessageID messageID, std::shared_ptr signalCallbacks) { LOGS(mLogPrefix + "Processor onRemoteSignal; methodID: " << methodID << " messageID: " << messageID); diff --git a/libs/logger/logger-scope.hpp b/libs/logger/logger-scope.hpp index 41a99bf..1462272 100644 --- a/libs/logger/logger-scope.hpp +++ b/libs/logger/logger-scope.hpp @@ -74,8 +74,12 @@ private: * @brief Automatically create LoggerScope object which logs at the construction and destruction * @ingroup libLogger */ +#if !defined(NDEBUG) #define LOGS(MSG) logger::LoggerScope logScopeObj(__FILE__, __LINE__, __func__, \ logger::SStreamWrapper() << MSG, \ PROJECT_SOURCE_DIR) +#else +#define LOGS(MSG) do {} while (0) +#endif #endif // COMMON_LOGGER_LOGGER_SCOPE_HPP diff --git a/libs/logger/logger.hpp b/libs/logger/logger.hpp index e27d3dd..bedddb0 100644 --- a/libs/logger/logger.hpp +++ b/libs/logger/logger.hpp @@ -117,6 +117,7 @@ public: /// Logging information #define LOGI(MESSAGE) LOG(INFO, MESSAGE) +#if !defined(NDEBUG) /// Logging debug information #define LOGD(MESSAGE) LOG(DEBUG, MESSAGE) @@ -125,6 +126,12 @@ public: /// Logging tracing information #define LOGT(MESSAGE) LOG(TRACE, MESSAGE) +#else +#define LOGD(MESSAGE) do {} while (0) +#define LOGH(MESSAGE) do {} while (0) +#define LOGT(MESSAGE) do {} while (0) +#endif #endif // COMMON_LOGGER_LOGGER_HPP -/*@}*/ \ No newline at end of file + +/*@}*/ diff --git a/server/main.cpp b/server/main.cpp index 707eb50..e9440cb 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -23,11 +23,6 @@ * @brief Main file for the Vasum Daemon */ -// Always log to console in DEBUG mode -#if !defined(LOG_TO_CONSOLE) && !defined(NDEBUG) -#define LOG_TO_CONSOLE -#endif - #include "config.hpp" #include "exception.hpp" @@ -109,7 +104,7 @@ int main(int argc, char* argv[]) } Logger::setLogLevel(vm["log-level"].as()); -#ifdef LOG_TO_CONSOLE +#if !defined(NDEBUG) Logger::setLogBackend(new StderrBackend()); #elif HAVE_SYSTEMD Logger::setLogBackend(new SystemdJournalBackend()); diff --git a/tests/unit_tests/log/ut-logger.cpp b/tests/unit_tests/log/ut-logger.cpp index 36f52e3..9201f8f 100644 --- a/tests/unit_tests/log/ut-logger.cpp +++ b/tests/unit_tests/log/ut-logger.cpp @@ -176,6 +176,7 @@ BOOST_AUTO_TEST_CASE(LogsLevelInfo) BOOST_CHECK(tf.logContains("[TRACE]") == false); } +#if !defined(NDEBUG) BOOST_AUTO_TEST_CASE(LogsLevelDebug) { TestLog tf(LogLevel::DEBUG); @@ -199,6 +200,7 @@ BOOST_AUTO_TEST_CASE(LogsLevelTrace) BOOST_CHECK(tf.logContains("[DEBUG]") == true); BOOST_CHECK(tf.logContains("[TRACE]") == true); } +#endif BOOST_AUTO_TEST_CASE(LoggerScope) { diff --git a/wrapper/wrapper-compatibility.cpp b/wrapper/wrapper-compatibility.cpp index 6c3dfa9..634c187 100644 --- a/wrapper/wrapper-compatibility.cpp +++ b/wrapper/wrapper-compatibility.cpp @@ -278,7 +278,9 @@ API int sock_send_fd(int fd, int sendfd, void *data, size_t size) { return sendmsg(fd, &msg, MSG_NOSIGNAL); } // vasum_log -API void vasum_log(int type, const char *tag, const char *fmt, ...) { +API void vasum_log(__attribute__((unused)) int type, + __attribute__((unused)) const char *tag, + const char *fmt, ...) { va_list arg_ptr; char buf[255]; LOGS("type=" << type << " tag=" << tag); diff --git a/zone-daemon/main.cpp b/zone-daemon/main.cpp index 0cfe21f..58fad9b 100644 --- a/zone-daemon/main.cpp +++ b/zone-daemon/main.cpp @@ -23,11 +23,6 @@ * @brief Main file for the Vasum Daemon */ -// Always log to console in DEBUG mode -#if !defined(LOG_TO_CONSOLE) && !defined(NDEBUG) -#define LOG_TO_CONSOLE -#endif - #include "config.hpp" #include "exception.hpp" @@ -99,7 +94,7 @@ int main(int argc, char* argv[]) } Logger::setLogLevel(vm["log-level"].as()); -#ifdef LOG_TO_CONSOLE +#if !defined(NDEBUG) Logger::setLogBackend(new StderrBackend()); #elif HAVE_SYSTEMD Logger::setLogBackend(new SystemdJournalBackend()); -- 2.7.4 From 5649bd03bdb39c513ec38545dffe5b00a6448160 Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Tue, 28 Jul 2015 13:12:10 +0200 Subject: [PATCH 15/16] lxcpp: Added logger, tests and changed exceptions [Feature] Using libLogger in lxcpp in an example clone function. Set up unit-tests Changed exception names [Cause] N/A [Solution] N/A [Verification] N/A Change-Id: I039bf3e17d791ccf1a18f17a9b2a180ee2081722 --- libs/lxcpp/CMakeLists.txt | 1 + libs/lxcpp/container-impl.cpp | 30 +++++++++---------- libs/lxcpp/container-impl.hpp | 2 +- libs/lxcpp/container.hpp | 2 +- libs/lxcpp/exception.hpp | 21 ++++++++----- libs/lxcpp/lxcpp.cpp | 2 +- libs/lxcpp/lxcpp.hpp | 4 +-- libs/lxcpp/process.cpp | 52 ++++++++++++++++++++++++++++++++ libs/lxcpp/process.hpp | 35 ++++++++++++++++++++++ tests/unit_tests/CMakeLists.txt | 2 +- tests/unit_tests/lxcpp/ut-container.cpp | 53 +++++++++++++++++++++++++++++++++ 11 files changed, 175 insertions(+), 29 deletions(-) create mode 100644 libs/lxcpp/process.cpp create mode 100644 libs/lxcpp/process.hpp create mode 100644 tests/unit_tests/lxcpp/ut-container.cpp diff --git a/libs/lxcpp/CMakeLists.txt b/libs/lxcpp/CMakeLists.txt index 74522a3..0d49df9 100644 --- a/libs/lxcpp/CMakeLists.txt +++ b/libs/lxcpp/CMakeLists.txt @@ -37,6 +37,7 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ## Link libraries ############################################################## INCLUDE_DIRECTORIES(${LIBS_FOLDER}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} Logger) ## Generate the pc file ######################################################## CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} @ONLY) diff --git a/libs/lxcpp/container-impl.cpp b/libs/lxcpp/container-impl.cpp index a7f404e..e4f290d 100644 --- a/libs/lxcpp/container-impl.cpp +++ b/libs/lxcpp/container-impl.cpp @@ -21,8 +21,8 @@ * @brief ContainerImpl definition */ -#include -#include +#include "lxcpp/container-impl.hpp" +#include "lxcpp/exception.hpp" namespace lxcpp { @@ -36,62 +36,62 @@ ContainerImpl::~ContainerImpl() std::string ContainerImpl::getName() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::setName(const std::string& /* name */) { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::start() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::stop() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::freeze() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::unfreeze() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::reboot() { - throw NotImplemented(); + throw NotImplementedException(); } int ContainerImpl::getInitPid() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::create() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::destroy() { - throw NotImplemented(); + throw NotImplementedException(); } void ContainerImpl::setRootPath(const std::string& /* path */) { - throw NotImplemented(); + throw NotImplementedException(); } -std::string getRootPath() +std::string ContainerImpl::getRootPath() { - throw NotImplemented(); + throw NotImplementedException(); } } // namespace lxcpp diff --git a/libs/lxcpp/container-impl.hpp b/libs/lxcpp/container-impl.hpp index 9b9b1ea..f5d9547 100644 --- a/libs/lxcpp/container-impl.hpp +++ b/libs/lxcpp/container-impl.hpp @@ -24,7 +24,7 @@ #ifndef LXCPP_CONTAINER_IMPL_HPP #define LXCPP_CONTAINER_IMPL_HPP -#include +#include "lxcpp/container.hpp" namespace lxcpp { diff --git a/libs/lxcpp/container.hpp b/libs/lxcpp/container.hpp index 36e877e..74caa51 100644 --- a/libs/lxcpp/container.hpp +++ b/libs/lxcpp/container.hpp @@ -30,7 +30,7 @@ namespace lxcpp { class Container { public: - virtual ~Container(); + virtual ~Container() {}; virtual std::string getName() = 0; virtual void setName(const std::string& name) = 0; diff --git a/libs/lxcpp/exception.hpp b/libs/lxcpp/exception.hpp index 1e3ce4c..9d59101 100644 --- a/libs/lxcpp/exception.hpp +++ b/libs/lxcpp/exception.hpp @@ -28,18 +28,23 @@ namespace lxcpp { -class ContainerException : std::runtime_error -{ -public: - ContainerException(const std::string& what) : std::runtime_error(what) {} +/** + * Base class for exceptions in lxcpp + */ +struct Exception: public std::runtime_error { + Exception(const std::string& message) + : std::runtime_error(message) {} }; -class NotImplemented : ContainerException -{ -public: - NotImplemented() : ContainerException(std::string()) {} +struct NotImplementedException: public Exception { + NotImplementedException(const std::string& message = "Functionality not yet implemented") + : Exception(message) {} }; +struct ProcessSetupException: public Exception { + ProcessSetupException(const std::string& message = "Error during setting up a process") + : Exception(message) {} +}; } // namespace lxcpp #endif // LXCPP_EXCEPTION_HPP diff --git a/libs/lxcpp/lxcpp.cpp b/libs/lxcpp/lxcpp.cpp index 3cb906c..97c3866 100644 --- a/libs/lxcpp/lxcpp.cpp +++ b/libs/lxcpp/lxcpp.cpp @@ -21,7 +21,7 @@ * @brief lxcpp container factory definition */ -#include +#include "lxcpp/container-impl.hpp" namespace lxcpp { diff --git a/libs/lxcpp/lxcpp.hpp b/libs/lxcpp/lxcpp.hpp index 8037d3c..5eb3f57 100644 --- a/libs/lxcpp/lxcpp.hpp +++ b/libs/lxcpp/lxcpp.hpp @@ -18,13 +18,13 @@ /** * @file * @author Mateusz Malicki (m.malicki2@samsung.com) - * @brief LXCpp factory declaration + * @brief lxcpp container factory */ #ifndef LXCPP_LXCPP_HPP #define LXCPP_LXCPP_HPP -#include +#include "lxcpp/container.hpp" namespace lxcpp { diff --git a/libs/lxcpp/process.cpp b/libs/lxcpp/process.cpp new file mode 100644 index 0000000..200d12e --- /dev/null +++ b/libs/lxcpp/process.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * @author Jan Olszak (j.olszak@samsung.com) + * @brief process handling routines + */ + +#include "lxcpp/process.hpp" +#include "lxcpp/exception.hpp" +#include "logger/logger.hpp" + +#include +#include +#include +#include + +namespace lxcpp { + +pid_t clone(int (*function)(void *), int flags, void *args) { + // Won't fail, well known resource name + size_t stackSize = ::sysconf(_SC_PAGESIZE); + + // PAGESIZE is enough, it'll exec after this + char *stack = static_cast(::alloca(stackSize)); + + pid_t ret; + ret = ::clone(function, stack + stackSize, flags | SIGCHLD, args); + if (ret < 0) { + LOGE("clone() failed"); + throw ProcessSetupException("clone() failed"); + } + + return ret; +} + +} // namespace lxcpp \ No newline at end of file diff --git a/libs/lxcpp/process.hpp b/libs/lxcpp/process.hpp new file mode 100644 index 0000000..8ca8aaf --- /dev/null +++ b/libs/lxcpp/process.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * @author Jan Olszak (j.olszak@samsung.com) + * @brief process handling routines + */ + +#ifndef LXCPP_PROCESS_HPP +#define LXCPP_PROCESS_HPP + +#include + +namespace lxcpp { + +pid_t clone(int (*function)(void *), int flags, void *args); + +} // namespace lxcpp + +#endif // LXCPP_PROCESS_HPP \ No newline at end of file diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index aa652c7..956082d 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -61,7 +61,7 @@ SET_TARGET_PROPERTIES(${UT_SERVER_CODENAME} PROPERTIES ) TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES} - Logger Config Ipc) + Logger Config Ipc lxcpp) IF(NOT WITHOUT_DBUS) TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} SimpleDbus) ENDIF(NOT WITHOUT_DBUS) diff --git a/tests/unit_tests/lxcpp/ut-container.cpp b/tests/unit_tests/lxcpp/ut-container.cpp new file mode 100644 index 0000000..74ebbfe --- /dev/null +++ b/tests/unit_tests/lxcpp/ut-container.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Piotr Bartosiewicz + * + * 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 + */ + + +/** + * @file + * @author Jan Olszak(j.olszak@samsung.com) + * @brief Unit tests of lxcpp Container class + */ + +#include "config.hpp" +#include "ut.hpp" + +#include "lxcpp/lxcpp.hpp" +#include "lxcpp/exception.hpp" + +#include + +namespace { + +struct Fixture { + Fixture() {} + ~Fixture() {} +}; + +} // namespace + +BOOST_FIXTURE_TEST_SUITE(LxcppContainerSuite, Fixture) + +using namespace lxcpp; + +BOOST_AUTO_TEST_CASE(ConstructorDestructor) +{ + auto c = createContainer(); + delete c; +} + +BOOST_AUTO_TEST_SUITE_END() -- 2.7.4 From 44461ead945d681a7941e0d2a2dc10b7103330f7 Mon Sep 17 00:00:00 2001 From: Lukasz Pawelczyk Date: Wed, 29 Jul 2015 12:03:08 +0200 Subject: [PATCH 16/16] Fix pkg-config files from returning wrong relative paths. [Bug] The pkg-config files were using wrong relative paths [Cause] CMAKE_INSTALL_* variables are relative, cmake could handle them internally for INSTALL and similar, but for pkgconfig understands them literally. [Solution] Use absolute paths everywhere. [Verification] Check the content of *.pc files after make install. Change-Id: I2a14d0f9ddc45238be7e8d487d186df1877730bd --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5203a6a..735b349 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,15 +161,15 @@ IF(NOT DEFINED SYSCONF_INSTALL_DIR) ENDIF(NOT DEFINED SYSCONF_INSTALL_DIR) IF(NOT DEFINED LIB_INSTALL_DIR) - SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") + SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") ENDIF(NOT DEFINED LIB_INSTALL_DIR) IF(NOT DEFINED INCLUDE_INSTALL_DIR) - SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") + SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") ENDIF(NOT DEFINED INCLUDE_INSTALL_DIR) IF(NOT DEFINED SCRIPT_INSTALL_DIR) - SET(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_SBINDIR}") + SET(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SBINDIR}") ENDIF(NOT DEFINED SCRIPT_INSTALL_DIR) IF(NOT DEFINED SYSTEMD_UNIT_DIR) -- 2.7.4