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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/* Logging locking and interface presented to vty et al
* Copyright (C) 2011 Chris Hall (GMCH), Highwayman
*
* This file is part of GNU Zebra.
*
* GNU Zebra is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* GNU Zebra is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef _ZEBRA_LOG_LOCAL_H
#define _ZEBRA_LOG_LOCAL_H
#include "misc.h"
#include "log_common.h"
#include "qpthreads.h"
/*==============================================================================
* This is for access to some things in log.c which are not required
* by external users, who use log.h.
*
* This is for use within the log/command/vty family.
*
* Should not be used with log.h ! (Except in log.c itself.)
*
* This may duplicate things published in log.h, but also includes things
* which are not intended for "external" use.
*/
/*==============================================================================
* To make logging qpthread safe we use a single mutex.
*
* A normal mutex is used -- recursion is not expected or required.
*
* There are some "ulog" functions which assume the mutex is locked.
*
* It is assumed that while the log_mutex is owned, NO OTHER SIGNIFICANT lock
* will be acquired -- in particular, NOT the VTY_LOCK() !!
*/
extern qpt_mutex_t log_mutex ;
/*------------------------------------------------------------------------------
* Sort out LOG_DEBUG.
*
* Set to 1 if defined, but blank.
* Set to QDEBUG if not defined.
*
* Force to 0 if LOG_NO_DEBUG is defined and not zero.
*
* So: defaults to same as QDEBUG, but no matter what QDEBUG is set to:
*
* * can set LOG_DEBUG == 0 to turn off debug
* * or set LOG_DEBUG != 0 to turn on debug
* * or set LOG_NO_DEBUG != 0 to force debug off
*/
#ifdef LOG_DEBUG /* If defined, make it 1 or 0 */
# if IS_BLANK_OPTION(LOG_DEBUG)
# undef LOG_DEBUG
# define LOG_DEBUG 1
# endif
#else /* If not defined, follow QDEBUG */
# define LOG_DEBUG QDEBUG
#endif
#ifdef LOG_NO_DEBUG /* Override, if defined */
# if IS_NOT_ZERO_OPTION(LOG_NO_DEBUG)
# undef LOG_DEBUG
# define LOG_DEBUG 0
# endif
#endif
enum { log_debug = LOG_DEBUG } ;
/*------------------------------------------------------------------------------
* Locking and related functions.
*/
extern int log_lock_count ;
Inline void
LOG_LOCK(void) /* if is qpthreads_enabled, lock log_mutex */
{
qpt_mutex_lock(log_mutex) ;
if (log_debug)
++log_lock_count ;
} ;
Inline void
LOG_UNLOCK(void) /* if is qpthreads_enabled, unlock log_mutex */
{
if (log_debug)
--log_lock_count ;
qpt_mutex_unlock(log_mutex) ;
} ;
/* For debug (and documentation) purposes, will LOG_ASSERT_LOCKED where that
* is required.
*
* Note that both these checks will pass if !qpthreads_enabled. So can have
* code which is called before qpthreads are started up, or which will never
* run qpthreaded !
*/
extern int log_assert_fail ;
Inline void
LOG_ASSERT_FAILED(void)
{
if (log_assert_fail == 0) ;
{
log_assert_fail = 1 ;
assert(0) ;
} ;
} ;
Inline void
LOG_ASSERT_LOCKED(void)
{
if (log_debug)
if ((log_lock_count == 0) && (qpthreads_enabled))
LOG_ASSERT_FAILED() ;
} ;
/*==============================================================================
* Functions in log.c -- used in any of the log/command/vty
*/
extern void log_init_r(void) ;
extern void log_finish(void);
extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
char *buf, size_t buflen);
extern void uzlog_set_monitor(struct zlog *zl, int level) ;
extern int uzlog_get_monitor_lvl(struct zlog *zl) ;
extern int zlog_set_file(struct zlog *zl, const char *filename, int log_level);
extern int zlog_reset_file(struct zlog *zl);
extern int zlog_get_default_lvl (struct zlog *zl);
extern void zlog_set_default_lvl (struct zlog *zl, int level);
extern void zlog_set_default_lvl_dest (struct zlog *zl, int level);
extern int zlog_get_maxlvl (struct zlog *zl, zlog_dest_t dest);
extern int zlog_get_facility (struct zlog *zl);
extern void zlog_set_facility (struct zlog *zl, int facility);
extern bool zlog_get_record_priority (struct zlog *zl);
extern void zlog_set_record_priority (struct zlog *zl, bool record_priority);
extern int zlog_get_timestamp_precision (struct zlog *zl);
extern void zlog_set_timestamp_precision (struct zlog *zl, int timestamp_precision);
extern const char * zlog_get_ident (struct zlog *zl);
extern char * zlog_get_filename (struct zlog *zl);
extern bool zlog_is_file (struct zlog *zl);
#endif /* _ZEBRA_LOG_LOCAL_H */
|