lxcpp: Switch on serialization from libConfig 13/49213/4
authorJan Olszak <j.olszak@samsung.com>
Thu, 8 Oct 2015 12:19:22 +0000 (14:19 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 12 Oct 2015 09:41:49 +0000 (02:41 -0700)
[Feature]       Use std::pair and enum serialization
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: I6edb4543bf85eacfb2efe13065970326b30aba17

libs/lxcpp/attach/attach-config.hpp
libs/lxcpp/attach/attach-helper.cpp
libs/lxcpp/commands/attach.cpp
libs/lxcpp/commands/attach.hpp
libs/lxcpp/container-impl.cpp
libs/lxcpp/container-impl.hpp
libs/lxcpp/container.hpp
libs/lxcpp/guard/guard.cpp
libs/lxcpp/process.cpp
libs/lxcpp/process.hpp

index 9788abe..94e2626 100644 (file)
@@ -39,7 +39,7 @@ namespace lxcpp {
 struct AttachConfig {
 
     /// Arguments passed by user, argv[0] is the binary's path in container
-    std::vector<const char*> argv;
+    std::vector<std::string> argv;
 
     /// PID of the container's init process
     pid_t initPid;
@@ -73,7 +73,7 @@ struct AttachConfig {
 
     AttachConfig() = default;
 
-    AttachConfig(const std::vector<const char*>& argv,
+    AttachConfig(const std::vector<std::string>& argv,
                  const pid_t initPid,
                  const std::vector<Namespace>& namespaces,
                  const uid_t uid,
@@ -99,19 +99,17 @@ struct AttachConfig {
     CONFIG_REGISTER
     (
         //TODO: Uncomment and fix cstring serialization
-        // argv,
+        argv,
         initPid,
-        //TODO: Uncomment and fix Namespace serialization (or remove Namespace)
-        // namespaces,
+        namespaces,
         uid,
         gid,
         ttyFD,
         supplementaryGids,
         capsToKeep,
         workDirInContainer,
-        envToKeep
-        //TODO: Uncomment and fix std::pair serialization
-        // envToSet
+        envToKeep,
+        envToSet
     )
 };
 
index 321502f..5aaaecb 100644 (file)
@@ -70,8 +70,8 @@ int child(void* data)
         ::_exit(EXIT_FAILURE);
     }
 
-    // Run user's binary
-    ::execve(config.argv[0], const_cast<char *const*>(config.argv.data()), nullptr);
+    lxcpp::execve(config.argv);
+
     return EXIT_FAILURE;
 }
 
index 2bfa592..a059986 100644 (file)
@@ -34,7 +34,7 @@
 namespace lxcpp {
 
 Attach::Attach(const lxcpp::ContainerImpl& container,
-               const std::vector<const char*>& argv,
+               const std::vector<std::string>& argv,
                const uid_t uid,
                const gid_t gid,
                const std::string& ttyPath,
index ce39b83..123a384 100644 (file)
@@ -56,7 +56,7 @@ public:
      * @param envToSet new environment variables that will be set
      */
     Attach(const lxcpp::ContainerImpl& container,
-           const std::vector<const char*>& argv,
+           const std::vector<std::string>& argv,
            const uid_t uid,
            const gid_t gid,
            const std::string& ttyPath,
index c7035e4..9ff4b52 100644 (file)
@@ -205,7 +205,7 @@ void ContainerImpl::reboot()
     throw NotImplementedException();
 }
 
-void ContainerImpl::attach(const std::vector<const char*>& argv,
+void ContainerImpl::attach(const std::vector<std::string>& argv,
                            const std::string& cwdInContainer)
 {
     Attach attach(*this,
index 7393974..041303b 100644 (file)
@@ -65,7 +65,7 @@ public:
     void reboot();
 
     // Other
-    void attach(const std::vector<const char*>& argv,
+    void attach(const std::vector<std::string>& argv,
                 const std::string& cwdInContainer);
 
     // Network interfaces setup/config
index 51dda8c..7f98aed 100644 (file)
@@ -71,7 +71,7 @@ public:
     virtual void reboot() = 0;
 
     // Other
-    virtual void attach(const std::vector<const char*>& argv,
+    virtual void attach(const std::vector<std::string>& argv,
                         const std::string& cwdInContainer) = 0;
 
     // Network interfaces setup/config
index 952cdf5..369d423 100644 (file)
@@ -38,16 +38,7 @@ namespace lxcpp {
 
 void startContainer(const ContainerConfig &cfg)
 {
-    std::vector<char const *> argv;
-    argv.reserve(cfg.mInit.size() + 1);
-    for (auto const & it : cfg.mInit) {
-        argv.push_back(it.c_str());
-    }
-    argv.push_back(nullptr);
-
-    LOGD("Executing container's init: " << argv[0]);
-    ::execve(argv[0], const_cast<char *const*>(argv.data()), NULL);
-    ::_exit(EXIT_FAILURE);
+    lxcpp::execve(cfg.mInit);
 }
 
 int startGuard(int channelFD)
index 0353d82..204dec2 100644 (file)
@@ -156,4 +156,20 @@ void unshare(const Namespace ns)
         throw ProcessSetupException(msg);
     }
 }
+
+void execve(const std::vector<std::string>& argv)
+{
+    // Prepare the arguments
+    std::vector<char const *> tmpArgv;
+    tmpArgv.reserve(argv.size() + 1);
+
+    for (auto const &str : argv) {
+        tmpArgv.push_back(str.c_str());
+    }
+    tmpArgv.push_back(nullptr);
+
+    // Run user's binary
+    ::execve(tmpArgv[0], const_cast<char *const*>(tmpArgv.data()), nullptr);
+}
+
 } // namespace lxcpp
index 869e3d6..75c1e4f 100644 (file)
@@ -49,6 +49,8 @@ int waitpid(const pid_t pid);
 
 void unshare(const Namespace ns);
 
+void execve(const std::vector<std::string>& argv);
+
 } // namespace lxcpp
 
 #endif // LXCPP_PROCESS_HPP
\ No newline at end of file