15 |
|
|
16 |
|
|
17 |
extern conn_t connpri, connaux; |
extern conn_t connpri, connaux; |
18 |
extern char logfile[PATH_MAX]; |
extern opts_t opts; |
|
extern unsigned int options; |
|
|
extern int verbosity; |
|
19 |
extern unsigned int flags; |
extern unsigned int flags; |
20 |
|
|
21 |
static FILE *debugfp = NULL; /* Pointer to debug file. */ |
static FILE *debugfp = NULL; /* Pointer to debug file. */ |
34 |
{ |
{ |
35 |
va_list args; |
va_list args; |
36 |
|
|
37 |
if (verbosity == -2) |
if (opts.verbosity == -2) |
38 |
return; |
return; |
39 |
|
|
40 |
va_start(args, info); |
va_start(args, info); |
51 |
{ |
{ |
52 |
va_list args; |
va_list args; |
53 |
|
|
54 |
if (verbosity == 2) { |
if (opts.verbosity == 2) { |
55 |
va_start(args, info); |
va_start(args, info); |
56 |
vprintf(info, args); |
vprintf(info, args); |
57 |
va_end(args); |
va_end(args); |
67 |
{ |
{ |
68 |
va_list args; |
va_list args; |
69 |
|
|
70 |
if ((options & OPTION_DEBUG) && debugfp) { |
if (opts.debug && debugfp) { |
71 |
va_start(args, debug); |
va_start(args, debug); |
72 |
vfprintf(debugfp, debug, args); |
vfprintf(debugfp, debug, args); |
73 |
fflush(debugfp); |
fflush(debugfp); |
89 |
fprintf(stderr, "imapfilter: "); |
fprintf(stderr, "imapfilter: "); |
90 |
vfprintf(stderr, errmsg, args); |
vfprintf(stderr, errmsg, args); |
91 |
|
|
92 |
if ((options & OPTION_ERRORS) && logfp) { |
if (opts.errors && logfp) { |
93 |
vfprintf(logfp, errmsg, args); |
vfprintf(logfp, errmsg, args); |
94 |
fflush(logfp); |
fflush(logfp); |
95 |
} |
} |
160 |
static char dt[] = PATHNAME_DEBUG_FILE; |
static char dt[] = PATHNAME_DEBUG_FILE; |
161 |
int fd; |
int fd; |
162 |
|
|
163 |
if (!(options & OPTION_DEBUG)) |
if (!opts.debug) |
164 |
return 0; |
return 0; |
165 |
|
|
166 |
fd = mkstemp(dt); |
fd = mkstemp(dt); |
168 |
if (fd != -1) { |
if (fd != -1) { |
169 |
debugfp = fdopen(fd, "w"); |
debugfp = fdopen(fd, "w"); |
170 |
if (debugfp == NULL) { |
if (debugfp == NULL) { |
171 |
error("opening debug file %s: %s\n", logfile, |
error("opening debug file %s: %s\n", opts.logfile, |
172 |
strerror(errno)); |
strerror(errno)); |
173 |
return ERROR_TRIVIAL; |
return ERROR_TRIVIAL; |
174 |
} |
} |
196 |
int |
int |
197 |
log_start(void) |
log_start(void) |
198 |
{ |
{ |
199 |
if (*logfile == '\0') |
if (*opts.logfile == '\0') |
200 |
return 0; /* Logging not enabled. */ |
return 0; /* Logging not enabled. */ |
201 |
|
|
202 |
debug("log file: '%s'\n", logfile); |
debug("log file: '%s'\n", opts.logfile); |
203 |
|
|
204 |
if (create_file(logfile, S_IRUSR | S_IWUSR)) |
if (create_file(opts.logfile, S_IRUSR | S_IWUSR)) |
205 |
return ERROR_TRIVIAL; |
return ERROR_TRIVIAL; |
206 |
|
|
207 |
logfp = fopen(logfile, "a"); |
logfp = fopen(opts.logfile, "a"); |
208 |
if (logfp == NULL) { |
if (logfp == NULL) { |
209 |
error("opening log file %s: %s\n", logfile, strerror(errno)); |
error("opening log file %s: %s\n", opts.logfile, |
210 |
|
strerror(errno)); |
211 |
return ERROR_TRIVIAL; |
return ERROR_TRIVIAL; |
212 |
} |
} |
213 |
return 0; |
return 0; |