Changeset 13330


Ignore:
Timestamp:
May 30, 2012, 5:59:52 PM (9 years ago)
Author:
jordan
Message:

(trunmk libT) #4162 "daemon should reopen logfile on SIGHUP" -- patch from gvdl to reopen the logfile on SIGHUP s.t. log rotation can be used by outside tools

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/daemon.c

    r13312 r13330  
    5858#define SPEED_T_STR "TB/s"
    5959
     60#define LOGFILE_MODE_STR "a+"
     61
    6062static bool paused = false;
    6163static bool closing = false;
    6264static bool seenHUP = false;
     65static const char *logfileName = NULL;
     66static FILE *logfile = NULL;
    6367static tr_session * mySession = NULL;
    6468
     
    151155            {
    152156                tr_benc settings;
    153                 const char * configDir = tr_sessionGetConfigDir( mySession );
     157                const char * configDir;
     158
     159                /* reopen the logfile to allow for log rotation */
     160                if( logfileName ) {
     161                    logfile = freopen( logfileName, LOGFILE_MODE_STR, logfile );
     162                    if( !logfile )
     163                        fprintf( stderr, "Couldn't reopen \"%s\": %s\n", logfileName, tr_strerror( errno ) );
     164                }
     165
     166                configDir = tr_sessionGetConfigDir( mySession );
    154167                tr_inf( "Reloading settings from \"%s\"", configDir );
    155168                tr_bencInitDict( &settings, 0 );
     
    354367    const char * pid_filename;
    355368    dtr_watchdir * watchdir = NULL;
    356     FILE * logfile = NULL;
    357369    bool pidfile_created = false;
    358370    tr_session * session = NULL;
     
    393405            case 'd': dumpSettings = true;
    394406                      break;
    395             case 'e': logfile = fopen( optarg, "a+" );
    396                       if( logfile == NULL )
     407            case 'e': logfile = fopen( optarg, LOGFILE_MODE_STR );
     408                      if( logfile )
     409                          logfileName = optarg;
     410                      else
    397411                          fprintf( stderr, "Couldn't open \"%s\": %s\n", optarg, tr_strerror( errno ) );
    398412                      break;
Note: See TracChangeset for help on using the changeset viewer.