summaryrefslogtreecommitdiff
path: root/src/mmo/core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mmo/core.cpp')
-rw-r--r--src/mmo/core.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/mmo/core.cpp b/src/mmo/core.cpp
index 68b7823..f1a8d07 100644
--- a/src/mmo/core.cpp
+++ b/src/mmo/core.cpp
@@ -22,23 +22,26 @@
#include <sys/wait.h>
-#include <unistd.h>
+#include <alloca.h>
#include <csignal>
#include <cstdlib>
-#include <ctime>
-#include "../strings/zstring.hpp"
+#include <tmwa/shared.hpp>
-#include "../generic/random.hpp"
+#include "../strings/zstring.hpp"
+#include "../strings/literal.hpp"
#include "../io/cxxstdio.hpp"
-#include "socket.hpp"
-#include "timer.hpp"
+#include "../net/socket.hpp"
+#include "../net/timer.hpp"
#include "../poison.hpp"
+
+namespace tmwa
+{
// Added by Gabuzomeu
//
// This is an implementation of signal() using sigaction() for portability.
@@ -61,10 +64,12 @@ sigfunc compat_signal(int signo, sigfunc func)
sact.sa_flags = 0;
if (sigaction(signo, &sact, &oact) < 0)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wold-style-cast"
+ {
+ DIAG_PUSH();
+ DIAG_I(old_style_cast);
return SIG_ERR;
-#pragma GCC diagnostic pop
+ DIAG_POP();
+ }
return oact.sa_handler;
}
@@ -75,16 +80,18 @@ bool runflag = true;
static
void chld_proc(int)
{
- wait(NULL);
+ wait(nullptr);
}
static
void sig_proc(int)
{
for (int i = 1; i < 31; ++i)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wold-style-cast"
+ {
+ DIAG_PUSH();
+ DIAG_I(old_style_cast);
compat_signal(i, SIG_IGN);
-#pragma GCC diagnostic pop
+ DIAG_POP();
+ }
runflag = false;
}
@@ -97,8 +104,14 @@ void sig_proc(int)
Unless you use SA_SIGINFO and *carefully* check the origin,
that means they must be SIG_DFL.
*/
+} // namespace tmwa
+
int main(int argc, char **argv)
{
+ using namespace tmwa;
+
+ check_paths();
+
// ZString args[argc]; is (deliberately!) not supported by clang yet
ZString *args = static_cast<ZString *>(alloca(argc * sizeof(ZString)));
for (int i = 0; i < argc; ++i)
@@ -107,29 +120,30 @@ int main(int argc, char **argv)
if (!runflag)
{
- PRINTF("Fatal error during startup; exiting\n");
+ PRINTF("Fatal error during startup; exiting\n"_fmt);
return 1;
}
// set up exit handlers *after* the initialization has happened.
// This is because term_func is likely to depend on successful init.
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wold-style-cast"
+ DIAG_PUSH();
+ DIAG_I(old_style_cast);
compat_signal(SIGPIPE, SIG_IGN);
-#pragma GCC diagnostic pop
+ DIAG_POP();
compat_signal(SIGTERM, sig_proc);
compat_signal(SIGINT, sig_proc);
compat_signal(SIGCHLD, chld_proc);
// Signal to create coredumps by system when necessary (crash)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wold-style-cast"
+ DIAG_PUSH();
+ DIAG_I(old_style_cast);
+ DIAG_I(zero_as_null_pointer_constant);
compat_signal(SIGSEGV, SIG_DFL);
compat_signal(SIGBUS, SIG_DFL);
compat_signal(SIGTRAP, SIG_DFL);
compat_signal(SIGILL, SIG_DFL);
compat_signal(SIGFPE, SIG_DFL);
-#pragma GCC diagnostic pop
+ DIAG_POP();
atexit(term_func);