37 |
va_start(arglist, fmt); |
va_start(arglist, fmt); |
38 |
vfprintf(stderr, fmt, arglist); |
vfprintf(stderr, fmt, arglist); |
39 |
va_end(arglist); |
va_end(arglist); |
40 |
fprintf(stderr, "\n"); |
fputc('\n', stderr); |
41 |
} |
} |
42 |
|
|
43 |
void |
void |
44 |
info(int mode, const char *fmt, ...) |
info(int mode, const char *fmt, ...) |
45 |
{ |
{ |
46 |
va_list arglist; |
va_list arglist; |
47 |
char txt[LINEBUFFER+1]; |
char msg[LINEBUFFER+1]; |
48 |
|
|
49 |
if (mode > options.termlevel) |
if (mode > options.termlevel) |
50 |
return; |
return; |
51 |
|
|
52 |
va_start(arglist, fmt); |
va_start(arglist, fmt); |
53 |
vsnprintf(txt, LINEBUFFER, fmt, arglist); |
vsnprintf(msg, LINEBUFFER, fmt, arglist); |
54 |
va_end(arglist); |
va_end(arglist); |
55 |
|
|
56 |
#ifdef HAVE_SYSLOG |
#ifdef HAVE_SYSLOG |
57 |
if ((topt & T_DAEMON) && !(topt & T_FOREGROUND)) { |
if ((topt & T_DAEMON) && !(topt & T_FOREGROUND)) { |
58 |
if (options.slogfile) |
syslog(LOG_INFO | LOG_MAIL, msg); |
|
filelog(options.slogfile, txt); |
|
|
else |
|
|
syslog(LOG_INFO | LOG_MAIL, txt); |
|
|
|
|
59 |
if (options.ulogfile && options.uloglevel >= ALL) |
if (options.ulogfile && options.uloglevel >= ALL) |
60 |
filelog(options.ulogfile, txt); |
filelog(options.ulogfile, msg); |
61 |
} |
} |
62 |
else |
else |
63 |
#endif /* HAVE_SYSLOG */ |
#endif /* HAVE_SYSLOG */ |
64 |
if (topt & T_FOREGROUND) |
if (topt & T_FOREGROUND) |
65 |
mprintf("> [%d] %s", (int)getpid(), txt); |
mprintf("> [%d] %s", (int)getpid(), msg); |
66 |
else |
else |
67 |
mprintf("> %s", txt); |
mprintf("> %s", msg); |
|
return; |
|
68 |
} |
} |
69 |
|
|
70 |
void |
void |
71 |
filelog(char *logfile, char *txt) |
filelog(char *logfile, char *msg) |
72 |
{ |
{ |
73 |
FILE *fplog; |
FILE *fplog; |
74 |
|
|
85 |
timeptr = localtime(&tp); |
timeptr = localtime(&tp); |
86 |
strftime(timebuf, sizeof(timebuf) - 1, |
strftime(timebuf, sizeof(timebuf) - 1, |
87 |
"%a, %d %b %Y %H:%M:%S", timeptr); |
"%a, %d %b %Y %H:%M:%S", timeptr); |
88 |
fprintf(fplog, "%s [%d] %s\n", timebuf, (int)getpid(), txt); |
fprintf(fplog, "%s [%d] %s\n", timebuf, (int)getpid(), msg); |
89 |
fclose(fplog); |
fclose(fplog); |
90 |
} |
} |
91 |
} |
} |
95 |
{ |
{ |
96 |
va_list ap; |
va_list ap; |
97 |
int n = 0; |
int n = 0; |
98 |
char txt[LINEBUFFER+1]; |
char msg[LINEBUFFER+1]; |
99 |
|
|
100 |
if (options.termlevel < VERBOSE) |
if (options.termlevel < VERBOSE) |
101 |
return; |
return; |
102 |
|
|
103 |
if (loc) |
if (loc) |
104 |
n = snprintf(txt, sizeof(txt), "%s:%lu: ", |
n = snprintf(msg, LINEBUFFER, "%s:%lu: ", |
105 |
loc->file, (unsigned long)loc->line); |
loc->file, (unsigned long)loc->line); |
106 |
va_start(ap, fmt); |
va_start(ap, fmt); |
107 |
vsnprintf(txt + n, LINEBUFFER - n, fmt, ap); |
vsnprintf(msg + n, LINEBUFFER - n, fmt, ap); |
108 |
va_end(ap); |
va_end(ap); |
109 |
info(VERBOSE, "%s", txt); |
info(VERBOSE, "%s", msg); |
110 |
} |
} |
111 |
|
|
112 |
/* EOF */ |
/* EOF */ |