1 | #define INCL_DOSERRORS
|
---|
2 | #define INCL_DOS
|
---|
3 | #include <os2emx.h>
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <stdarg.h>
|
---|
7 | #include <string.h>
|
---|
8 | #include <sys/types.h>
|
---|
9 | #include <process.h>
|
---|
10 | #include <sys/time.h>
|
---|
11 |
|
---|
12 | #include "smbwrp.h"
|
---|
13 | //#include "smbcd.h"
|
---|
14 | //#include "config.h"
|
---|
15 |
|
---|
16 | #define SMBCD_MAX_THREADS 250
|
---|
17 |
|
---|
18 | int debuglevel = 0;
|
---|
19 | HMTX logmutex = 0;
|
---|
20 | char *logfile = NULL;
|
---|
21 |
|
---|
22 |
|
---|
23 | #if 0
|
---|
24 | int debug_parse_levels(const char *params_str)
|
---|
25 | {
|
---|
26 | return 1;
|
---|
27 | }
|
---|
28 |
|
---|
29 | void dbgflush( void )
|
---|
30 | {
|
---|
31 | // if (!logfile) fflush(stdout);
|
---|
32 | }
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | int debuglvl(int level)
|
---|
36 | {
|
---|
37 | return (level <= debuglevel) ? 1 : 0;
|
---|
38 | }
|
---|
39 |
|
---|
40 | int debugheader(int level, char * file, char * func, int line)
|
---|
41 | {
|
---|
42 | int rc;
|
---|
43 | if (level > debuglevel)
|
---|
44 | {
|
---|
45 | return 0;
|
---|
46 | }
|
---|
47 | rc = DosRequestMutexSem(logmutex, -1L);
|
---|
48 | if (rc)
|
---|
49 | {
|
---|
50 | return 0;
|
---|
51 | }
|
---|
52 | rc = 1;
|
---|
53 | do
|
---|
54 | {
|
---|
55 | FILE * f;
|
---|
56 | struct timeval tv;
|
---|
57 | time_t t;
|
---|
58 | char buf[80] = {0};
|
---|
59 | if (logfile)
|
---|
60 | {
|
---|
61 | f = fopen(logfile, "a");
|
---|
62 | if (!f)
|
---|
63 | {
|
---|
64 | rc = 0;
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | else
|
---|
69 | {
|
---|
70 | f = stdout;
|
---|
71 | }
|
---|
72 | gettimeofday(&tv, NULL);
|
---|
73 | t = time(NULL);
|
---|
74 | // strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
|
---|
75 | strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime(&t));
|
---|
76 | fprintf(f, "%s.%d: %d %d: %s:%s(%d) :", buf, tv.tv_usec / 10000, level, (long)_gettid(), file, func, line);
|
---|
77 | if (logfile)
|
---|
78 | {
|
---|
79 | fclose(f);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | while (0);
|
---|
83 | DosReleaseMutexSem(logmutex);
|
---|
84 | return rc;
|
---|
85 | }
|
---|
86 |
|
---|
87 | int debugmessage(char * fmt, ...)
|
---|
88 | {
|
---|
89 | int rc;
|
---|
90 | rc = DosRequestMutexSem(logmutex, -1L);
|
---|
91 | if (rc)
|
---|
92 | {
|
---|
93 | return 0;
|
---|
94 | }
|
---|
95 | do
|
---|
96 | {
|
---|
97 | FILE * f;
|
---|
98 | va_list args;
|
---|
99 | if (logfile)
|
---|
100 | {
|
---|
101 | f = fopen(logfile, "a");
|
---|
102 | if (!f)
|
---|
103 | {
|
---|
104 | break;
|
---|
105 | }
|
---|
106 | }
|
---|
107 | else
|
---|
108 | {
|
---|
109 | f = stdout;
|
---|
110 | }
|
---|
111 | va_start(args, fmt);
|
---|
112 | vfprintf(f, fmt, args);
|
---|
113 | va_end(args);
|
---|
114 | if (logfile)
|
---|
115 | {
|
---|
116 | fclose(f);
|
---|
117 | }
|
---|
118 | }
|
---|
119 | while (0);
|
---|
120 | DosReleaseMutexSem(logmutex);
|
---|
121 | return 0;
|
---|
122 | }
|
---|
123 |
|
---|
124 | void debuglocal(int level, const char * fmt, ...)
|
---|
125 | {
|
---|
126 | int rc;
|
---|
127 | if (level > debuglevel)
|
---|
128 | {
|
---|
129 | return;
|
---|
130 | }
|
---|
131 | rc = DosRequestMutexSem(logmutex, -1L);
|
---|
132 | if (rc)
|
---|
133 | {
|
---|
134 | return;
|
---|
135 | }
|
---|
136 | do
|
---|
137 | {
|
---|
138 | FILE * f;
|
---|
139 | struct timeval tv;
|
---|
140 | char buf[80] = {0};
|
---|
141 | va_list args;
|
---|
142 | if (logfile)
|
---|
143 | {
|
---|
144 | f = fopen(logfile, "a");
|
---|
145 | if (!f)
|
---|
146 | {
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | }
|
---|
150 | else
|
---|
151 | {
|
---|
152 | f = stdout;
|
---|
153 | }
|
---|
154 | gettimeofday(&tv, NULL);
|
---|
155 | strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
|
---|
156 | fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid());
|
---|
157 | va_start(args, fmt);
|
---|
158 | vfprintf(f, fmt, args);
|
---|
159 | va_end(args);
|
---|
160 | if (logfile)
|
---|
161 | {
|
---|
162 | fclose(f);
|
---|
163 | }
|
---|
164 | }
|
---|
165 | while (0);
|
---|
166 | DosReleaseMutexSem(logmutex);
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|