Changeset 960 for trunk/client/src/debug.c
- Timestamp:
- Aug 16, 2016, 5:41:49 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/src/debug.c
r959 r960 31 31 #include <sys/stat.h> 32 32 #include "nversion.h" 33 #include "smbwrp.h" 33 34 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"; 35 void debugInit(Resource *pRes, char *logfileext, int ifL) 36 { 37 if (!pRes) 38 return; 42 39 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; 61 42 APIRET rc = NO_ERROR; 62 63 // create the debugfile name64 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 debug69 if (stat(debugfile, &filestat) !=0)70 return;71 43 72 44 //create the logfile variable … … 74 46 if (env != NULL) 75 47 { 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); 79 50 } 80 51 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; 90 57 91 58 return; … … 94 61 void debugDelete() 95 62 { 96 DosCloseMutexSem(logMutex);97 63 return; 98 64 } 99 65 100 void debug local(int level, const char * fmt, ...)66 void debugClose(Resource *pRes) 101 67 { 102 FILE *f=NULL; 68 if (pRes && pRes->logfileFH) 69 { 70 fclose(pRes->logfileFH); 71 pRes->logfileFH = NULL; 72 } 73 return; 74 } 103 75 76 void debuglocal(Resource *pRes, int level, const char * fmt, ...) 77 { 78 FILE *f = NULL; 104 79 // do we have to log at all 105 if ( !do_logging)80 if (pRes && (level > pRes->loglevel)) 106 81 return; 107 108 // if the sem is created we request it109 if (logMutex)110 DosRequestMutexSem(logMutex, (ULONG) SEM_INDEFINITE_WAIT);111 82 112 83 do { … … 114 85 char buf[80] = {0}; 115 86 va_list args; 116 if ( logfile[0])87 if (pRes) 117 88 { 118 f = fopen(logfile, "a"); 119 if (!f) 89 if (!pRes->logfileFH) 90 pRes->logfileFH = fopen(pRes->logfile, "a"); 91 if (!pRes->logfileFH) 120 92 break; 93 else 94 f = pRes->logfileFH; 121 95 } 122 96 else … … 124 98 125 99 // in the first log line we write our version of the client 126 if ( firstLogLine)100 if (pRes && pRes->firstLogLine) 127 101 { 128 102 fprintf(f, "Samba client %s build %s based on %s\n", VERSION, BUILD, smbwrp_getVersion()); 129 103 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; 131 107 } 132 108 … … 137 113 vfprintf(f, fmt, args); 138 114 va_end(args); 139 if (logfile)140 fclose(f);141 115 142 116 } while (0); 143 117 144 // if the sem is created we release it145 if (logMutex)146 DosReleaseMutexSem(logMutex);147 148 118 return; 149 119 }
Note:
See TracChangeset
for help on using the changeset viewer.