/*******************************************************************************
* 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.
*******************************************************************************/
/*
* p4dctlerr.cc - definitions of errors for p4dctl
*/
# include <stdhdrs.h>
# include <error.h>
# include <errornum.h>
# include <strbuf.h>
# include "p4dctlerr.h"
//
// Error numbers are allocated like this:
//
// Fatal Errors: 001 - 200
// Failed Errors: 201 - 400
// Warnings: 401 - 600
// Info messages: 601 - 800
// Empty messages: 801 - 1000
//
// Maximum is 1023 as 10 bits are allocated.
//
// Fatal errors
// Failed command errors
ErrorId CtlErr::BadCommand = { ErrorOf( ES_SERVER, 201, E_FAILED, EV_USAGE, 1), "Unrecognised command: %cmd%." };
ErrorId CtlErr::MissingRequiredParm = { ErrorOf( ES_SERVER, 202, E_FAILED, EV_USAGE, 3), "Configuration for %name% %type% is missing required parameter %parm%." };
ErrorId CtlErr::ServerAccessDenied = { ErrorOf( ES_SERVER, 203, E_FAILED, EV_USAGE, 3), "Access to %type% %name% owned by %user% denied." };
ErrorId CtlErr::NoRootServers = { ErrorOf( ES_SERVER, 204, E_FAILED, EV_USAGE, 0), "Servers owned by root are not permitted." };
ErrorId CtlErr::ConfigParseError = { ErrorOf( ES_SERVER, 205, E_FAILED, EV_USAGE, 2), "Syntax error in %configFile% at line %lineNo%." };
ErrorId CtlErr::ChildKilled = { ErrorOf( ES_SERVER, 207, E_FAILED, EV_FAULT, 2), "Child process %pid% exited on signal %signal%." };
ErrorId CtlErr::ChildFailed = { ErrorOf( ES_SERVER, 208, E_FAILED, EV_FAULT, 4), "%name% %type%: '%cmd%' exited with status %status%." };
ErrorId CtlErr::ChildExecFail = { ErrorOf( ES_SERVER, 209, E_FAILED, EV_CONFIG, 1), "Failed to exec() %prog%." };
ErrorId CtlErr::SomeFailedStops = { ErrorOf( ES_SERVER, 210, E_FAILED, EV_FAULT, 0), "Not all servers stopped successfully." };
ErrorId CtlErr::SomeFailedStarts = { ErrorOf( ES_SERVER, 211, E_FAILED, EV_FAULT, 0), "Not all servers started successfully." };
ErrorId CtlErr::UnsafeConfig = { ErrorOf( ES_SERVER, 212, E_FAILED, EV_USAGE, 0), "Not safe to use configuration file or pid location from command line\n"
"\twhen running as root." };
ErrorId CtlErr::CheckpointFail = { ErrorOf( ES_SERVER, 213, E_FAILED, EV_FAULT, 1), "Checkpointing %name% server failed. This needs investigation!" };
ErrorId CtlErr::RotateFail = { ErrorOf( ES_SERVER, 214, E_FAILED, EV_FAULT, 1), "Journal rotation for %name% server failed. This needs investigation!" };
ErrorId CtlErr::MissingDir = { ErrorOf( ES_SERVER, 215, E_FAILED, EV_USAGE, 3), "Server %name% %type%: Directory '%dir%' does not exist." };
ErrorId CtlErr::NotDirectory = { ErrorOf( ES_SERVER, 216, E_FAILED, EV_USAGE, 3), "Server %name% %type%: '%dir%' is not a directory." };
ErrorId CtlErr::OwnerNotFound = { ErrorOf( ES_SERVER, 217, E_FAILED, EV_USAGE, 3), "Server %name% %type%: Owner '%owner%' not found." };
ErrorId CtlErr::DupeParm = { ErrorOf( ES_SERVER, 218, E_FAILED, EV_USAGE, 3), "Configuration for \"%name%\" %type% has a conflicting parameter \"%parm%\"." };
ErrorId CtlErr::DirPerms = { ErrorOf( ES_SERVER, 219, E_FAILED, EV_USAGE, 3), "Server %name% %type%: Directory '%dir%' does not appear to be writable." };
// Warnings
ErrorId CtlErr::SkippedServer = { ErrorOf( ES_SERVER, 401, E_WARN, EV_USAGE, 3), "Skipped %name% %type% owned by %owner%." };
ErrorId CtlErr::ServerNotRunning = { ErrorOf( ES_SERVER, 402, E_WARN, EV_USAGE, 2), "%name% %type% not running." };
ErrorId CtlErr::AlreadyRunning = { ErrorOf( ES_SERVER, 403, E_WARN, EV_USAGE, 2), "%name% %type% already running." };
ErrorId CtlErr::IgnoreDisabled = { ErrorOf( ES_SERVER, 404, E_WARN, EV_USAGE, 2), "%name% %type% disabled in config file. Ignored." };
ErrorId CtlErr::IgnoreNonExist = { ErrorOf( ES_SERVER, 405, E_WARN, EV_USAGE, 2), "%name% does not exist in config file. Ignored." };
ErrorId CtlErr::RunningErrors = { ErrorOf( ES_SERVER, 406, E_WARN, EV_USAGE, 3), "%name% %type% is running but not responding." };
// Informational messages
ErrorId CtlErr::StartedServer = { ErrorOf( ES_SERVER, 601, E_INFO, EV_USAGE, 2), "Started %name% %type%." };
ErrorId CtlErr::StartedServers = { ErrorOf( ES_SERVER, 602, E_INFO, EV_USAGE, 1), "Started %count% servers." };
ErrorId CtlErr::StoppedServer = { ErrorOf( ES_SERVER, 603, E_INFO, EV_USAGE, 2), "Stopped %name% %type% server." };
ErrorId CtlErr::StoppedServers = { ErrorOf( ES_SERVER, 604, E_INFO, EV_USAGE, 1), "Stopped %count% servers." };
ErrorId CtlErr::ServerRunning = { ErrorOf( ES_SERVER, 605, E_INFO, EV_USAGE, 2), "%name% %type% is running." };
ErrorId CtlErr::KillingServer = { ErrorOf( ES_SERVER, 606, E_INFO, EV_USAGE, 2), "Failed to stop %name% %type% using 'p4 admin stop'. Trying a SIGTERM..." };
ErrorId CtlErr::Checkpointing = { ErrorOf( ES_SERVER, 607, E_INFO, EV_USAGE, 1), "Checkpointing %name% server..." };
ErrorId CtlErr::JnlRotate = { ErrorOf( ES_SERVER, 608, E_INFO, EV_USAGE, 1), "Rotating journal for %name% server..." };
ErrorId CtlErr::NoServersConfigured = { ErrorOf( ES_SERVER, 609, E_INFO, EV_USAGE, 0), "No servers configured." };
ErrorId CtlErr::UsageMain = { ErrorOf( ES_SERVER, 650, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl [global flags] <cmd> [flags] [server name]\n"
"\n"
"Global Flags\n"
"------------\n"
"\n"
"-c <cfg_file> - Path to config file. Default: /etc/perforce/p4dctl.conf\n"
"-p <pid_dir> - Path to pid file directory. Default: /var/run\n"
"-q - Send output to syslog instead of stdout/stderr\n"
"-v <level> - Set debug level to <level> (1-9)\n"
"-V - Print version and exit\n"
"\n"
"Commands\n"
"--------\n"
"\n"
"list - List configured server(s)\n"
"start - Start the specified server(s)\n"
"stop - Stop the specified server(s)\n"
"restart - Restart the specified server(s)\n"
"status - Check the status of the specified server(s)\n"
"checkpoint - Checkpoint the specified p4d server(s)\n"
"journal - Rotate p4d server(s) journal file\n"
"env - Query the environment of servers\n"
"\n"
};
ErrorId CtlErr::UsageStart = { ErrorOf( ES_SERVER, 651, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl start [-t <type>] [-o <options>] <server name>\n"
" p4dctl start [-t <type>] [-o <options>] -a\n"
"\n"
"Without the -a flag, starts a specific server; with the -a flag, starts\n"
"all configured servers that the running user has permission to start.\n"
"\n"
"If the -t flag is specified, then only servers of the specified type\n"
"will be started.\n"
"\n"
"If the -o flag is specified, then the specified option is appended to the\n"
"arguments passed to the service on start. The option must be quoted if it\n"
"consists of multiple arguments.\n"
"\n"
};
ErrorId CtlErr::UsageStop = { ErrorOf( ES_SERVER, 652, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl stop [-t <type>] <server name>\n"
" p4dctl stop [-t <type>] -a\n"
"\n"
"Without the -a flag, stops a specific server; with the -a flag, stops\n"
"all configured servers that the running user has permission to stop.\n"
"\n"
"If the -t flag is specified, then only servers of the specified type\n"
"will be stopped.\n"
"\n"
};
ErrorId CtlErr::UsageRestart = { ErrorOf( ES_SERVER, 653, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl restart [-t <type>] [-o <options>] <server name>\n"
" p4dctl restart [-t <type>] [-o <options>] -a\n"
"\n"
"Without the -a flag, restarts a specific server; with the -a flag, restarts\n"
"all configured servers that the running user has permission to restart.\n"
"\n"
"If the -t flag is specified, then only servers of the specified type\n"
"will be restarted.\n"
"\n"
"If the -o flag is specified, then the specified option is appended to the\n"
"arguments passed to the service on start. The option must be quoted if it\n"
"consists of multiple arguments.\n"
"\n"
};
ErrorId CtlErr::UsageStatus = { ErrorOf( ES_SERVER, 654, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl status [-t <type>] <server name>\n"
" p4dctl status [-t <type>] -a\n"
"\n"
"Without the -a flag, checks a specific server; with the -a flag, checks\n"
"all configured servers that the running user has permission to check.\n"
"\n"
"If the -t flag is specified, then only servers of the specified type\n"
"will be checked.\n"
"\n"
};
ErrorId CtlErr::UsageCheckpoint = { ErrorOf( ES_SERVER, 655, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl checkpoint <server name>\n"
" p4dctl checkpoint -a\n"
"\n"
"Without the -a flag, checkpoints a specific p4d server; with the -a flag,\n"
"checkpoints all configured p4d servers that the running user has permission\n"
"to checkpoint.\n"
"\n"
};
ErrorId CtlErr::UsageJournal = { ErrorOf( ES_SERVER, 656, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl journal <server name>\n"
" p4dctl journal -a\n"
"\n"
"Without the -a flag, rotates the journal of a specific p4d server; with the\n"
"-a flag, rotates the journals of all configured p4d servers that the running\n"
"user has permission to administer.\n"
"\n"
};
ErrorId CtlErr::UsageList = { ErrorOf( ES_SERVER, 657, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl list [-t <type>]\n"
"\n"
"Lists all configured servers of the specified type. If <type> is not\n"
"specified, lists all servers of all types that the running user has\n"
"permission to administer.\n"
"\n"
};
ErrorId CtlErr::UsageEnv = { ErrorOf( ES_SERVER, 658, E_INFO, EV_USAGE, 0),
"\n"
"Usage: p4dctl env [-a | <name>] [-t <type>] <var> ...\n"
"\n"
"Prints the values of variables <var> for each of the servers\n"
"matching either the specified <name> or <type> (or all servers\n"
"if -a is supplied) provided that the user has permission to access\n"
"them.\n"
"\n"
};