Ignore:
Timestamp:
Jan 26, 2011, 3:31:18 PM (15 years ago)
Author:
Silvan Scherrer
Message:

Samba Client 2.1: degug changes, attemp to fix the trap

File:
1 edited

Legend:

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

    r508 r533  
    3232
    3333int debuglevel = 9; // we set it to 9, so we get all messages
    34 char logfile[_MAX_PATH +1]  = {0};
    35 char debugfile[_MAX_PATH +1] = {0};
     34char logfile[_MAX_PATH +1];
     35char debugfile[_MAX_PATH +1];
    3636char logfilename[] = "log.ndpsmb";
    37 BOOL do_logging = FALSE;
    38 BOOL firstLogLine = TRUE;
     37BOOL do_logging;
     38BOOL firstLogLine;
     39HMTX logMutex;
     40char nameMutex[] = "\\SEM32\\NDPSMB";
    3941
    4042int debuglvl(int level)
     
    4850}
    4951
     52void debugInit()
     53{
     54        *logfile = '\0';
     55        *debugfile = '\0';
     56        do_logging = FALSE;
     57        firstLogLine = TRUE;
     58        logMutex = NULLHANDLE;
     59        struct stat filestat;
     60        APIRET rc = NO_ERROR;
     61
     62        // create the debugfile name
     63        strncat(debugfile, getenv("ETC"), 2);
     64        strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
     65        strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
     66
     67        // is the file around? if not we have no debug
     68        if (stat(debugfile, &filestat) !=0)
     69           return;
     70
     71        //create the logfile variable
     72        char *env = getenv("LOGFILES");
     73        if (env != NULL)
     74        {
     75           strncat(logfile, env, sizeof(logfile) -1);
     76           strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
     77           strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); 
     78        }
     79        else
     80        {
     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        {
     90        rc = DosOpenMutexSem(nameMutex, &logMutex);
     91        }
     92
     93        return;
     94}
     95
     96void debugDelete()
     97{
     98        DosCloseMutexSem(logMutex);
     99        return;
     100}
     101
    50102void debuglocal(int level, const char * fmt, ...)
    51103{
    52104        FILE *f=NULL;
    53         struct stat filestat;
    54105
    55         // do we have to log at all (not needed atm)
    56 /*      if (!debuglvl(level))
     106        // do we have to log at all
     107        if (!do_logging)
    57108        {
    58109                return;
    59         }*/
     110        }
    60111
    61         // if the file ndpsmb.dbg is around we write a logfile
    62         if (!debugfile[0])
     112        // if the sem is created we request it
     113        if (logMutex)
    63114        {
    64            strncpy(debugfile, getenv("ETC"), 2);
    65            strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
    66            strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
    67         } /* endif */
    68        
    69         if (stat(debugfile, &filestat) !=0)
    70            return;
    71 
    72         //we create the logfile variable only once
    73         if (!logfile[0])
    74         {
    75                 char *env = getenv("LOGFILES");
    76                 if (env != NULL)
    77                 {
    78                    strncpy(logfile, env, sizeof(logfile) -1);
    79                    strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
    80                    strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); 
    81                 }
    82                 else
    83                 {
    84                    strncpy(logfile, logfilename, sizeof(logfile) -1);
    85                 }
    86                 // set the samba logging stuff
    87                 do_logging = TRUE;
    88         } /* endif */
     115           DosRequestMutexSem(logMutex, (ULONG) SEM_INDEFINITE_WAIT);
     116        }
    89117
    90118        do
     
    121149                if (logfile)
    122150                {
    123                         fclose(f);
     151//                      fflush(f);
     152                        fclose(f);
    124153                }
    125154        }
    126155        while (0);
     156
     157        // if the sem is created we release it
     158        if (logMutex)
     159        {
     160           DosReleaseMutexSem(logMutex);
     161        }
     162
     163        return;
    127164}
Note: See TracChangeset for help on using the changeset viewer.