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 Lukasz Pawelczyk (l.pawelczyk@samsung.com)
21 * @brief LXCPP guard process implementation
24 #include "lxcpp/utils.hpp"
25 #include "lxcpp/guard/guard.hpp"
26 #include "lxcpp/process.hpp"
27 #include "lxcpp/commands/prep-guest-terminal.hpp"
28 #include "lxcpp/commands/provision.hpp"
30 #include "config/manager.hpp"
31 #include "logger/logger.hpp"
40 int startContainer(void* data)
42 ContainerConfig& config = *static_cast<ContainerConfig*>(data);
44 // TODO: container preparation part 2
46 Provisions provisions(config);
49 PrepGuestTerminal terminals(config.mTerminals);
52 lxcpp::execve(config.mInit);
60 Guard::Guard(const int channelFD)
63 mChannel.setCloseOnExec(true);
64 config::loadFromFD(mChannel.getFD(), mConfig);
66 logger::setupLogger(mConfig.mLogger.getType(),
67 mConfig.mLogger.getLevel(),
68 mConfig.mLogger.getArg());
70 LOGD("Config & logging restored");
73 LOGD("Setting the guard process title");
74 const std::string title = "[LXCPP] " + mConfig.mName + " " + mConfig.mRootPath;
76 } catch (std::exception &e) {
77 // Ignore, this is optional
78 LOGW("Failed to set the guard process title: " << e.what());
88 // TODO: container preparation part 1
90 const pid_t initPid = lxcpp::clone(startContainer,
94 mConfig.mGuardPid = ::getpid();
95 mConfig.mInitPid = initPid;
97 mChannel.write(mConfig.mGuardPid);
98 mChannel.write(mConfig.mInitPid);
101 int status = lxcpp::waitpid(initPid);
102 LOGD("Init exited with status: " << status);
104 // TODO: cleanup after child exits
105 Provisions provisions(mConfig);