]> jfr.im git - irc/UndernetIRC/gnuworld.git/commitdiff
Fix: if log files are closed and reopened because of SIGHUP signal,
authorHidden <redacted>
Sun, 25 Sep 2022 23:45:25 +0000 (19:45 -0400)
committerHidden <redacted>
Sun, 25 Sep 2022 23:45:25 +0000 (19:45 -0400)
reopen in APPEND mode

include/server.h
libgnuworld/ELog.cc
src/main.cc
src/server.cc

index 06cc12b22fa821b7650c5b5ff849f5e1e187e5cf..146d8a2b62f3b2a24420bcc0367279639dec5ed5 100644 (file)
@@ -902,7 +902,7 @@ public:
        /**
         * Start logging.
         */
-       virtual void startLogging() ;
+       virtual void startLogging(bool logrotate = false) ;
 
        /**
         * Rotate logs.
index 0e57f78002c7b602674176ca4a1e713c95d5b735..a50451872671fa308e65926c4beeb0f256bce24c 100755 (executable)
@@ -62,12 +62,17 @@ if( logFile )
 
 bool ELog::openFile( const string& fileName )
 {
+bool isAlreadyOpen = false;
 if( isOpen() )
        {
+       isAlreadyOpen = true;
        closeFile() ;
        }
 logFile = true ;
-outFile.open( fileName.c_str(), std::ios::out | std::ios::trunc ) ;
+if (isAlreadyOpen)
+       outFile.open( fileName.c_str(), std::ios::out | std::ios::app ) ;
+else
+       outFile.open( fileName.c_str(), std::ios::out | std::ios::trunc ) ;
 
 if( !isOpen() )
        {
index 9dd02240dd648700bb0a25508966de2c20189f37..abe4b689326a55d57786d7df82e1c2af95c69cc7 100644 (file)
@@ -289,7 +289,7 @@ while( (c = getopt( argc, argv, "cd:Df:l:Lhs:")) != -1 )
                } // close switch
        } // close while
 
-startLogging() ;
+startLogging(false) ;
 // Sets up the server internals
 initializeSystem() ;
 }
index a5a812ca1cd800a52bc1ead42bd2c531c9054f97..434ae392621a34033b0f5b413ade63762156deae 100644 (file)
@@ -1994,7 +1994,7 @@ clog      << "Read " << burstBytes
        << endl ;
 }
 
-void xServer::startLogging()
+void xServer::startLogging(bool logrotate)
 {
 if( doDebug )
        {
@@ -2019,7 +2019,10 @@ if( verbose )
 
 if( logSocket )
        {
-       socketFile.open( socketFileName.c_str(), std::ios::out ) ;
+       if (logrotate)
+               socketFile.open( socketFileName.c_str(), std::ios::out | std::ios::app) ;
+       else
+               socketFile.open( socketFileName.c_str(), std::ios::out ) ;
        if( !socketFile.is_open() )
                {
                clog    << "*** Unable to open socket log file: "
@@ -2039,13 +2042,13 @@ void xServer::rotateLogs()
 if (elog.isOpen())
        {
        elog << endl << "Received SIGHUP. Rotating log files..." << endl;
-       elog.closeFile();
+       //elog.closeFile();  /* Do not close the file, elog.openFile() will handle that.
        }
 if( logSocket && socketFile.is_open() )
        {
        socketFile.close() ;
        }
-startLogging();
+startLogging(true);
 }
 
 void xServer::run()