From c95778523a5324cc43349a2269d6cd0d43f5590a Mon Sep 17 00:00:00 2001 From: joonicks Date: Fri, 24 Oct 2025 16:17:34 +0200 Subject: [PATCH] turn on and off debug at runtime --- src/debug.c | 35 +++++++++++++++++++++++++++++++++++ src/global.h | 1 + src/main.c | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/debug.c b/src/debug.c index 899900b..6e4c440 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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 diff --git a/src/global.h b/src/global.h index 8f853d5..5bf1f30 100644 --- a/src/global.h +++ b/src/global.h @@ -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); diff --git a/src/main.c b/src/main.c index 2d885b4..1bc9573 100755 --- a/src/main.c +++ b/src/main.c @@ -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