ipc: Fix critical build break in unique-id
[platform/core/security/vasum.git] / libs / lxcpp / commands / attach-manager.hpp
1 /*
2  *  Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License version 2.1 as published by the Free Software Foundation.
7  *
8  *  This library is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  *  Lesser General Public License for more details.
12  *
13  *  You should have received a copy of the GNU Lesser General Public
14  *  License along with this library; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17
18 /**
19  * @file
20  * @author  Jan Olszak (j.olszak@samsung.com)
21  * @brief   Implementation of attaching to a container
22  */
23
24 #ifndef LXCPP_ATTACH_MANAGER_HPP
25 #define LXCPP_ATTACH_MANAGER_HPP
26
27 #include "lxcpp/container-impl.hpp"
28 #include "utils/channel.hpp"
29
30 #include <string>
31
32 namespace lxcpp {
33
34 class AttachManager final {
35 public:
36     typedef std::function<int(void)> Call;
37
38     AttachManager(lxcpp::ContainerImpl& container);
39     ~AttachManager();
40
41     /**
42      * Runs the call in the container's context
43      *
44      * @param call function to run inside container
45      * @param capsToKeep mask of the capabilities that shouldn't be dropped
46      * @param workDirInContainer Current Work Directory. Path relative to container's root
47      * @param envToKeep environment variables to keep in container
48      * @param envToSet environment variables to add/modify in container
49      */
50     void attach(Container::AttachCall& call,
51                 const int capsToKeep,
52                 const std::string& workDirInContainer,
53                 const std::vector<std::string>& envToKeep,
54                 const std::vector<std::pair<std::string, std::string>>& envToSet);
55
56 private:
57
58     const lxcpp::ContainerImpl& mContainer;
59
60     // Methods for different stages of setting up the attachment
61     static int child(const Container::AttachCall& call,
62                      const int capsToKeep,
63                      const std::vector<std::string>& envToKeep,
64                      const std::vector<std::pair<std::string, std::string>>& envToSet);
65
66     void parent(utils::Channel& intermChannel,
67                 const pid_t pid);
68
69     void interm(utils::Channel& intermChannel,
70                 const std::string& workDirInContainer,
71                 Container::AttachCall& call);
72 };
73
74 } // namespace lxcpp
75
76 #endif // LXCPP_ATTACH_MANAGER_HPP