refactor: Common.h replace anon enum with set constexpr exit codes
This commit is contained in:
committed by
Chris Rizzitello
parent
29e9b8ae3b
commit
9905f32738
@ -97,10 +97,10 @@ int main(int argc, char **argv)
|
||||
|
||||
if (parser.isSet(installOption)) {
|
||||
daemon.install();
|
||||
return kExitSuccess;
|
||||
return s_exitSuccess;
|
||||
} else if (parser.isSet(uninstallOption)) {
|
||||
daemon.uninstall();
|
||||
return kExitSuccess;
|
||||
return s_exitSuccess;
|
||||
}
|
||||
|
||||
const auto ipcServer =
|
||||
@ -120,10 +120,10 @@ int main(int argc, char **argv)
|
||||
|
||||
} catch (std::exception &e) {
|
||||
handleError(e.what());
|
||||
return kExitFailed;
|
||||
return s_exitFailed;
|
||||
} catch (...) {
|
||||
handleError();
|
||||
return kExitFailed;
|
||||
return s_exitFailed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -33,11 +33,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
kExitSuccess = 0, // successful completion
|
||||
kExitFailed = 1, // general failure
|
||||
kExitTerminated = 2, // killed by signal
|
||||
kExitArgs = 3, // bad arguments
|
||||
kExitConfig = 4, // cannot read configuration
|
||||
};
|
||||
static const int s_exitSuccess = 0; //!< App successfully completed
|
||||
static const int s_exitFailed = 1; //!< App had a general failure
|
||||
static const int s_exitTerminated = 2; //!< App was kill by a signal
|
||||
static const int s_exitArgs = 3; //!< App was unable to run due to bad arguments being passed
|
||||
static const int s_exitConfig = 4; //!< App was unable to read the configuration
|
||||
|
||||
@ -87,7 +87,7 @@ int App::run(int argc, char **argv)
|
||||
appUtil().adoptApp(this);
|
||||
|
||||
// HACK: fail by default (saves us setting result in each catch)
|
||||
int result = kExitFailed;
|
||||
int result = s_exitFailed;
|
||||
|
||||
try {
|
||||
result = appUtil().run(argc, argv);
|
||||
@ -172,7 +172,7 @@ void App::initApp(int argc, const char **argv)
|
||||
LOG((
|
||||
CLOG_CRIT "%s: unrecognized log level `%s'" BYE, argsBase().m_pname, argsBase().m_logFilter, argsBase().m_pname
|
||||
));
|
||||
m_bye(kExitArgs);
|
||||
m_bye(s_exitArgs);
|
||||
}
|
||||
loggingFilterWarning();
|
||||
|
||||
|
||||
@ -72,9 +72,9 @@ void ClientApp::parseArgs(int argc, const char *const *argv)
|
||||
|
||||
if (!result || args().m_shouldExitOk || args().m_shouldExitFail) {
|
||||
if (args().m_shouldExitOk) {
|
||||
m_bye(kExitSuccess);
|
||||
m_bye(s_exitSuccess);
|
||||
} else {
|
||||
m_bye(kExitArgs);
|
||||
m_bye(s_exitArgs);
|
||||
}
|
||||
} else {
|
||||
// save server address
|
||||
@ -89,7 +89,7 @@ void ClientApp::parseArgs(int argc, const char *const *argv)
|
||||
// Priddy.
|
||||
if (!args().m_restartable || e.getError() == XSocketAddress::kBadPort) {
|
||||
LOG((CLOG_CRIT "%s: %s" BYE, args().m_pname, e.what(), args().m_pname));
|
||||
m_bye(kExitFailed);
|
||||
m_bye(s_exitFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -417,7 +417,7 @@ int ClientApp::mainLoop()
|
||||
updateStatus();
|
||||
LOG((CLOG_NOTE "stopped client"));
|
||||
|
||||
return kExitSuccess;
|
||||
return s_exitSuccess;
|
||||
}
|
||||
|
||||
static int daemonMainLoopStatic(int argc, const char **argv)
|
||||
@ -462,7 +462,7 @@ void ClientApp::startNode()
|
||||
// we shouldn't retry.
|
||||
LOG((CLOG_DEBUG1 "starting client"));
|
||||
if (!startClient()) {
|
||||
m_bye(kExitFailed);
|
||||
m_bye(s_exitFailed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -196,7 +196,7 @@ int DaemonApp::mainLoop()
|
||||
#if SYSAPI_WIN32
|
||||
if (m_pWatchdog == nullptr) {
|
||||
LOG_ERR("watchdog not initialized");
|
||||
return kExitFailed;
|
||||
return s_exitFailed;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -235,7 +235,7 @@ int DaemonApp::mainLoop()
|
||||
#endif
|
||||
|
||||
DAEMON_RUNNING(false);
|
||||
return kExitSuccess;
|
||||
return s_exitSuccess;
|
||||
}
|
||||
|
||||
QString DaemonApp::logFilename()
|
||||
|
||||
@ -80,9 +80,9 @@ void ServerApp::parseArgs(int argc, const char *const *argv)
|
||||
|
||||
if (!result || args().m_shouldExitOk || args().m_shouldExitFail) {
|
||||
if (args().m_shouldExitOk) {
|
||||
m_bye(kExitSuccess);
|
||||
m_bye(s_exitSuccess);
|
||||
} else {
|
||||
m_bye(kExitArgs);
|
||||
m_bye(s_exitArgs);
|
||||
}
|
||||
} else {
|
||||
if (!args().m_deskflowAddress.empty()) {
|
||||
@ -91,7 +91,7 @@ void ServerApp::parseArgs(int argc, const char *const *argv)
|
||||
m_deskflowAddress->resolve();
|
||||
} catch (XSocketAddress &e) {
|
||||
LOG((CLOG_CRIT "%s: %s" BYE, args().m_pname, e.what(), args().m_pname));
|
||||
m_bye(kExitArgs);
|
||||
m_bye(s_exitArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,12 +162,12 @@ void ServerApp::loadConfig()
|
||||
const auto path = args().m_configFile;
|
||||
if (path.empty()) {
|
||||
LOG((CLOG_CRIT "no configuration path provided"));
|
||||
m_bye(kExitConfig);
|
||||
m_bye(s_exitConfig);
|
||||
}
|
||||
|
||||
if (!loadConfig(path)) {
|
||||
LOG((CLOG_CRIT "%s: failed to load config: %s", args().m_pname, path.c_str()));
|
||||
m_bye(kExitConfig);
|
||||
m_bye(s_exitConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@ -609,7 +609,7 @@ int ServerApp::mainLoop()
|
||||
// canonicalize the primary screen name
|
||||
if (std::string primaryName = args().m_config->getCanonicalName(args().m_name); primaryName.empty()) {
|
||||
LOG((CLOG_CRIT "unknown screen name `%s'", args().m_name.c_str()));
|
||||
return kExitFailed;
|
||||
return s_exitFailed;
|
||||
}
|
||||
|
||||
// start server, etc
|
||||
@ -661,7 +661,7 @@ int ServerApp::mainLoop()
|
||||
updateStatus();
|
||||
LOG((CLOG_NOTE "stopped server"));
|
||||
|
||||
return kExitSuccess;
|
||||
return s_exitSuccess;
|
||||
}
|
||||
|
||||
void ServerApp::resetServer()
|
||||
@ -735,6 +735,6 @@ void ServerApp::startNode()
|
||||
// we shouldn't retry.
|
||||
LOG((CLOG_DEBUG1 "starting server"));
|
||||
if (!startServer()) {
|
||||
m_bye(kExitFailed);
|
||||
m_bye(s_exitFailed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ void MSWindowsProcess::shutdown(HANDLE handle, DWORD pid, int timeout)
|
||||
}
|
||||
|
||||
// Last resort, terminate the process forcefully.
|
||||
if (TerminateProcess(handle, kExitSuccess)) {
|
||||
if (TerminateProcess(handle, s_exitSuccess)) {
|
||||
LOG_WARN("forcefully terminated process %d", pid);
|
||||
} else {
|
||||
LOG_ERR("failed to terminate process %d, error: %s", pid, windowsErrorToString(GetLastError()).c_str());
|
||||
|
||||
Reference in New Issue
Block a user