예제 #1
0
파일: cli.cpp 프로젝트: direvius/porto
int TCommandHandler::TryExec(const std::string &commandName,
                             const std::vector<std::string> &commandArgs) {
    const auto it = Commands.find(commandName);
    if (it == Commands.end()) {
        std::cerr << "Invalid command " << commandName << "!" << std::endl;
        return EXIT_FAILURE;
    }

    ICmd *cmd = it->second.get();
    PORTO_ASSERT(cmd);
    if (!cmd->ValidArgs(commandArgs)) {
        Usage(cmd->GetName().c_str());
        return EXIT_FAILURE;
    }

    CurrentCmd = cmd;

    // in case client closes pipe we are writing to in the protobuf code
    (void)RegisterSignal(SIGPIPE, SIG_IGN);
    (void)RegisterSignal(SIGINT, SigInt);
    (void)RegisterSignal(SIGTERM, SigInt);

    TCommandEnviroment commandEnv{*this, commandArgs};
    int ret = cmd->Execute(&commandEnv);
    if (cmd->GotSignal())
        return -cmd->InterruptedSignal;
    else
        return ret;
}
예제 #2
0
파일: cli.cpp 프로젝트: presto53/porto
static int TryExec(int argc, char *argv[]) {
    string name(argv[1]);

    if (commands.find(name) == commands.end()) {
        std::cerr << "Invalid command " << name << "!" << std::endl;
        return EXIT_FAILURE;
    }

    ICmd *cmd = commands[name];
    if (!cmd->ValidArgs(argc - 2, argv + 2)) {
        Usage(cmd->GetName().c_str());
        return EXIT_FAILURE;
    }

    CurrentCmd = cmd;

    // in case client closes pipe we are writing to in the protobuf code
    (void)RegisterSignal(SIGPIPE, SIG_IGN);
    (void)RegisterSignal(SIGINT, SigInt);
    (void)RegisterSignal(SIGTERM, SigInt);

    int ret = cmd->Execute(argc - 2, argv + 2);
    if (cmd->GotSignal())
        return -cmd->InterruptedSignal;
    else
        return ret;
}
예제 #3
0
파일: cli.cpp 프로젝트: noxiouz/porto
int TCommandHandler::TryExec(const std::string &commandName,
                             const std::vector<std::string> &commandArgs) {
    const auto it = Commands.find(commandName);
    if (it == Commands.end()) {
        std::cerr << "Invalid command " << commandName << "!" << std::endl;
        return EXIT_FAILURE;
    }

    ICmd *cmd = it->second.get();
    PORTO_ASSERT(cmd);
    if (!cmd->ValidArgs(commandArgs)) {
        Usage(cmd->GetName().c_str());
        return EXIT_FAILURE;
    }

    // in case client closes pipe we are writing to in the protobuf code
    Signal(SIGPIPE, SIG_IGN);

    TCommandEnviroment commandEnv{*this, commandArgs};
    commandEnv.NeedArgs = cmd->NeedArgs;
    return cmd->Execute(&commandEnv);
}