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_COMMANDS_ATTACH_HPP
25 #define LXCPP_COMMANDS_ATTACH_HPP
27 #include "lxcpp/commands/command.hpp"
28 #include "lxcpp/container-impl.hpp"
29 #include "utils/channel.hpp"
35 class Attach final: Command {
37 typedef std::function<int(void)> Call;
40 * Runs call in the container's context
42 * Object attach should be used immediately after creation.
43 * It will not be stored for future use like most other commands.
45 * @param container container to which it attaches
46 * @param userCall user's function to run
47 * @param capsToKeep capabilities that will be kept
48 * @param workDirInContainer work directory set for the new process
49 * @param envToKeep environment variables that will be kept
50 * @param envToSet new environment variables that will be set
52 Attach(lxcpp::ContainerImpl& container,
53 Container::AttachCall& userCall,
55 const std::string& workDirInContainer,
56 const std::vector<std::string>& envToKeep,
57 const std::vector<std::pair<std::string, std::string>>& envToSet);
63 const lxcpp::ContainerImpl& mContainer;
64 const Container::AttachCall& mUserCall;
65 const int mCapsToKeep;
66 const std::string& mWorkDirInContainer;
67 const std::vector<std::string>& mEnvToKeep;
68 const std::vector<std::pair<std::string, std::string>>& mEnvToSet;
70 // Methods for different stages of setting up the attachment
71 static int child(const Container::AttachCall& call,
73 const std::vector<std::string>& envToKeep,
74 const std::vector<std::pair<std::string, std::string>>& envToSet);
76 void parent(utils::Channel& intermChannel,
79 void interm(utils::Channel& intermChannel,
85 #endif // LXCPP_COMMANDS_ATTACH_HPP