Move oops actions from log.c up to application
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.
This commit is contained in:
parent
6709931d51
commit
f55860670a
3 changed files with 24 additions and 24 deletions
|
@ -69,13 +69,6 @@
|
|||
#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));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue