From 2debc2e833836c99710553837e30210009818ed7 Mon Sep 17 00:00:00 2001 From: Katherine Peeters Date: Sat, 29 Oct 2022 21:33:18 -0700 Subject: Split NoSyslog from behaviour of NoDaemon Allows syslog to be enabled/disabled seperately from daemonization --- src/ngircd/log.c | 10 +++++----- src/ngircd/log.h | 2 +- src/ngircd/ngircd.c | 6 ++++-- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ngircd/log.c b/src/ngircd/log.c index a47ce92c..910a4793 100644 --- a/src/ngircd/log.c +++ b/src/ngircd/log.c @@ -39,13 +39,13 @@ #include "log.h" -static bool Is_Daemon; +static bool Use_Syslog; static void Log_Message(int Level, const char *msg) { - if (!Is_Daemon) { + if (!Use_Syslog) { /* log to console */ fprintf(stdout, "[%ld:%d %4ld] %s\n", (long)getpid(), Level, (long)(time(NULL) - NGIRCd_Start), msg); @@ -63,12 +63,12 @@ Log_Message(int Level, const char *msg) * Initialitze logging. * This function is called before the configuration file is read in. * - * @param Daemon_Mode Set to true if ngIRCd is running as daemon. + * @param Syslog_Mode Set to true if ngIRCd is running as daemon. */ GLOBAL void -Log_Init(bool Daemon_Mode) +Log_Init(bool Syslog_Mode) { - Is_Daemon = Daemon_Mode; + Use_Syslog = Syslog_Mode; #ifdef SYSLOG #ifndef LOG_CONS /* Kludge: mips-dec-ultrix4.5 has no LOG_CONS */ diff --git a/src/ngircd/log.h b/src/ngircd/log.h index f582e6c8..b48193f5 100644 --- a/src/ngircd/log.h +++ b/src/ngircd/log.h @@ -32,7 +32,7 @@ #define LOG_snotice 1024 -GLOBAL void Log_Init PARAMS(( bool Daemon_Mode )); +GLOBAL void Log_Init PARAMS(( bool Syslog_Mode )); GLOBAL void Log_Exit PARAMS(( void )); GLOBAL void Log PARAMS(( int Level, const char *Format, ... )); diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index 8b28a2fc..9f77f302 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.c @@ -74,7 +74,7 @@ GLOBAL int main(int argc, const char *argv[]) { bool ok, configtest = false; - bool NGIRCd_NoDaemon = false; + bool NGIRCd_NoDaemon = false, NGIRCd_NoSyslog = false; int i; size_t n; @@ -130,6 +130,7 @@ main(int argc, const char *argv[]) } if (strcmp(argv[i], "--nodaemon") == 0) { NGIRCd_NoDaemon = true; + NGIRCd_NoSyslog = true; ok = true; } if (strcmp(argv[i], "--passive") == 0) { @@ -178,6 +179,7 @@ main(int argc, const char *argv[]) if (argv[i][n] == 'n') { NGIRCd_NoDaemon = true; + NGIRCd_NoSyslog = true; ok = true; } if (argv[i][n] == 'p') { @@ -249,7 +251,7 @@ main(int argc, const char *argv[]) NGIRCd_SignalRestart = false; NGIRCd_SignalQuit = false; - Log_Init(!NGIRCd_NoDaemon); + Log_Init(!NGIRCd_NoSyslog); Random_Init(); Conf_Init(); Log_ReInit(); -- cgit 1.4.1 From 8f6d04095be35a9d0ff5b9375a61ddc243b6c83c Mon Sep 17 00:00:00 2001 From: Katherine Peeters Date: Sat, 29 Oct 2022 21:46:46 -0700 Subject: Added command line flag to enable syslog This allows -y / --syslog to be used to override -n / --nodaemon disabling it --- src/ngircd/ngircd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index 9f77f302..398c75c0 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.c @@ -142,6 +142,12 @@ main(int argc, const char *argv[]) NGIRCd_Sniffer = true; ok = true; } +#endif +#ifdef SYSLOG + if (strcmp(argv[i], "--syslog") == 0) { + NGIRCd_NoSyslog = false; + ok = true; + } #endif if (strcmp(argv[i], "--version") == 0) { Show_Version(); @@ -201,6 +207,12 @@ main(int argc, const char *argv[]) Show_Version(); exit(1); } +#ifdef SYSLOG + if (argv[i][n] == 'y') { + NGIRCd_NoSyslog = false; + ok = true; + } +#endif if (!ok) { fprintf(stderr, @@ -479,6 +491,9 @@ Show_Help( void ) #endif puts( " -t, --configtest read, validate and display configuration; then exit" ); puts( " -V, --version output version information and exit" ); +#ifdef SYSLOG + puts( " -y, --syslog log to syslog even when using -n" ); +#endif puts( " -h, --help display this help and exit" ); } /* Show_Help */ -- cgit 1.4.1 From dc412a450ef14b424f8e581c933663d9bcf9ebcc Mon Sep 17 00:00:00 2001 From: Katherine Peeters Date: Tue, 1 Nov 2022 16:21:56 -0700 Subject: Improve documentation for --syslog --- man/ngircd.8.tmpl | 3 +++ src/ngircd/log.c | 2 +- src/ngircd/ngircd.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/man/ngircd.8.tmpl b/man/ngircd.8.tmpl index d9c0f528..d9657362 100644 --- a/man/ngircd.8.tmpl +++ b/man/ngircd.8.tmpl @@ -53,6 +53,9 @@ Don't fork a child and don't detach from controlling terminal. All log messages go to the console and you can use CTRL-C to terminate the server. .TP +\fB\-y\fR, \fB\-\-syslog\fR +Write log messages to the syslog even when running in the foreground. +.TP \fB\-p\fR, \fB\-\-passive\fR Disable automatic connections to other servers. You can use the IRC command CONNECT later on as IRC Operator to link this ngIRCd to other servers. diff --git a/src/ngircd/log.c b/src/ngircd/log.c index 910a4793..f2582bce 100644 --- a/src/ngircd/log.c +++ b/src/ngircd/log.c @@ -63,7 +63,7 @@ Log_Message(int Level, const char *msg) * Initialitze logging. * This function is called before the configuration file is read in. * - * @param Syslog_Mode Set to true if ngIRCd is running as daemon. + * @param Syslog_Mode Set to true if ngIRCd is configured to log to the syslog. */ GLOBAL void Log_Init(bool Syslog_Mode) diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index 398c75c0..a124e2e7 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.c @@ -492,7 +492,7 @@ Show_Help( void ) puts( " -t, --configtest read, validate and display configuration; then exit" ); puts( " -V, --version output version information and exit" ); #ifdef SYSLOG - puts( " -y, --syslog log to syslog even when using -n" ); + puts( " -y, --syslog log to syslog even when running in the foreground (-n)" ); #endif puts( " -h, --help display this help and exit" ); } /* Show_Help */ -- cgit 1.4.1