1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/* util.c ....... error message utilities.
* C. Scott Ananian <cananian@alumni.princeton.edu>
*
* $Id: util.c,v 1.1.1.1 2002/07/25 06:52:39 honor Exp $
*/
#include <stdio.h>
#include <stdarg.h>
#include <syslog.h>
#include <unistd.h>
#include <stdlib.h>
#include "util.h"
#ifndef PROGRAM_NAME
#define PROGRAM_NAME "pptp"
#endif
static void open_log(void) __attribute__ ((constructor));
static void close_log(void) __attribute__ ((destructor));
static void open_log(void) {
openlog(PROGRAM_NAME, LOG_PID, LOG_DAEMON);
}
static void close_log(void) {
closelog();
}
#define MAKE_STRING(label) \
va_list ap; \
char buf[256], string[256]; \
va_start(ap, format); \
vsnprintf(buf, sizeof(buf), format, ap); \
snprintf(string, sizeof(string), "%s[%s:%s:%d]: %s", \
label, func, file, line, buf); \
va_end(ap)
void _log(char *func, char *file, int line, char *format, ...) {
MAKE_STRING("log");
syslog(LOG_NOTICE, "%s", string);
}
void _warn(char *func, char *file, int line, char *format, ...) {
MAKE_STRING("warn");
fprintf(stderr, "%s\n", string);
syslog(LOG_NOTICE, "%s", string);
}
void _fatal(char *func, char *file, int line, char *format, ...) {
MAKE_STRING("fatal");
fprintf(stderr, "%s\n", string);
syslog(LOG_NOTICE, "%s", string);
exit(1);
}
|