/******************************************************************************* * * Copyright (c) 2007, Perforce Software, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************/ #ifndef EXECUTABLE_H_ #define EXECUTABLE_H_ #include <string> #include <map> #include <vector> #include "VariableHolder.h" #include "exceptions.h" class Configuration; // forward typedef std::map<std::string, std::string> env_map; typedef std::vector<std::string> arg_vec; class Executable : public VariableHolder { protected: typedef std::vector<std::string> arg_vec; typedef void (Executable::*cmd_func)(); typedef std::map<std::string, cmd_func> cmd_map; protected: std::string _name; std::string _type; std::string _user; std::string _executable; std::string _client; std::string _port; pid_t _pid; Configuration * _configuration; env_map _variables; bool _verbose; static cmd_map CommandMap; static bool initializeCommandMap(); public: Executable(const std::string& name, const std::string& type, Configuration * config); virtual ~Executable(); public: void addVariable(const std::string& name, const std::string& value); virtual void verifyVariables() throw(VerificationException) = 0; const std::string& getName() const { return _name; } const std::string& getExecutable() const { return _executable; } const std::string& getUser() const { return _user; } const std::string& getType() const { return _type; } void setUser(const std::string& user) { _user = user; } void setExecutable(const std::string& exec) { _executable = exec; } void setClient(const std::string& client) { _client = client; } void setPort(const std::string& port) { _port = port; } int executeCommand(const std::string& command); virtual void print(std::ostream& str) const; protected: cmd_func parseCommand(const std::string& command); virtual void startServer(); virtual void stopServer(); virtual void restartServer(); virtual void statusServer(); virtual void checkpointServer(); virtual void rotateJournalServer(); void prepareEnv(arg_vec& vec); virtual void prepareArgs(arg_vec& args) = 0; virtual void changeUser(); void addUserEnvironment(const std::string& name, const std::string& value); void addOption(const char * name, const char * option, arg_vec& args); void storePid(pid_t pid); void removePid(); bool isServerRunning(); std::string createRunName() const; char ** makeCharArray(Executable::arg_vec& vec); }; std::ostream& operator<<(std::ostream& str, const Executable& exec); #endif /*EXECUTABLE_H_*/
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 8039 | Sven Erik Knop |
P4FTPD is allowed to run as root. This also fixes an overloaded method that could cause confusion in the code. |
||
#2 | 5987 | Sven Erik Knop |
Few minor changes: All commands now accept variable called "Options". This can be used to collect all options for which Perforce has not defined an environment variable - for example the undocumented "-C1" for p4d to start a case insensitive server. p4d also accepts the variables P4USER and P4PASSWD. These are only used for stopping the service, which is done first via "p4 admin stop". Note that if the stop via the admin command fails, p4dcfg will stop the service via a kill |
||
#1 | 5882 | Sven Erik Knop | initial publish |