[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>
|
---|
[145] | 31 |
|
---|
[189] | 32 | int debuglevel = 9; // we set it to 9, so we get all messages
|
---|
| 33 | char logfile[_MAX_PATH +1] = {0};
|
---|
| 34 | char debugfile[_MAX_PATH +1] = {0};
|
---|
[439] | 35 | char logfilename[] = "log.ndpsmb";
|
---|
[437] | 36 | BOOL do_logging = FALSE;
|
---|
[145] | 37 |
|
---|
| 38 | int debuglvl(int level)
|
---|
| 39 | {
|
---|
| 40 | return (level <= debuglevel) ? 1 : 0;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[436] | 43 | BOOL writeLog()
|
---|
| 44 | {
|
---|
| 45 | return do_logging;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[189] | 48 | void debuglocal(int level, const char * fmt, ...)
|
---|
[145] | 49 | {
|
---|
[189] | 50 | FILE *f=NULL;
|
---|
| 51 | struct stat filestat;
|
---|
[145] | 52 |
|
---|
[189] | 53 | // if the file ndpsmb.dbg is around we write a logfile
|
---|
| 54 | if (!debugfile[0])
|
---|
| 55 | {
|
---|
| 56 | strncpy(debugfile, getenv("ETC"), 2);
|
---|
| 57 | strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
|
---|
| 58 | strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
|
---|
| 59 | } /* endif */
|
---|
| 60 |
|
---|
| 61 | if (stat(debugfile, &filestat) !=0)
|
---|
| 62 | return;
|
---|
[145] | 63 |
|
---|
[189] | 64 | //we create the logfile variable only once
|
---|
| 65 | if (!logfile[0])
|
---|
| 66 | {
|
---|
| 67 | char *env = getenv("LOGFILES");
|
---|
| 68 | if (env != NULL)
|
---|
| 69 | {
|
---|
| 70 | strncpy(logfile, env, sizeof(logfile) -1);
|
---|
| 71 | strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
|
---|
[434] | 72 | strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1);
|
---|
[189] | 73 | }
|
---|
| 74 | else
|
---|
| 75 | {
|
---|
| 76 | strncpy(logfile, logfilename, sizeof(logfile) -1);
|
---|
| 77 | }
|
---|
[434] | 78 | // set the samba logging stuff
|
---|
[436] | 79 | do_logging = TRUE;
|
---|
[189] | 80 | } /* endif */
|
---|
[188] | 81 |
|
---|
| 82 | if (!debuglvl(level))
|
---|
[145] | 83 | {
|
---|
| 84 | return;
|
---|
| 85 | }
|
---|
| 86 | do
|
---|
| 87 | {
|
---|
| 88 | struct timeval tv;
|
---|
| 89 | char buf[80] = {0};
|
---|
| 90 | va_list args;
|
---|
[189] | 91 | if (logfile[0])
|
---|
[145] | 92 | {
|
---|
| 93 | f = fopen(logfile, "a");
|
---|
| 94 | if (!f)
|
---|
| 95 | {
|
---|
| 96 | break;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | else
|
---|
| 100 | {
|
---|
| 101 | f = stdout;
|
---|
| 102 | }
|
---|
| 103 | gettimeofday(&tv, NULL);
|
---|
| 104 | strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
|
---|
| 105 | fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid());
|
---|
| 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 | }
|
---|