]> git.pond.sub.org Git - empserver/commitdiff
Move oops actions from log.c up to application
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 25 Apr 2008 18:20:07 +0000 (20:20 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 25 Apr 2008 20:06:13 +0000 (22:06 +0200)
Change oops() to call the new oops_handler function pointer instead of
offering a fixed set of actions.  Change server's main() to install a
handler for the action requested by -E.

include/misc.h
src/lib/gen/log.c
src/server/main.c

index 2bf4c082583304643352ee3d2327c7d862ebae8b..224e6c2a487f216a73f826f8dfd519c7f5e39041 100644 (file)
 #define hours(x)       (60*60*(x))
 #define days(x)                (60*60*24*(x))
 
-enum oops_action {
-    OOPS_ABORT,
-    OOPS_CRASH_DUMP,
-    OOPS_NOTHING
-};
-extern enum oops_action oops_action;
-
 /*
  * If EXPR is true, an internal error occured.
  * Return EXPR != 0.
@@ -90,6 +83,7 @@ extern enum oops_action oops_action;
 #define CANT_REACH() (void)oops(NULL, __FILE__, __LINE__)
 
 extern int oops(char *, char *, int);
+extern void (*oops_handler)(void);
 
 void exit_nomem(void) ATTRIBUTE((noreturn));
 
index 6cdca129cb2a8ac6b5b7621578e8dc9031b9dea6..1c78f2efda24a7dd8f99df6375f4858c470e3db3 100644 (file)
@@ -46,7 +46,7 @@
 #include "player.h"
 #include "prototypes.h"
 
-enum oops_action oops_action = OOPS_ABORT;
+void (*oops_handler)(void) = abort;
 
 static char logfile[32];
 static int logfd = -1;
@@ -126,24 +126,14 @@ logerror(char *format, ...)
 
 /*
  * Log internal error MSG occured in FILE:LINE.
- * If debugging, call abort(), else return 1.
+ * Call oops handler, and if it returns, return 1.
+ * Oops handler defaults to abort().
  */
 int
 oops(char *msg, char *file, int line)
 {
     logerror("Oops: %s in %s:%d", msg ? msg : "bug", file, line);
-    switch (oops_action) {
-    case OOPS_ABORT:
-       abort();
-    case OOPS_CRASH_DUMP:
-#ifndef _WIN32
-       if (fork() == 0)
-           abort();
-#endif
-       /* fall through */
-    case OOPS_NOTHING:
-       break;
-    }
+    oops_handler();
     return 1;
 }
 
index 34409820c8c410a0d6de3f6ee4f5a6d563a16c17..cd9de4fd774edf83d912974e690351b823f3f724 100644 (file)
@@ -68,6 +68,8 @@
 #include "ship.h"
 #include "version.h"
 
+static void ignore(void);
+static void crash_dump(void);
 static void create_pidfile(char *, pid_t);
 
 #if defined(_WIN32)
@@ -133,6 +135,7 @@ int
 main(int argc, char **argv)
 {
     static char *oops_key[] = { "abort", "crash-dump", "nothing", NULL };
+    static void (*oops_hndlr[])(void) = { abort, crash_dump, ignore };
     int flags = 0;
 #if defined(_WIN32)
     int install_service_set = 0;
@@ -144,7 +147,7 @@ main(int argc, char **argv)
     int op, idx, sig;
     unsigned seed = time(NULL);
 
-    oops_action = OOPS_NOTHING;
+    oops_handler = ignore;
 
 #ifdef _WIN32
 # define XOPTS "iI:uU:"
@@ -157,7 +160,7 @@ main(int argc, char **argv)
            flags |= EMPTH_PRINT;
            /* fall through */
        case 'd':
-           oops_action = OOPS_ABORT;
+           oops_handler = abort;
            daemonize = 0;
            break;
        case 'e':
@@ -169,7 +172,7 @@ main(int argc, char **argv)
                help(argv[0], "invalid argument for -E");
                return EXIT_FAILURE;
            }
-           oops_action = idx;
+           oops_handler = oops_hndlr[idx];
            break;
 #if defined(_WIN32)
        case 'I':
@@ -304,6 +307,19 @@ main(int argc, char **argv)
     return EXIT_SUCCESS;
 }
 
+static void
+ignore(void)
+{
+}
+
+static void
+crash_dump(void)
+{
+#ifndef _WIN32
+    if (fork() == 0)
+       abort();
+#endif
+}
 
 /*
  * Initialize for serving, acquire resources.