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"
29 #include "config/manager.hpp"
30 #include "logger/logger.hpp"
39 int startContainer(void* data)
41 ContainerConfig& config = *static_cast<ContainerConfig*>(data);
43 // TODO: container preparation part 2
45 PrepGuestTerminal terminals(config.mTerminals);
48 lxcpp::execve(config.mInit);
56 Guard::Guard(const int channelFD)
59 mChannel.setCloseOnExec(true);
60 config::loadFromFD(mChannel.getFD(), mConfig);
62 logger::setupLogger(mConfig.mLogger.getType(),
63 mConfig.mLogger.getLevel(),
64 mConfig.mLogger.getArg());
66 LOGD("Config & logging restored");
69 LOGD("Setting the guard process title");
70 const std::string title = "[LXCPP] " + mConfig.mName + " " + mConfig.mRootPath;
72 } catch (std::exception &e) {
73 // Ignore, this is optional
74 LOGW("Failed to set the guard process title: " << e.what());
84 // TODO: container preparation part 1
86 const pid_t initPid = lxcpp::clone(startContainer,
90 mConfig.mGuardPid = ::getpid();
91 mConfig.mInitPid = initPid;
93 mChannel.write(mConfig.mGuardPid);
94 mChannel.write(mConfig.mInitPid);
97 int status = lxcpp::waitpid(initPid);
98 LOGD("Init exited with status: " << status);