}
}
+void sendSignal(const pid_t pid, const int sigNum)
+{
+ if (-1 == ::kill(pid, sigNum)) {
+ const std::string msg = "Error during killing pid: " + std::to_string(pid) +
+ " sigNum: " + std::to_string(sigNum) +
+ ": " + getSystemErrorMessage();
+ LOGE(msg);
+ throw UtilsException(msg);
+ }
+}
+
} // namespace utils
void signalBlock(const int sigNum);
void signalUnblock(const int sigNum);
void signalIgnore(const std::initializer_list<int>& signals);
+void sendSignal(const pid_t pid, const int sigNum);
} // namespace utils
--- /dev/null
+/*
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Implementation of stopping a container
+ */
+
+#include "lxcpp/commands/stop.hpp"
+#include "lxcpp/exception.hpp"
+#include "lxcpp/process.hpp"
+
+#include "logger/logger.hpp"
+#include "utils/signal.hpp"
+
+namespace lxcpp {
+
+Stop::Stop(ContainerConfig &config)
+ : mConfig(config)
+{
+}
+
+Stop::~Stop()
+{
+}
+
+void Stop::execute()
+{
+ LOGD("Stopping container: " << mConfig.mName);
+
+ // TODO: Use initctl/systemd-initctl if available in container
+
+ utils::sendSignal(mConfig.mInitPid, SIGTERM);
+}
+
+} // namespace lxcpp
--- /dev/null
+/*
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Implementation of stopping a container
+ */
+
+#ifndef LXCPP_COMMANDS_STOP_HPP
+#define LXCPP_COMMANDS_STOP_HPP
+
+#include "lxcpp/commands/command.hpp"
+#include "lxcpp/container-config.hpp"
+
+#include <sys/types.h>
+
+
+namespace lxcpp {
+
+
+class Stop final: Command {
+public:
+ /**
+ * Stops the container
+ *
+ * @param config container's config
+ */
+ Stop(ContainerConfig &config);
+ ~Stop();
+
+ void execute();
+
+private:
+ ContainerConfig &mConfig;
+};
+
+
+} // namespace lxcpp
+
+
+#endif // LXCPP_COMMANDS_STOP_HPP
#include "lxcpp/capability.hpp"
#include "lxcpp/commands/attach.hpp"
#include "lxcpp/commands/start.hpp"
+#include "lxcpp/commands/stop.hpp"
#include "lxcpp/commands/prep-host-terminal.hpp"
#include "logger/logger.hpp"
// TODO: things to do when shuttting down the container:
// - close PTY master FDs from the config so we won't keep PTYs open
- throw NotImplementedException();
+ Stop stop(mConfig);
+ stop.execute();
}
void ContainerImpl::freeze()
// Skip the first 47 fields, entries 48-49 are ARG_START and ARG_END.
std::advance(it, 47);
- unsigned long argStart = std::stol(*it++);
- unsigned long argEnd = std::stol(*it++);
+ unsigned long argStart = std::stoul(*it++);
+ unsigned long argEnd = std::stoul(*it);
f.close();
BadArgument);
}
-// BOOST_AUTO_TEST_CASE(StartStop)
-// {
-// auto c = std::unique_ptr<Container>(createContainer("StartStop", "/"));
-// BOOST_CHECK_NO_THROW(c->setInit(COMMAND));
-// BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_PERSISTENT_FILE,
-// logger::LogLevel::DEBUG,
-// LOGGER_FILE));
-// BOOST_CHECK_NO_THROW(c->start());
-// }
+BOOST_AUTO_TEST_CASE(StartStop)
+{
+ auto c = std::unique_ptr<Container>(createContainer("StartStop", "/"));
+ BOOST_CHECK_NO_THROW(c->setInit(COMMAND));
+ BOOST_CHECK_NO_THROW(c->setLogger(logger::LogType::LOG_PERSISTENT_FILE,
+ logger::LogLevel::DEBUG,
+ LOGGER_FILE));
+ BOOST_CHECK_NO_THROW(c->start());
+ BOOST_CHECK_NO_THROW(c->stop());
+}
BOOST_AUTO_TEST_SUITE_END()