Skip to content

Commit

Permalink
Also use binary exit codes in places that terminate abruptly.
Browse files Browse the repository at this point in the history
This is a partial reversion of commit 57330e9.
  • Loading branch information
SadieCat committed Jul 19, 2022
1 parent f3fa07f commit 42b1429
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 8 additions & 0 deletions include/inspircd.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ class CoreExport InspIRCd
*/
void Exit(int status);

/** Causes the server to exit immediately.
*
* @param status The exit code to give to the operating system
* (See the ExitStatus enum for valid values)
*/
static void QuickExit(int status);


/** Formats the input string with the specified arguments.
* @param formatString The string to format
* @param ... A variable number of format arguments.
Expand Down
14 changes: 7 additions & 7 deletions src/inspircd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,20 @@ namespace
if (setgroups(0, NULL) == -1)
{
ServerInstance->Logs->Log("STARTUP", LOG_DEFAULT, "setgroups() failed (wtf?): %s", strerror(errno));
exit(EXIT_STATUS_CONFIG);
InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}

struct group* g = getgrnam(SetGroup.c_str());
if (!g)
{
ServerInstance->Logs->Log("STARTUP", LOG_DEFAULT, "getgrnam(%s) failed (wrong group?): %s", SetGroup.c_str(), strerror(errno));
exit(EXIT_STATUS_CONFIG);
InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}

if (setgid(g->gr_gid) == -1)
{
ServerInstance->Logs->Log("STARTUP", LOG_DEFAULT, "setgid(%d) failed (wrong group?): %s", g->gr_gid, strerror(errno));
exit(EXIT_STATUS_CONFIG);
InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}
}

Expand All @@ -192,13 +192,13 @@ namespace
if (!u)
{
ServerInstance->Logs->Log("STARTUP", LOG_DEFAULT, "getpwnam(%s) failed (wrong user?): %s", SetUser.c_str(), strerror(errno));
exit(EXIT_STATUS_CONFIG);
InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}

if (setuid(u->pw_uid) == -1)
{
ServerInstance->Logs->Log("STARTUP", LOG_DEFAULT, "setuid(%d) failed (wrong user?): %s", u->pw_uid, strerror(errno));
exit(EXIT_STATUS_CONFIG);
InspIRCd::QuickExit(EXIT_STATUS_CONFIG);
}
}
#endif
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace
// happened and the parent should exit.
while (kill(childpid, 0) != -1)
sleep(1);
exit(EXIT_STATUS_NOERROR);
InspIRCd::QuickExit(EXIT_STATUS_NOERROR);
}
else
{
Expand Down Expand Up @@ -399,7 +399,7 @@ namespace
// Required for returning the proper value of EXIT_SUCCESS for the parent process.
void VoidSignalHandler(int)
{
exit(EXIT_STATUS_NOERROR);
InspIRCd::QuickExit(EXIT_STATUS_NOERROR);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ void InspIRCd::Exit(int status)
this->Cleanup();
ServerInstance = NULL;
delete this;
QuickExit(status);
}

void InspIRCd::QuickExit(int status)
{
#ifdef INSPIRCD_BINARY_EXIT
// Some init systems handle non-binary exit statuses weirdly.
exit(status ? EXIT_FAILURE : EXIT_SUCCESS);
Expand Down
2 changes: 1 addition & 1 deletion src/socketengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void EventHandler::OnEventHandlerError(int errornum)
void SocketEngine::InitError()
{
std::cerr << con_red << "FATAL ERROR!" << con_reset << " Socket engine initialization failed. " << strerror(errno) << '.' << std::endl;
exit(EXIT_STATUS_SOCKETENGINE);
InspIRCd::QuickExit(EXIT_STATUS_SOCKETENGINE);
}

void SocketEngine::LookupMaxFds()
Expand Down

0 comments on commit 42b1429

Please sign in to comment.