diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-25 13:36:02 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-25 13:36:02 +0200 |
commit | af0f84058d322d68cbbff98ef272dd2bcd0f692c (patch) | |
tree | 23b1fb83790f2100ae2d16eb0af71122e88cba0a /src | |
parent | 3a8e13c8ef66a4fdb06b2051bd7ab95ca24cc81c (diff) | |
download | mad-af0f84058d322d68cbbff98ef272dd2bcd0f692c.tar mad-af0f84058d322d68cbbff98ef272dd2bcd0f692c.zip |
Daemon-Host kann jetzt heruntergefahren und neu gestartet werden
Diffstat (limited to 'src')
28 files changed, 648 insertions, 61 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 87202b4..74b5710 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -19,6 +19,7 @@ #include "CommandParser.h" #include "Requests/CoreStatusRequest.h" +#include "Requests/DaemonCommandRequest.h" #include "Requests/DaemonListRequest.h" #include "Requests/DaemonStatusRequest.h" #include <Common/Exception.h> @@ -38,6 +39,8 @@ namespace Client { const CommandParser::Command CommandParser::commands[] = { {{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand}, {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand}, + {{"reboot", 0}, "reboot host", "Reboots a host", "Reboots a host.", &CommandParser::rebootCommand}, + {{"shutdown", 0}, "shutdown host", "Shuts a host down", "Shuts a host down.", &CommandParser::shutdownCommand}, {{"status", "st", 0}, "status [host]", "Displays status information", "Displays host status information. If no host is given, server status information is displayed.", &CommandParser::statusCommand}, {{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand}, {{0}, 0, 0, 0, 0} @@ -135,7 +138,7 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) { std::cout << command->longdesc << std::endl << std::endl; } else - Common::Logger::logf(Common::Logger::WARNING,"%s: Command '%s' doesn't exist.\n", args[0].c_str(), args[1].c_str()); + Common::Logger::logf(Common::Logger::WARNING,"%s: Command '%s' doesn't exist.", args[0].c_str(), args[1].c_str()); } else { Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); @@ -176,6 +179,44 @@ void CommandParser::listHostsCommand(const std::vector<std::string> &args) { activeRequests++; } +void CommandParser::rebootCommand(const std::vector<std::string> &args) { + if(args.size() < 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: No host given.", args[0].c_str()); + printUsage("reboot"); + return; + } + else if(args.size() > 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); + printUsage("reboot"); + return; + } + + Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>( + new Requests::DaemonCommandRequest(args[1], true, sigc::mem_fun(this, &CommandParser::daemonCommandRequestFinished)) + )); + + activeRequests++; +} + +void CommandParser::shutdownCommand(const std::vector<std::string> &args) { + if(args.size() < 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: No host given.", args[0].c_str()); + printUsage("reboot"); + return; + } + else if(args.size() > 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); + printUsage("reboot"); + return; + } + + Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>( + new Requests::DaemonCommandRequest(args[1], false, sigc::mem_fun(this, &CommandParser::daemonCommandRequestFinished)) + )); + + activeRequests++; +} + void CommandParser::statusCommand(const std::vector<std::string> &args) { if(args.size() == 1) Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::CoreStatusRequest(sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished)))); @@ -203,7 +244,18 @@ void CommandParser::coreStatusRequestFinished(const Common::Request<Net::Packets printHostStatus(packet); } catch(Common::Exception &exception) { - Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.\n", exception.strerror().c_str()); + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); + } + + requestFinished(); +} + +void CommandParser::daemonCommandRequestFinished(const Common::Request<> &request) { + try { + request.getResult(); + } + catch(Common::Exception &exception) { + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); } requestFinished(); @@ -243,7 +295,7 @@ void CommandParser::daemonListRequestFinished(const Common::Request<Net::Packets } } catch(Common::Exception &exception) { - Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.\n", exception.strerror().c_str()); + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); } requestFinished(); @@ -256,7 +308,7 @@ void CommandParser::daemonStatusRequestFinished(const Common::Request<Net::Packe printHostStatus(packet); } catch(Common::Exception &exception) { - Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.\n", exception.strerror().c_str()); + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); } requestFinished(); @@ -268,7 +320,7 @@ void CommandParser::disconnectRequestFinished(const Common::Request<> &request) disconnect = true; } catch(Common::Exception &exception) { - Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.\n", exception.strerror().c_str()); + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); } requestFinished(); @@ -344,7 +396,7 @@ bool CommandParser::parse(const std::string &cmd) { if(command) (this->*command->funcPtr)(splitCmd); else - Common::Logger::logf(Common::Logger::ERROR, "Unknown command '%s'.\n", splitCmd[0].c_str()); + Common::Logger::logf(Common::Logger::ERROR, "Unknown command '%s'.", splitCmd[0].c_str()); return true; } diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index 28abb12..9b94ef0 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -72,10 +72,13 @@ class CommandParser { void helpCommand(const std::vector<std::string> &args); void listHostsCommand(const std::vector<std::string> &args); + void rebootCommand(const std::vector<std::string> &args); + void shutdownCommand(const std::vector<std::string> &args); void statusCommand(const std::vector<std::string> &args); void exitCommand(const std::vector<std::string>&); void coreStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request); + void daemonCommandRequestFinished(const Common::Request<> &request); void daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request, bool all); void daemonStatusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request); void disconnectRequestFinished(const Common::Request<> &request); diff --git a/src/Client/Requests/DaemonCommandRequest.cpp b/src/Client/Requests/DaemonCommandRequest.cpp new file mode 100644 index 0000000..d27c3fb --- /dev/null +++ b/src/Client/Requests/DaemonCommandRequest.cpp @@ -0,0 +1,47 @@ +/* + * DaemonCommandRequest.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "DaemonCommandRequest.h" +#include <Net/Connection.h> +#include <Net/Packets/ErrorPacket.h> + +namespace Mad { +namespace Client { +namespace Requests { + +void DaemonCommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(reboot ? Net::Packet::DAEMON_COMMAND_REBOOT : Net::Packet::DAEMON_COMMAND_SHUTDOWN, requestId, daemon.c_str(), daemon.length())); +} + +void DaemonCommandRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { + if(packet.getType() == Net::Packet::ERROR) { + finishWithError(Net::Packets::ErrorPacket(packet).getException()); + return; + } + else if(packet.getType() != Net::Packet::OK) { + finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET)); + return; // TODO Logging + } + + finish(); +} + +} +} +} diff --git a/src/Client/Requests/DaemonCommandRequest.h b/src/Client/Requests/DaemonCommandRequest.h new file mode 100644 index 0000000..439462f --- /dev/null +++ b/src/Client/Requests/DaemonCommandRequest.h @@ -0,0 +1,47 @@ +/* + * DaemonCommandRequest.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_ +#define MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_ + +#include <Common/Request.h> +#include <string> + +namespace Mad { +namespace Client { +namespace Requests { + +class DaemonCommandRequest : public Common::Request<> { + private: + std::string daemon; + bool reboot; + + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + DaemonCommandRequest(const std::string &daemon0, bool reboot0, slot_type slot) : Common::Request<>(slot), daemon(daemon0), reboot(reboot0) {} +}; + +} +} +} + +#endif /* MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_ */ diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h index 8f74ca4..cd71dfb 100644 --- a/src/Client/Requests/DaemonStatusRequest.h +++ b/src/Client/Requests/DaemonStatusRequest.h @@ -26,10 +26,6 @@ namespace Mad { -namespace Common { -class Exception; -} - namespace Net { namespace Packets { class HostStatusPacket; diff --git a/src/Client/Requests/Makefile.am b/src/Client/Requests/Makefile.am index e8e72d4..8c4f542 100644 --- a/src/Client/Requests/Makefile.am +++ b/src/Client/Requests/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp +librequests_la_SOURCES = CoreStatusRequest.cpp DaemonCommandRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp -noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h DaemonStatusRequest.h +noinst_HEADERS = CoreStatusRequest.h DaemonCommandRequest.h DaemonListRequest.h DaemonStatusRequest.h diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in index bb9a837..9336dbb 100644 --- a/src/Client/Requests/Makefile.in +++ b/src/Client/Requests/Makefile.in @@ -48,7 +48,8 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequests_la_LIBADD = -am_librequests_la_OBJECTS = CoreStatusRequest.lo DaemonListRequest.lo \ +am_librequests_la_OBJECTS = CoreStatusRequest.lo \ + DaemonCommandRequest.lo DaemonListRequest.lo \ DaemonStatusRequest.lo librequests_la_OBJECTS = $(am_librequests_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src @@ -188,8 +189,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = CoreStatusRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp -noinst_HEADERS = CoreStatusRequest.h DaemonListRequest.h DaemonStatusRequest.h +librequests_la_SOURCES = CoreStatusRequest.cpp DaemonCommandRequest.cpp DaemonListRequest.cpp DaemonStatusRequest.cpp +noinst_HEADERS = CoreStatusRequest.h DaemonCommandRequest.h DaemonListRequest.h DaemonStatusRequest.h all: all-am .SUFFIXES: @@ -242,6 +243,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusRequest.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonCommandRequest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@ diff --git a/src/Common/Backends/SystemBackendPosix.h b/src/Common/Backends/SystemBackendPosix.h index aa2b9be..9efd59f 100644 --- a/src/Common/Backends/SystemBackendPosix.h +++ b/src/Common/Backends/SystemBackendPosix.h @@ -33,7 +33,7 @@ namespace Mad { namespace Common { namespace Backends { -class SystemBackendPosix { +class SystemBackendPosix : public SystemBackend { private: static SystemBackendPosix backend; static std::map<pid_t, sigc::slot<void, int> > processes; @@ -46,9 +46,21 @@ class SystemBackendPosix { setChildHandler(); } + protected: + virtual bool doShutdown() {return exec(sigc::slot<void, int>(), "/sbin/halt");} + virtual bool doReboot() {return exec(sigc::slot<void, int>(), "/sbin/reboot");} + public: ~SystemBackendPosix(); + static void registerBackend() { + SystemBackend::registerBackend(&backend); + } + + static void unregisterBackend() { + SystemBackend::unregisterBackend(&backend); + } + static bool exec(sigc::slot<void, int> resultHandler, const std::string &filename, const std::vector<std::string> &argv = std::vector<std::string>(), const std::vector<std::string> &env = std::vector<std::string>()); }; diff --git a/src/Common/Exception.cpp b/src/Common/Exception.cpp index 9366fe7..67eb1d9 100644 --- a/src/Common/Exception.cpp +++ b/src/Common/Exception.cpp @@ -42,6 +42,8 @@ std::string Exception::strerror() const { return ret + "Not available"; case NOT_FINISHED: return ret + "Not finished"; + case NOT_IMPLEMENTED: + return ret + "Not implemented"; case INTERNAL_ERRNO: return ret + std::strerror(subCode); case INTERNAL_GNUTLS: diff --git a/src/Common/Exception.h b/src/Common/Exception.h index 9862f9b..7b86fbd 100644 --- a/src/Common/Exception.h +++ b/src/Common/Exception.h @@ -28,7 +28,7 @@ namespace Common { class Exception { public: enum ErrorCode { - SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, NOT_AVAILABLE = 0x0003, NOT_FINISHED = 0x0004, + SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, NOT_AVAILABLE = 0x0003, NOT_FINISHED = 0x0004, NOT_IMPLEMENTED = 0x0005, INTERNAL_ERRNO = 0x0010, INTERNAL_GNUTLS = 0x0011, INVALID_ADDRESS = 0x0020, ALREADY_IDENTIFIED = 0x0030, UNKNOWN_DAEMON = 0x0031 diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index ad37964..dbdf9e1 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -31,7 +31,7 @@ namespace RequestHandlers { void StatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { if(packet.getType() != Net::Packet::STATUS) { Logger::log(Logger::ERROR, "Received an unexpected packet."); - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::UNEXPECTED_PACKET))); signalFinished().emit(); return; diff --git a/src/Common/SystemBackend.cpp b/src/Common/SystemBackend.cpp index 0d4b2b7..c017356 100644 --- a/src/Common/SystemBackend.cpp +++ b/src/Common/SystemBackend.cpp @@ -52,5 +52,23 @@ SystemBackend::LoadInfo SystemBackend::getLoadInfo() { return ret; } +bool SystemBackend::shutdown() { + bool ret = false; + + for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end() && !ret; ++backend) + ret = (*backend)->doShutdown(); + + return ret; +} + +bool SystemBackend::reboot() { + bool ret = false; + + for(std::set<SystemBackend*>::iterator backend = backends.begin(); backend != backends.end() && !ret; ++backend) + ret = (*backend)->doReboot(); + + return ret; +} + } } diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h index c531224..d9506a9 100644 --- a/src/Common/SystemBackend.h +++ b/src/Common/SystemBackend.h @@ -85,6 +85,9 @@ class SystemBackend { return ret; } + virtual bool doShutdown() {return false;} + virtual bool doReboot() {return false;} + virtual int getPriority() const { return 0; } @@ -95,6 +98,9 @@ class SystemBackend { static UptimeInfo getUptimeInfo(); static MemoryInfo getMemoryInfo(); static LoadInfo getLoadInfo(); + + static bool shutdown(); + static bool reboot(); }; } diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 272c04b..faf6e29 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -21,6 +21,7 @@ #include "ConfigManager.h" #include <Common/Logger.h> #include <Common/RequestHandlers/StatusRequestHandler.h> +#include "RequestHandlers/DaemonCommandRequestHandler.h" #include "RequestHandlers/DaemonListRequestHandler.h" #include "RequestHandlers/DaemonStatusRequestHandler.h" #include "RequestHandlers/GSSAPIAuthRequestHandler.h" @@ -67,6 +68,8 @@ ConnectionManager::ConnectionManager() { Common::RequestManager::init(true); Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>(Net::Packet::STATUS); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_REBOOT); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_SHUTDOWN); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonListRequestHandler>(Net::Packet::LIST_DAEMONS); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); diff --git a/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp new file mode 100644 index 0000000..9ae0bdd --- /dev/null +++ b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp @@ -0,0 +1,71 @@ +/* + * DaemonCommandRequestHandler.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "DaemonCommandRequestHandler.h" +#include "../ConnectionManager.h" +#include <Common/Logger.h> +#include <Core/Requests/CommandRequest.h> +#include <Net/Packets/ErrorPacket.h> + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::DAEMON_COMMAND_SHUTDOWN && packet.getType() != Net::Packet::DAEMON_COMMAND_REBOOT) { + Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + signalFinished().emit(); + return; + } + + // TODO Require authentication + + con = connection; + requestId = packet.getRequestId(); + + std::string daemonName((char*)packet.getData(), packet.getLength()); + + try { + Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName); + Common::RequestManager::getRequestManager()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>( + new Requests::CommandRequest(packet.getType() == Net::Packet::DAEMON_COMMAND_REBOOT, sigc::mem_fun(this, &DaemonCommandRequestHandler::requestFinished)) + )); + } + catch(Common::Exception &e) { + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e)); + } +} + +void DaemonCommandRequestHandler::requestFinished(const Common::Request<> &request) { + try { + request.getResult(); + con->send(Net::Packet(Net::Packet::OK, requestId)); + } + catch(Common::Exception &e) { + con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, requestId, e)); + } + + signalFinished().emit(); +} + +} +} +} diff --git a/src/Core/RequestHandlers/DaemonCommandRequestHandler.h b/src/Core/RequestHandlers/DaemonCommandRequestHandler.h new file mode 100644 index 0000000..bb021ed --- /dev/null +++ b/src/Core/RequestHandlers/DaemonCommandRequestHandler.h @@ -0,0 +1,49 @@ +/* + * DaemonCommandRequestHandler.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_CORE_REQUESTHANDLERS_DAEMONCOMMANDREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_DAEMONCOMMANDREQUESTHANDLER_H_ + +#include <Common/RequestHandler.h> +#include <Common/Request.h> +#include <stdint.h> + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +class DaemonCommandRequestHandler : public Common::RequestHandler { + private: + Net::Connection *con; + uint16_t requestId; + + void requestFinished(const Common::Request<> &request); + + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + DaemonCommandRequestHandler() {} +}; + +} +} +} + +#endif /* MAD_CORE_REQUESTHANDLERS_DAEMONCOMMANDREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am index 3c52634..484df59 100644 --- a/src/Core/RequestHandlers/Makefile.am +++ b/src/Core/RequestHandlers/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp +librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp -noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h +noinst_HEADERS = DaemonCommandRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in index a450ea0..e0dc6f2 100644 --- a/src/Core/RequestHandlers/Makefile.in +++ b/src/Core/RequestHandlers/Makefile.in @@ -48,9 +48,10 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = -am_librequesthandlers_la_OBJECTS = DaemonListRequestHandler.lo \ - DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \ - IdentifyRequestHandler.lo LogRequestHandler.lo +am_librequesthandlers_la_OBJECTS = DaemonCommandRequestHandler.lo \ + DaemonListRequestHandler.lo DaemonStatusRequestHandler.lo \ + GSSAPIAuthRequestHandler.lo IdentifyRequestHandler.lo \ + LogRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -189,8 +190,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp -noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h +librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp +noinst_HEADERS = DaemonCommandRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h all: all-am .SUFFIXES: @@ -242,6 +243,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonCommandRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequestHandler.Plo@am__quote@ diff --git a/src/Core/Requests/CommandRequest.cpp b/src/Core/Requests/CommandRequest.cpp new file mode 100644 index 0000000..35d4dd2 --- /dev/null +++ b/src/Core/Requests/CommandRequest.cpp @@ -0,0 +1,47 @@ +/* + * CommandRequest.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "CommandRequest.h" +#include <Net/Connection.h> +#include <Net/Packets/ErrorPacket.h> + +namespace Mad { +namespace Core { +namespace Requests { + +void CommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(reboot ? Net::Packet::COMMAND_REBOOT : Net::Packet::COMMAND_SHUTDOWN, requestId)); +} + +void CommandRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { + if(packet.getType() == Net::Packet::ERROR) { + finishWithError(Net::Packets::ErrorPacket(packet).getException()); + return; + } + else if(packet.getType() != Net::Packet::OK) { + finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET)); + return; // TODO Logging + } + + finish(); +} + +} +} +} diff --git a/src/Core/Requests/CommandRequest.h b/src/Core/Requests/CommandRequest.h new file mode 100644 index 0000000..181fa4d --- /dev/null +++ b/src/Core/Requests/CommandRequest.h @@ -0,0 +1,45 @@ +/* + * CommandRequest.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_CORE_REQUESTS_COMMANDREQUEST_H_ +#define MAD_CORE_REQUESTS_COMMANDREQUEST_H_ + +#include <Common/Request.h> + +namespace Mad { +namespace Core { +namespace Requests { + +class CommandRequest : public Common::Request<> { + private: + bool reboot; + + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + CommandRequest(bool reboot0, slot_type slot) : Common::Request<>(slot), reboot(reboot0) {} +}; + +} +} +} + +#endif /* MAD_CORE_REQUESTS_COMMANDREQUEST_H_ */ diff --git a/src/Core/Requests/Makefile.am b/src/Core/Requests/Makefile.am index d220dd6..2d08477 100644 --- a/src/Core/Requests/Makefile.am +++ b/src/Core/Requests/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = DaemonStatusRequest.cpp +librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp -noinst_HEADERS = DaemonStatusRequest.h +noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h diff --git a/src/Core/Requests/Makefile.in b/src/Core/Requests/Makefile.in index 23458f1..22ac701 100644 --- a/src/Core/Requests/Makefile.in +++ b/src/Core/Requests/Makefile.in @@ -48,7 +48,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequests_la_LIBADD = -am_librequests_la_OBJECTS = DaemonStatusRequest.lo +am_librequests_la_OBJECTS = CommandRequest.lo DaemonStatusRequest.lo librequests_la_OBJECTS = $(am_librequests_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -187,8 +187,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequests.la -librequests_la_SOURCES = DaemonStatusRequest.cpp -noinst_HEADERS = DaemonStatusRequest.h +librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp +noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h all: all-am .SUFFIXES: @@ -240,6 +240,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandRequest.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@ .cpp.o: diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp new file mode 100644 index 0000000..e49b0f5 --- /dev/null +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp @@ -0,0 +1,64 @@ +/* + * CommandRequestHandler.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "CommandRequestHandler.h" +#include <Common/Exception.h> +#include <Common/Logger.h> +#include <Common/SystemBackend.h> +#include <Net/Connection.h> +#include <Net/Packets/ErrorPacket.h> + +namespace Mad { +namespace Daemon { +namespace RequestHandlers { + +void CommandRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + // TODO Require authentication + + bool ret = false; + + switch(packet.getType()) { + case Net::Packet::COMMAND_SHUTDOWN: + ret = Common::SystemBackend::shutdown(); + break; + + case Net::Packet::COMMAND_REBOOT: + ret = Common::SystemBackend::reboot(); + break; + + default: + Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + signalFinished().emit(); + return; + } + + if(ret) + connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())); + else { + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::NOT_IMPLEMENTED))); + } + + signalFinished().emit(); +} + +} +} +} diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h new file mode 100644 index 0000000..cff6c10 --- /dev/null +++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h @@ -0,0 +1,41 @@ +/* + * CommandRequestHandler.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_ +#define MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_ + +#include <Common/RequestHandler.h> + +namespace Mad { +namespace Daemon { +namespace RequestHandlers { + +class CommandRequestHandler : public Common::RequestHandler { + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + CommandRequestHandler() {} +}; + +} +} +} + +#endif /* MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_ */ diff --git a/src/Daemon/RequestHandlers/Makefile.am b/src/Daemon/RequestHandlers/Makefile.am index 2108fe5..db7b343 100644 --- a/src/Daemon/RequestHandlers/Makefile.am +++ b/src/Daemon/RequestHandlers/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = +librequesthandlers_la_SOURCES = CommandRequestHandler.cpp -noinst_HEADERS = +noinst_HEADERS = CommandRequestHandler.h diff --git a/src/Daemon/RequestHandlers/Makefile.in b/src/Daemon/RequestHandlers/Makefile.in index 924fab1..96e1c75 100644 --- a/src/Daemon/RequestHandlers/Makefile.in +++ b/src/Daemon/RequestHandlers/Makefile.in @@ -48,21 +48,25 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = -am_librequesthandlers_la_OBJECTS = +am_librequesthandlers_la_OBJECTS = CommandRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(librequesthandlers_la_SOURCES) DIST_SOURCES = $(librequesthandlers_la_SOURCES) HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -183,11 +187,12 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = -noinst_HEADERS = +librequesthandlers_la_SOURCES = CommandRequestHandler.cpp +noinst_HEADERS = CommandRequestHandler.h all: all-am .SUFFIXES: +.SUFFIXES: .cpp .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -227,7 +232,7 @@ clean-noinstLTLIBRARIES: rm -f "$${dir}/so_locations"; \ done librequesthandlers.la: $(librequesthandlers_la_OBJECTS) $(librequesthandlers_la_DEPENDENCIES) - $(LINK) $(librequesthandlers_la_OBJECTS) $(librequesthandlers_la_LIBADD) $(LIBS) + $(CXXLINK) $(librequesthandlers_la_OBJECTS) $(librequesthandlers_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -235,17 +240,81 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandRequestHandler.Plo@am__quote@ + +.cpp.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique tags: TAGS -TAGS: +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi ctags: CTAGS -CTAGS: - +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -307,8 +376,10 @@ clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ mostlyclean-am distclean: distclean-am + -rm -rf ./$(DEPDIR) -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags dvi: dvi-am @@ -339,6 +410,7 @@ install-ps: install-ps-am installcheck-am: maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -359,18 +431,18 @@ uninstall-am: .MAKE: install-am install-strip -.PHONY: all all-am check check-am clean clean-generic clean-libtool \ - clean-noinstLTLIBRARIES distclean distclean-compile \ - distclean-generic distclean-libtool distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - uninstall uninstall-am +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/Net/Packet.h b/src/Net/Packet.h index 6b6ed75..a3fe524 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -34,7 +34,9 @@ class Packet { OK = 0x0000, ERROR = 0x0001, DISCONNECT = 0x0002, LOG = 0x0003, GSSAPI_AUTH = 0x0010, IDENTIFY = 0x0011, LIST_DAEMONS = 0x0020, - STATUS = 0x0030, DAEMON_STATUS = 0x0031 + STATUS = 0x0030, DAEMON_STATUS = 0x0031, + COMMAND_SHUTDOWN = 0x0040, COMMAND_REBOOT = 0x0041, + DAEMON_COMMAND_SHUTDOWN = 0x0050, DAEMON_COMMAND_REBOOT = 0x0051 }; struct Data { diff --git a/src/mad.cpp b/src/mad.cpp index ca4682f..47dbfec 100644 --- a/src/mad.cpp +++ b/src/mad.cpp @@ -19,6 +19,7 @@ #include "Net/ClientConnection.h" #include "Net/IPAddress.h" +#include "Common/Backends/SystemBackendPosix.h" #include "Common/Backends/SystemBackendProc.h" #include "Common/Logger.h" #include "Common/Backends/ConsoleLogger.h" @@ -27,6 +28,7 @@ #include "Common/RequestHandlers/StatusRequestHandler.h" #include "Daemon/Backends/NetworkLogger.h" #include "Daemon/Requests/IdentifyRequest.h" +#include "Daemon/RequestHandlers/CommandRequestHandler.h" #include <unistd.h> @@ -45,7 +47,10 @@ int main() { Common::RequestManager::init(false); Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>(Net::Packet::STATUS); + Common::RequestManager::getRequestManager()->registerPacketType<Daemon::RequestHandlers::CommandRequestHandler>(Net::Packet::COMMAND_REBOOT); + Common::RequestManager::getRequestManager()->registerPacketType<Daemon::RequestHandlers::CommandRequestHandler>(Net::Packet::COMMAND_SHUTDOWN); + Common::Backends::SystemBackendPosix::registerBackend(); Common::Backends::SystemBackendProc::registerBackend(); Net::ClientConnection *connection = new Net::ClientConnection; |