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