]>
Commit | Line | Data |
---|---|---|
282113ba CV |
1 | /* bsd_log.cc |
2 | ||
1dcd520b | 3 | Copyright 2003, 2004 Red Hat Inc. |
282113ba CV |
4 | |
5 | This file is part of Cygwin. | |
6 | ||
7 | This software is a copyrighted work licensed under the terms of the | |
8 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
9 | details. */ | |
10 | #ifdef __OUTSIDE_CYGWIN__ | |
11 | #include "woutsup.h" | |
12 | #define _KERNEL 1 | |
13 | #define __BSD_VISIBLE 1 | |
14 | #include <sys/smallprint.h> | |
15 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | ||
18 | long log_level = 8; /* Illegal value. Don't change! */ | |
19 | tun_bool_t log_debug = TUN_UNDEF; | |
20 | tun_bool_t log_syslog = TUN_UNDEF; | |
21 | tun_bool_t log_stderr = TUN_UNDEF; | |
22 | ||
23 | void | |
24 | loginit (tun_bool_t opt_stderr, tun_bool_t opt_syslog) | |
25 | { | |
26 | if (log_debug == TUN_UNDEF) | |
27 | TUNABLE_BOOL_FETCH ("kern.log.debug", &log_debug); | |
28 | if (log_debug == TUN_UNDEF) | |
29 | log_debug = TUN_FALSE; | |
30 | ||
31 | if (opt_stderr != TUN_UNDEF) | |
32 | log_stderr = opt_stderr; | |
33 | else | |
34 | TUNABLE_BOOL_FETCH ("kern.log.stderr", &log_stderr); | |
35 | if (log_stderr == TUN_UNDEF) | |
36 | log_stderr = TUN_FALSE; | |
37 | ||
38 | if (opt_syslog != TUN_UNDEF) | |
39 | log_syslog = opt_syslog; | |
40 | else | |
41 | TUNABLE_BOOL_FETCH ("kern.log.syslog", &log_syslog); | |
42 | if (log_syslog == TUN_UNDEF) | |
43 | log_syslog = TUN_FALSE; | |
44 | ||
45 | if (log_level == 8) | |
46 | TUNABLE_INT_FETCH ("kern.log.level", &log_level); | |
47 | if (log_level == 8) | |
48 | log_level = 6; | |
49 | } | |
50 | ||
51 | void | |
52 | _vlog (const char *file, int line, int level, | |
53 | const char *fmt, va_list ap) | |
54 | { | |
55 | char buf[16384]; | |
56 | ||
57 | if ((level == LOG_DEBUG && log_debug != TUN_TRUE) | |
58 | || (level != LOG_DEBUG && level >= log_level)) | |
59 | return; | |
60 | strcpy (buf, "cygserver: "); | |
61 | if (file && log_debug == TUN_TRUE) | |
62 | __small_sprintf (strchr (buf, '\0'), "%s, line %d: ", file, line); | |
63 | __small_vsprintf (strchr (buf, '\0'), fmt, ap); | |
64 | if (log_syslog == TUN_TRUE && level != LOG_DEBUG) | |
65 | syslog (level, buf); | |
66 | if (log_stderr == TUN_TRUE || level == LOG_DEBUG) | |
67 | { | |
68 | fputs (buf, stderr); | |
69 | fputc ('\n', stderr); | |
70 | } | |
71 | } | |
72 | ||
73 | void | |
74 | _log (const char *file, int line, int level, const char *fmt, ...) | |
75 | { | |
76 | va_list ap; | |
77 | va_start (ap, fmt); | |
78 | _vlog (file, line, level, fmt, ap); | |
79 | } | |
80 | ||
81 | void | |
82 | _vpanic (const char *file, int line, const char *fmt, va_list ap) | |
83 | { | |
8032f815 | 84 | _vlog (file, line, LOG_CRIT, fmt, ap); |
282113ba CV |
85 | exit (1); |
86 | } | |
87 | ||
88 | void | |
89 | _panic (const char *file, int line, const char *fmt, ...) | |
90 | { | |
91 | va_list ap; | |
92 | va_start (ap, fmt); | |
93 | _vpanic (file, line, fmt, ap); | |
94 | } | |
95 | #endif /* __OUTSIDE_CYGWIN__ */ |