Ignore:
Timestamp:
Aug 16, 2016, 5:41:49 PM (9 years ago)
Author:
Silvan Scherrer
Message:

samba client: add the possibility to have logfiles per share

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/src/debug.c

    r959 r960  
    3131#include <sys/stat.h>
    3232#include "nversion.h"
     33#include "smbwrp.h"
    3334
    34 int debuglevel = 9; // we set it to 9, so we get all messages
    35 char logfile[_MAX_PATH +1];
    36 char debugfile[_MAX_PATH +1];
    37 char logfilename[] = "log.ndpsmb";
    38 BOOL do_logging;
    39 BOOL firstLogLine;
    40 HMTX logMutex;
    41 char nameMutex[] = "\\SEM32\\NDPSMB";
     35void debugInit(Resource *pRes, char *logfileext, int ifL)
     36{
     37        if (!pRes)
     38           return;
    4239
    43 int debuglvl(int level)
    44 {
    45         return (level <= debuglevel) ? 1 : 0;
    46 }
    47 
    48 BOOL writeLog()
    49 {
    50         return do_logging;
    51 }
    52 
    53 void debugInit()
    54 {
    55         *logfile = '\0';
    56         *debugfile = '\0';
    57         do_logging = FALSE;
    58         firstLogLine = TRUE;
    59         logMutex = NULLHANDLE;
    60         struct stat filestat;
     40        pRes->firstLogLine = 1;
     41        pRes->ifL = ifL;
    6142        APIRET rc = NO_ERROR;
    62 
    63         // create the debugfile name
    64         strncat(debugfile, getenv("ETC"), 2);
    65         strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
    66         strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
    67 
    68         // is the file around? if not we have no debug
    69         if (stat(debugfile, &filestat) !=0)
    70            return;
    7143
    7244        //create the logfile variable
     
    7446        if (env != NULL)
    7547        {
    76            strncat(logfile, env, sizeof(logfile) -1);
    77            strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
    78            strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); 
     48           snprintf(pRes->logfile, sizeof(pRes->logfile), "%s/%s.%s", env, "log.ndpsmb", logfileext);
     49           snprintf(pRes->smb_logfile, sizeof(pRes->smb_logfile), "%s/%s.%s", env, "log.smbc", logfileext);
    7950        }
    8051        else
    81            strncat(logfile, logfilename, sizeof(logfile) -1);
    82        
    83         // set the samba logging stuff
    84         do_logging = TRUE;
    85 
    86         // now we create a sem, so that logging from different threads works
    87         rc = DosCreateMutexSem(nameMutex, &logMutex, 0, FALSE);
    88         if (rc == ERROR_DUPLICATE_NAME)
    89            rc = DosOpenMutexSem(nameMutex, &logMutex);
     52        {
     53           snprintf(pRes->logfile, sizeof(pRes->logfile), "%s.%s", "log.ndpsmb", logfileext);
     54           snprintf(pRes->smb_logfile, sizeof(pRes->smb_logfile), "%s.%s", "log.smbc", logfileext);
     55        }
     56        pRes->logfileFH = NULL;
    9057
    9158        return;
     
    9461void debugDelete()
    9562{
    96         DosCloseMutexSem(logMutex);
    9763        return;
    9864}
    9965
    100 void debuglocal(int level, const char * fmt, ...)
     66void debugClose(Resource *pRes)
    10167{
    102         FILE *f=NULL;
     68        if (pRes && pRes->logfileFH)
     69        {
     70           fclose(pRes->logfileFH);
     71           pRes->logfileFH = NULL;
     72        }
     73        return;
     74}
    10375
     76void debuglocal(Resource *pRes, int level, const char * fmt, ...)
     77{
     78        FILE *f = NULL;
    10479        // do we have to log at all
    105         if (!do_logging)
     80        if (pRes && (level > pRes->loglevel))
    10681           return;
    107 
    108         // if the sem is created we request it
    109         if (logMutex)
    110            DosRequestMutexSem(logMutex, (ULONG) SEM_INDEFINITE_WAIT);
    11182
    11283        do {
     
    11485           char buf[80] = {0};
    11586           va_list args;
    116            if (logfile[0])
     87           if (pRes)
    11788           {
    118               f = fopen(logfile, "a");
    119               if (!f)
     89              if (!pRes->logfileFH)
     90                 pRes->logfileFH = fopen(pRes->logfile, "a");
     91              if (!pRes->logfileFH)
    12092                 break;
     93              else
     94                 f = pRes->logfileFH;
    12195           }
    12296           else
     
    12498
    12599           // in the first log line we write our version of the client
    126            if (firstLogLine)
     100           if (pRes && pRes->firstLogLine)
    127101           {
    128102              fprintf(f, "Samba client %s build %s based on %s\n", VERSION, BUILD, smbwrp_getVersion());
    129103              fprintf(f, "This build is maintained by %s\n", VENDOR);
    130               firstLogLine = FALSE;
     104              fprintf(f, "Working with %s bit fileio NDFS\n", pRes->ifL ? "64" : "32");
     105
     106              pRes->firstLogLine = 0;
    131107           }
    132108
     
    137113           vfprintf(f, fmt, args);
    138114           va_end(args);
    139            if (logfile)
    140               fclose(f);
    141115
    142116        } while (0);
    143117
    144         // if the sem is created we release it
    145         if (logMutex)
    146            DosReleaseMutexSem(logMutex);
    147 
    148118        return;
    149119}
Note: See TracChangeset for help on using the changeset viewer.