Ignore:
Timestamp:
May 12, 2009, 8:09:42 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Final fix for Ticket #88 (by diver)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/client-1.5/src/debug.c

    r188 r189  
    2828#include <sys/types.h>
    2929#include <sys/time.h>
     30#include <sys/stat.h>
    3031
    31 // #include "smbwrp.h"
    32 
    33 int debuglevel = 0;
    34 char *logfile = NULL;
    35 
    36 
    37 void dbgfileinit(char *file, int loglevel)
    38 {
    39         logfile = file;
    40         debuglevel = loglevel;
    41 }
     32int debuglevel = 9; // we set it to 9, so we get all messages
     33char logfile[_MAX_PATH +1]  = {0};
     34char debugfile[_MAX_PATH +1] = {0};
     35char logfilename[] = "ndpsmb.log";
    4236
    4337int debuglvl(int level)
     
    4640}
    4741
    48 int debugheader(int level, char * file, char * func, int line)
    49 {
    50         int rc;
    51         if (!debuglvl(level))
    52         {
    53                 return 0;
    54         }
    55         rc = 1;
    56         do
    57         {
    58                 FILE * f;
    59                 struct timeval tv;
    60                 time_t t;
    61                 char buf[80] = {0};
    62                 if (logfile)
    63                 {
    64                         f = fopen(logfile, "a");
    65                         if (!f)
    66                         {
    67                                 rc = 0;
    68                                 break;
    69                         }
    70                 }
    71                 else
    72                 {
    73                         f = stdout;
    74                 }
    75                 gettimeofday(&tv, NULL);
    76                 t = time(NULL);
    77                 strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime(&t));
    78                 fprintf(f, "%s.%d: %d %d: %s:%s(%d) :", buf, tv.tv_usec / 10000, level, (long)_gettid(), file, func, line);
    79                 if (logfile)
    80                 {
    81                         fclose(f);
    82                 }
    83         }
    84         while (0);
    85         return rc;
    86 }
    87 
    88 int debugmessage(char * fmt, ...)
    89 {
    90         do
    91         {
    92                 FILE * f;
    93                 va_list args;
    94                 if (logfile)
    95                 {
    96                         f = fopen(logfile, "a");
    97                         if (!f)
    98                         {
    99                                 break;
    100                         }
    101                 }
    102                 else
    103                 {
    104                         f = stdout;
    105                 }
    106                 va_start(args, fmt);
    107                 vfprintf(f, fmt, args);
    108                 va_end(args);
    109                 if (logfile)
    110                 {
    111                         fclose(f);
    112                 }
    113         }
    114         while (0);
    115         return 0;
    116 }
    117 
    11842void debuglocal(int level, const char * fmt, ...)
    11943{
     44        FILE *f=NULL;
     45        struct stat filestat;
     46
     47        // if the file ndpsmb.dbg is around we write a logfile
     48        if (!debugfile[0])
     49        {
     50           strncpy(debugfile, getenv("ETC"), 2);
     51           strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
     52           strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
     53        } /* endif */
     54       
     55        if (stat(debugfile, &filestat) !=0)
     56           return;
     57
     58        //we create the logfile variable only once
     59        if (!logfile[0])
     60        {
     61                char *env = getenv("LOGFILES");
     62                if (env != NULL)
     63                {
     64                   strncpy(logfile, env, sizeof(logfile) -1);
     65                   strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
     66                   strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); 
     67                }
     68                else
     69                {
     70                   strncpy(logfile, logfilename, sizeof(logfile) -1);
     71                }
     72        } /* endif */
    12073
    12174        if (!debuglvl(level))
     
    12578        do
    12679        {
    127                 FILE * f;
    12880                struct timeval tv;
    12981                char buf[80] = {0};
    13082                va_list args;
    131                 if (logfile)
     83                if (logfile[0])
    13284                {
    13385                        f = fopen(logfile, "a");
Note: See TracChangeset for help on using the changeset viewer.