Change MSGHANDLER from compile-time to sysconf

This commit is contained in:
Pasi Kallinen
2024-10-19 10:47:53 +03:00
parent d35aa35c3f
commit 696af89299
11 changed files with 39 additions and 29 deletions

View File

@@ -173,6 +173,7 @@ staticfn boolean cnf_line_catname(char *);
#ifdef SYSCF
staticfn boolean cnf_line_WIZARDS(char *);
staticfn boolean cnf_line_SHELLERS(char *);
staticfn boolean cnf_line_MSGHANDLER(char *);
staticfn boolean cnf_line_EXPLORERS(char *);
staticfn boolean cnf_line_DEBUGFILES(char *);
staticfn boolean cnf_line_DUMPLOGFILE(char *);
@@ -2756,6 +2757,15 @@ cnf_line_SHELLERS(char *bufp)
return TRUE;
}
staticfn boolean
cnf_line_MSGHANDLER(char *bufp)
{
if (sysopt.msghandler)
free((genericptr_t) sysopt.msghandler);
sysopt.msghandler = dupstr(bufp);
return TRUE;
}
staticfn boolean
cnf_line_EXPLORERS(char *bufp)
{
@@ -3272,6 +3282,7 @@ static const struct match_config_line_stmt {
#ifdef SYSCF
CNFL_S(WIZARDS, 7),
CNFL_S(SHELLERS, 8),
CNFL_S(MSGHANDLER, 9),
CNFL_S(EXPLORERS, 7),
CNFL_S(DEBUGFILES, 5),
CNFL_S(DUMPLOGFILE, 7),

View File

@@ -478,9 +478,6 @@ static const char *const build_opts[] = {
#ifdef HOLD_LOCKFILE_OPEN
"exclusive lock on level 0 file",
#endif
#ifdef MSGHANDLER
"external program as a message handler",
#endif
#if defined(HANGUPHANDLING) && !defined(NO_SIGNAL)
#ifdef SAFERHANGUP
"deferred handling of hangup signal",

View File

@@ -11,9 +11,7 @@
staticfn void putmesg(const char *);
staticfn char *You_buf(int);
#if defined(MSGHANDLER)
staticfn void execplinehandler(const char *);
#endif
#ifdef USER_SOUNDS
extern void maybe_play_sound(const char *);
#endif
@@ -262,9 +260,7 @@ vpline(const char *line, va_list the_args)
putmesg(line);
#if defined(MSGHANDLER)
execplinehandler(line);
#endif
/* this gets cleared after every pline message */
iflags.last_msg = PLNMSG_UNKNOWN;
@@ -564,9 +560,7 @@ vraw_printf(const char *line, va_list the_args)
pbuf[BUFSZ - 1] = '\0'; /* terminate strncpy or truncate vsprintf */
}
raw_print(line);
#if defined(MSGHANDLER)
execplinehandler(line);
#endif
if (!program_state.beyond_savefile_load)
ge.early_raw_messages++;
}
@@ -626,7 +620,6 @@ impossible(const char *s, ...)
RESTORE_WARNING_FORMAT_NONLITERAL
#if defined(MSGHANDLER)
static boolean use_pline_handler = TRUE;
staticfn void
@@ -636,27 +629,21 @@ execplinehandler(const char *line)
int f;
#endif
const char *args[3];
char *env;
if (!use_pline_handler)
if (!use_pline_handler || !sysopt.msghandler)
return;
if (!(env = nh_getenv("NETHACK_MSGHANDLER"))) {
use_pline_handler = FALSE;
return;
}
#if defined(POSIX_TYPES) || defined(__GNUC__)
f = fork();
if (f == 0) { /* child */
args[0] = env;
args[0] = sysopt.msghandler;
args[1] = line;
args[2] = NULL;
(void) setgid(getgid());
(void) setuid(getuid());
(void) execv(args[0], (char *const *) args);
perror((char *) 0);
(void) fprintf(stderr, "Exec to message handler %s failed.\n", env);
(void) fprintf(stderr, "Exec to message handler %s failed.\n", sysopt.msghandler);
nh_terminate(EXIT_FAILURE);
} else if (f > 0) {
int status;
@@ -670,16 +657,15 @@ execplinehandler(const char *line)
#elif defined(WIN32)
{
intptr_t ret;
args[0] = env;
args[0] = sysopt.msghandler;
args[1] = line;
args[2] = NULL;
ret = _spawnv(_P_NOWAIT, env, args);
ret = _spawnv(_P_NOWAIT, sysopt.msghandler, args);
}
#else
#error MSGHANDLER is not implemented on this system.
use_pline_handler = FALSE;
#endif
}
#endif /* MSGHANDLER */
/*
* varargs handling for files.c

View File

@@ -48,6 +48,7 @@ sys_early_init(void)
sysopt.shellers = (char *) 0;
sysopt.explorers = (char *) 0;
sysopt.genericusers = (char *) 0;
sysopt.msghandler = (char *) 0;
sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */
sysopt.bones_pools = 0;
sysopt.livelog = LL_NONE;
@@ -115,6 +116,8 @@ sysopt_release(void)
free((genericptr_t) sysopt.debugfiles),
sysopt.debugfiles = (char *) 0;
sysopt.env_dbgfl = 0;
if (sysopt.msghandler)
free((genericptr_t) sysopt.msghandler), sysopt.msghandler = (char *) 0;
#ifdef DUMPLOG
if (sysopt.dumplogfile)
free((genericptr_t) sysopt.dumplogfile), sysopt.dumplogfile=(char *) 0;