]> arthur.barton.de Git - ngircd.git/commitdiff
Merge branch 'katp32/master'
authorAlexander Barton <alex@barton.de>
Sun, 17 Sep 2023 19:37:45 +0000 (21:37 +0200)
committerAlexander Barton <alex@barton.de>
Sun, 17 Sep 2023 19:37:45 +0000 (21:37 +0200)
Thanks Katherine Peeters for the patch and pull request!

Closes #294.

* katp32/master:
  Improve documentation for --syslog
  Added command line flag to enable syslog
  Split NoSyslog from behaviour of NoDaemon

1  2 
src/ngircd/log.c
src/ngircd/log.h
src/ngircd/ngircd.c

diff --combined src/ngircd/log.c
index e036b0158cdae1299cdd0fa03c053dc18d5b78fc,f2582bce78381ec6174974c854aa47629dc03747..dae53f9f5b45481b56be1295eb451eb2f162a986
  
  #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);
   * 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 configured to log to the syslog.
   */
  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 */
@@@ -121,6 -121,7 +121,6 @@@ Log_Exit( void 
   * @param Format Format string like printf().
   * @param ... Further arguments.
   */
 -#ifdef DEBUG
  # ifdef PROTOTYPES
  GLOBAL void
  LogDebug( const char *Format, ... )
@@@ -144,6 -145,7 +144,6 @@@ va_dc
        va_end( ap );
        Log(LOG_DEBUG, "%s", msg);
  }
 -#endif        /* DEBUG */
  
  
  /**
@@@ -182,7 -184,11 +182,7 @@@ va_dc
        }
        else snotice = false;
  
 -#ifdef DEBUG
        if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
 -#else
 -      if( Level == LOG_DEBUG ) return;
 -#endif
  
  #ifdef PROTOTYPES
        va_start( ap, Format );
@@@ -209,16 -215,20 +209,16 @@@ Log_Init_Subprocess(char UNUSED *Name
  #ifdef SYSLOG
        openlog(PACKAGE, LOG_CONS|LOG_PID, Conf_SyslogFacility);
  #endif
 -#ifdef DEBUG
        Log_Subprocess(LOG_DEBUG, "%s sub-process starting, PID %ld.",
                     Name, (long)getpid());
 -#endif
  }
  
  
  GLOBAL void
  Log_Exit_Subprocess(char UNUSED *Name)
  {
 -#ifdef DEBUG
        Log_Subprocess(LOG_DEBUG, "%s sub-process %ld done.",
                     Name, (long)getpid());
 -#endif
  #ifdef SYSLOG
        closelog( );
  #endif
@@@ -241,8 -251,13 +241,8 @@@ va_dc
  
        assert(Format != NULL);
  
 -#ifdef DEBUG
        if ((Level == LOG_DEBUG) && (!NGIRCd_Debug))
                return;
 -#else
 -      if (Level == LOG_DEBUG)
 -              return;
 -#endif
  
  #ifdef PROTOTYPES
        va_start(ap, Format);
diff --combined src/ngircd/log.h
index 85d00d9f6a16cd3c6f496efe574087be4d271269,b48193f5023b9feb415c1c8cd5d37f4c117a01f4..0ac4c4d9a4e85ad648abef9e9e20e16f3aab0247
@@@ -32,7 -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, ... ));
@@@ -40,14 -40,20 +40,14 @@@ GLOBAL void Log_ReInit PARAMS((void))
  
  GLOBAL void Log_ServerNotice PARAMS((char UserMode, const char *Format, ...));
  
 -#ifdef DEBUG
  GLOBAL void LogDebug PARAMS(( const char *Format, ... ));
 -#else
 -static inline void LogDebug PARAMS(( UNUSED const char *Format, ... )){/* Do nothing. The compiler should optimize this out, please ;-) */}
 -#endif
  
  GLOBAL void Log_Init_Subprocess PARAMS((char *Name));
  GLOBAL void Log_Exit_Subprocess PARAMS((char *Name));
  
  GLOBAL void Log_Subprocess PARAMS((const int Level, const char *Format, ...));
  
 -#ifdef DEBUG
  GLOBAL void Log_InitErrorfile PARAMS(( void ));
 -#endif
  
  #endif
  
diff --combined src/ngircd/ngircd.c
index 47f6092e25748b9e1844655dc0a08b3750768586,a124e2e75f57a00cceac0be88b53a3f7adc6504a..fd919e34becff5f6c7a33963e9b5d4e591fd991d
@@@ -1,6 -1,6 +1,6 @@@
  /*
   * ngIRCd -- The Next Generation IRC Daemon
 - * Copyright (c)2001-2022 Alexander Barton (alex@barton.de) and Contributors.
 + * Copyright (c)2001-2023 Alexander Barton (alex@barton.de) and Contributors.
   *
   * 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
@@@ -74,7 -74,7 +74,7 @@@ GLOBAL in
  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;
  
@@@ -88,7 -88,9 +88,7 @@@
  
        NGIRCd_SignalQuit = NGIRCd_SignalRestart = false;
        NGIRCd_Passive = false;
 -#ifdef DEBUG
        NGIRCd_Debug = false;
 -#endif
  #ifdef SNIFFER
        NGIRCd_Sniffer = false;
  #endif
                                configtest = true;
                                ok = true;
                        }
 -#ifdef DEBUG
                        if (strcmp(argv[i], "--debug") == 0) {
                                NGIRCd_Debug = true;
                                ok = true;
                        }
 -#endif
                        if (strcmp(argv[i], "--help") == 0) {
                                Show_Version();
                                puts(""); Show_Help( ); puts( "" );
                        }
                        if (strcmp(argv[i], "--nodaemon") == 0) {
                                NGIRCd_NoDaemon = true;
+                               NGIRCd_NoSyslog = true;
                                ok = true;
                        }
                        if (strcmp(argv[i], "--passive") == 0) {
                                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();
                        /* short option */
                        for (n = 1; n < strlen(argv[i]); n++) {
                                ok = false;
 -#ifdef DEBUG
                                if (argv[i][n] == 'd') {
                                        NGIRCd_Debug = true;
                                        ok = true;
                                }
 -#endif
                                if (argv[i][n] == 'f') {
                                        if (!argv[i][n+1] && i+1 < argc) {
                                                /* Ok, next character is a blank */
  
                                if (argv[i][n] == 'n') {
                                        NGIRCd_NoDaemon = true;
+                                       NGIRCd_NoSyslog = true;
                                        ok = true;
                                }
                                if (argv[i][n] == 'p') {
                                        Show_Version();
                                        exit(1);
                                }
+ #ifdef SYSLOG
+                               if (argv[i][n] == 'y') {
+                                       NGIRCd_NoSyslog = false;
+                                       ok = true;
+                               }
+ #endif
  
                                if (!ok) {
                                        fprintf(stderr,
  
        /* Debug level for "VERSION" command */
        NGIRCd_DebugLevel[0] = '\0';
 -#ifdef DEBUG
        if (NGIRCd_Debug)
                strcpy(NGIRCd_DebugLevel, "1");
 -#endif
  #ifdef SNIFFER
        if (NGIRCd_Sniffer) {
                NGIRCd_Debug = true;
                NGIRCd_SignalRestart = false;
                NGIRCd_SignalQuit = false;
  
-               Log_Init(!NGIRCd_NoDaemon);
+               Log_Init(!NGIRCd_NoSyslog);
                Random_Init();
                Conf_Init();
                Log_ReInit();
@@@ -443,7 -465,7 +457,7 @@@ static voi
  Show_Version( void )
  {
        puts( NGIRCd_Version );
 -      puts( "Copyright (c)2001-2022 Alexander Barton (<alex@barton.de>) and Contributors." );
 +      puts( "Copyright (c)2001-2023 Alexander Barton (<alex@barton.de>) and Contributors." );
        puts( "Homepage: <http://ngircd.barton.de/>\n" );
        puts( "This is free software; see the source for copying conditions. There is NO" );
        puts( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." );
  static void
  Show_Help( void )
  {
 -#ifdef DEBUG
        puts( "  -d, --debug        log extra debug messages" );
 -#endif
        puts( "  -f, --config <f>   use file <f> as configuration file" );
        puts( "  -n, --nodaemon     don't fork and don't detach from controlling terminal" );
        puts( "  -p, --passive      disable automatic connections to other servers" );
  #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 running in the foreground (-n)" );
+ #endif
        puts( "  -h, --help         display this help and exit" );
  } /* Show_Help */
  
@@@ -480,7 -507,9 +497,7 @@@ Pidfile_Delete( void 
        /* Pidfile configured? */
        if( ! Conf_PidFile[0] ) return;
  
 -#ifdef DEBUG
 -      Log( LOG_DEBUG, "Removing PID file (%s) ...", Conf_PidFile );
 -#endif
 +      LogDebug( "Removing PID file (%s) ...", Conf_PidFile );
  
        if( unlink( Conf_PidFile ))
                Log( LOG_ERR, "Error unlinking PID file (%s): %s", Conf_PidFile, strerror( errno ));
@@@ -502,7 -531,9 +519,7 @@@ Pidfile_Create(pid_t pid
        /* Pidfile configured? */
        if( ! Conf_PidFile[0] ) return;
  
 -#ifdef DEBUG
 -      Log( LOG_DEBUG, "Creating PID file (%s) ...", Conf_PidFile );
 -#endif
 +      LogDebug( "Creating PID file (%s) ...", Conf_PidFile );
  
        pidfd = open( Conf_PidFile, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
        if ( pidfd < 0 ) {
@@@ -803,7 -834,7 +820,7 @@@ NGIRCd_Init(bool NGIRCd_NoDaemon
  
        if (pwd) {
                if (chdir(pwd->pw_dir) == 0)
 -                      Log(LOG_DEBUG,
 +                      LogDebug(
                            "Changed working directory to \"%s\" ...",
                            pwd->pw_dir);
                else