2 * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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.
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.
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
20 * @author Jan Olszak (j.olszak@samsung.com)
21 * @brief Implementation of attaching to a container
24 #ifndef LXCPP_ATTACH_MANAGER_HPP
25 #define LXCPP_ATTACH_MANAGER_HPP
27 #include "lxcpp/container-impl.hpp"
28 #include "utils/channel.hpp"
34 class AttachManager final {
36 typedef std::function<int(void)> Call;
38 AttachManager(lxcpp::ContainerImpl& container);
42 * Runs the call in the container's context
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
50 void attach(Container::AttachCall& call,
52 const std::string& workDirInContainer,
53 const std::vector<std::string>& envToKeep,
54 const std::vector<std::pair<std::string, std::string>>& envToSet);
58 const lxcpp::ContainerImpl& mContainer;
60 // Methods for different stages of setting up the attachment
61 static int child(const Container::AttachCall& call,
63 const std::vector<std::string>& envToKeep,
64 const std::vector<std::pair<std::string, std::string>>& envToSet);
66 void parent(utils::Channel& intermChannel,
69 void interm(utils::Channel& intermChannel,
70 const std::string& workDirInContainer,
71 Container::AttachCall& call);
76 #endif // LXCPP_ATTACH_MANAGER_HPP