[151] | 1 | /*
|
---|
| 2 | Netdrive Samba client plugin
|
---|
| 3 | logging functions
|
---|
[188] | 4 | Copyright (C) netlabs.org 2003-2009
|
---|
[151] | 5 |
|
---|
| 6 | This program is free software; you can redistribute it and/or modify
|
---|
| 7 | it under the terms of the GNU General Public License as published by
|
---|
| 8 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | (at your option) any later version.
|
---|
| 10 |
|
---|
| 11 | This program is distributed in the hope that it will be useful,
|
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | You should have received a copy of the GNU General Public License
|
---|
| 17 | along with this program; if not, write to the Free Software
|
---|
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[145] | 21 | #define INCL_DOSERRORS
|
---|
| 22 | #define INCL_DOS
|
---|
| 23 | #include <os2emx.h>
|
---|
| 24 | #include <stdio.h>
|
---|
| 25 | #include <stdlib.h>
|
---|
| 26 | #include <stdarg.h>
|
---|
| 27 | #include <string.h>
|
---|
| 28 | #include <sys/types.h>
|
---|
| 29 | #include <sys/time.h>
|
---|
[189] | 30 | #include <sys/stat.h>
|
---|
[448] | 31 | #include "nversion.h"
|
---|
[145] | 32 |
|
---|
[189] | 33 | int 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};
|
---|
[441] | 36 | char logfilename[] = "log.ndpsmb";
|
---|
| 37 | BOOL do_logging = FALSE;
|
---|
[445] | 38 | BOOL firstLogLine = TRUE;
|
---|
[145] | 39 |
|
---|
| 40 | int debuglvl(int level)
|
---|
| 41 | {
|
---|
| 42 | return (level <= debuglevel) ? 1 : 0;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[441] | 45 | BOOL writeLog()
|
---|
| 46 | {
|
---|
| 47 | return do_logging;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[189] | 50 | void debuglocal(int level, const char * fmt, ...)
|
---|
[145] | 51 | {
|
---|
[189] | 52 | FILE *f=NULL;
|
---|
| 53 | struct stat filestat;
|
---|
[145] | 54 |
|
---|
[189] | 55 | // if the file ndpsmb.dbg is around we write a logfile
|
---|
| 56 | if (!debugfile[0])
|
---|
| 57 | {
|
---|
| 58 | strncpy(debugfile, getenv("ETC"), 2);
|
---|
| 59 | strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
|
---|
| 60 | strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
|
---|
| 61 | } /* endif */
|
---|
| 62 |
|
---|
| 63 | if (stat(debugfile, &filestat) !=0)
|
---|
| 64 | return;
|
---|
[145] | 65 |
|
---|
[189] | 66 | //we create the logfile variable only once
|
---|
| 67 | if (!logfile[0])
|
---|
| 68 | {
|
---|
| 69 | char *env = getenv("LOGFILES");
|
---|
| 70 | if (env != NULL)
|
---|
| 71 | {
|
---|
| 72 | strncpy(logfile, env, sizeof(logfile) -1);
|
---|
| 73 | strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
|
---|
| 74 | strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1);
|
---|
| 75 | }
|
---|
| 76 | else
|
---|
| 77 | {
|
---|
| 78 | strncpy(logfile, logfilename, sizeof(logfile) -1);
|
---|
| 79 | }
|
---|
[441] | 80 | // set the samba logging stuff
|
---|
| 81 | do_logging = TRUE;
|
---|
[189] | 82 | } /* endif */
|
---|
[188] | 83 |
|
---|
| 84 | if (!debuglvl(level))
|
---|
[145] | 85 | {
|
---|
| 86 | return;
|
---|
| 87 | }
|
---|
| 88 | do
|
---|
| 89 | {
|
---|
| 90 | struct timeval tv;
|
---|
| 91 | char buf[80] = {0};
|
---|
| 92 | va_list args;
|
---|
[189] | 93 | if (logfile[0])
|
---|
[145] | 94 | {
|
---|
| 95 | f = fopen(logfile, "a");
|
---|
| 96 | if (!f)
|
---|
| 97 | {
|
---|
| 98 | break;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | else
|
---|
| 102 | {
|
---|
| 103 | f = stdout;
|
---|
| 104 | }
|
---|
[445] | 105 |
|
---|
| 106 | // in the first log line we write our version of the client
|
---|
| 107 | if (firstLogLine)
|
---|
| 108 | {
|
---|
[448] | 109 | fprintf(f, "Samba client %s build %s based on %s\n", VERSION, BUILD, smbwrp_getVersion());
|
---|
[445] | 110 | firstLogLine = FALSE;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[145] | 113 | gettimeofday(&tv, NULL);
|
---|
| 114 | strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
|
---|
| 115 | fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid());
|
---|
| 116 | va_start(args, fmt);
|
---|
| 117 | vfprintf(f, fmt, args);
|
---|
| 118 | va_end(args);
|
---|
| 119 | if (logfile)
|
---|
| 120 | {
|
---|
| 121 | fclose(f);
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | while (0);
|
---|
| 125 | }
|
---|