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