turn on and off debug at runtime

This commit is contained in:
joonicks 2025-10-24 16:17:34 +02:00
parent 3da107f0e4
commit c95778523a
3 changed files with 37 additions and 1 deletions

View File

@ -1447,6 +1447,41 @@ int wrap_debug(void)
void do_debug(COMMAND_ARGS)
{
const char *arg;
int m;
arg = chop(&rest);
if (strcasecmp(arg,"off") == 0)
{
if (debugfile && debugfilemalloc == TRUE)
Free(&debugfile);
debugfilemalloc = FALSE;
debugfile = NULL;
dodebug = FALSE;
to_user(from,"Debug output turned off");
return;
}
if (strcasecmp(arg,"on") == 0)
{
m = is_safepath(rest,FILE_MAY_EXIST);
debug("(do_debug) turn on, rest = '%s', %i\n",rest,m);
if (*rest && m == FILE_IS_SAFE)
{
if (debugfile && debugfilemalloc == TRUE)
Free(&debugfile);
debugfilemalloc = TRUE;
set_mallocdoer(do_debug);
debugfile = strdup(rest);
dodebug = TRUE;
to_user(from,"Debug output turned on, Output = %s",rest);
}
else
{
to_user(from,"debug: Unsafe filename");
}
return;
}
if (wrap_debug())
to_user(from,"Debug information has been written to file");
else

View File

@ -184,6 +184,7 @@ BEG time_t ctcp_slot[CTCP_SLOTS];
BEG char debugbuf[MAXLEN];
BEG char *debugfile MDEF(NULL);
BEG int debugfilemalloc MDEF(FALSE);
BEG int dodebug MDEF(FALSE);
BEG int debug_fd MDEF(-1);
BEG int debug_on_exit MDEF(FALSE);

View File

@ -1,7 +1,7 @@
/*
EnergyMech, IRC bot software
Parts Copyright (c) 1997-2018 proton
Parts Copyright (c) 1997-2025 proton
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by