OSDN Git Service

b4efe7c9649754a7125954074b4631ef82919570
[linuxjm/LDP_man-pages.git] / original / man2 / syslog.2
1 .\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
26 .\" 2008-02-15, Jeremy Kerr <jk@ozlabs.org>
27 .\"     Add info on command type 10; add details on types 6, 7, 8, & 9.
28 .\" 2008-02-15, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\"     Update LOG_BUF_LEN details; update RETURN VALUE section.
30 .\"
31 .TH SYSLOG 2  2012-11-29 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 syslog, klogctl \- read and/or clear kernel message ring buffer;
34 set console_loglevel
35 .SH SYNOPSIS
36 .nf
37 .BI "int syslog(int " type ", char *" bufp ", int " len );
38 .B  "                /* No wrapper provided in glibc */"
39 .sp
40 /* The glibc interface */
41 .br
42 .B "#include <sys/klog.h>"
43 .sp
44 .BI "int klogctl(int " type ", char *" bufp ", int " len );
45 .fi
46 .SH DESCRIPTION
47 If you need the C library function
48 .BR syslog ()
49 (which talks to
50 .BR syslogd (8)),
51 then look at
52 .BR syslog (3).
53 The system call of this name is about controlling the kernel
54 .IR printk ()
55 buffer, and the glibc wrapper function is called
56 .BR klogctl ().
57 .SS The kernel log buffer
58 The kernel has a cyclic buffer of length
59 .B LOG_BUF_LEN
60 in which messages given as arguments to the kernel function
61 .BR printk ()
62 are stored (regardless of their loglevel).
63 In early kernels,
64 .B LOG_BUF_LEN
65 had the value 4096;
66 from kernel 1.3.54, it was 8192;
67 from kernel 2.1.113 it was 16384;
68 since 2.4.23/2.6 the value is a kernel configuration option
69 .RB ( CONFIG_LOG_BUF_SHIFT ).
70 .\" Under "General setup" ==> "Kernel log buffer size"
71 .\" For 2.6, precisely the option seems to have appeared in 2.5.55.
72 In recent kernels the size can be queried with command type 10 (see below).
73 .SS Commands
74 The \fItype\fP argument determines the action taken by this function.
75 The list below specifies the values for
76 .IR type .
77 The symbolic names are defined in the kernel source,
78 but are not exported to user space;
79 you will either need to use the numbers, or define the names yourself.
80 .TP
81 .BR SYSLOG_ACTION_CLOSE " (0)"
82 Close the log.
83 Currently a NOP.
84 .TP
85 .BR SYSLOG_ACTION_OPEN " (1)"
86 Open the log.
87 Currently a NOP.
88 .TP
89 .BR SYSLOG_ACTION_READ " (2)"
90 Read from the log.
91 The call
92 waits until the kernel log buffer is nonempty, and then reads
93 at most \fIlen\fP bytes into the buffer pointed to by
94 .IR bufp .
95 The call returns the number of bytes read.
96 Bytes read from the log disappear from the log buffer:
97 the information can be read only once.
98 This is the function executed by the kernel when a user program reads
99 .IR /proc/kmsg .
100 .TP
101 .BR SYSLOG_ACTION_READ_ALL " (3)"
102 Read all messages remaining in the ring buffer,
103 placing then in the buffer pointed to by
104 .IR bufp .
105 The call reads the last \fIlen\fP
106 bytes from the log buffer (nondestructively),
107 but will not read more than was written into the buffer since the
108 last "clear ring buffer" command (see command 5 below)).
109 The call returns the number of bytes read.
110 .TP
111 .BR SYSLOG_ACTION_READ_CLEAR " (4)"
112 Read and clear all messages remaining in the ring buffer.
113 The call does precisely the same as for a
114 .I type
115 of 3, but also executes the "clear ring buffer" command.
116 .TP
117 .BR SYSLOG_ACTION_CLEAR " (5)"
118 The call executes just the "clear ring buffer" command.
119 The
120 .I bufp
121 and
122 .I len
123 arguments are ignored.
124 .IP
125 This command does not really clear the ring buffer.
126 Rather, it sets a kernel bookkeeping variable that
127 determines the results returned by commands 3
128 .RB ( SYSLOG_ACTION_READ_ALL )
129 and 4
130 .RB ( SYSLOG_ACTION_READ_CLEAR ).
131 This command has no effect on commands 2
132 .RB ( SYSLOG_ACTION_READ )
133 and 9
134 .RB ( SYSLOG_ACTION_SIZE_UNREAD ).
135 .TP
136 .BR SYSLOG_ACTION_CONSOLE_OFF " (6)"
137 Disable printk to console.
138 The call sets the console log level to the minimum,
139 so that no messages are printed to the console.
140 The
141 .I bufp
142 and
143 .I len
144 arguments are ignored.
145 .TP
146 .BR SYSLOG_ACTION_CONSOLE_ON " (7)"
147 The call sets the console log level to the default,
148 so that messages are printed to the console.
149 The
150 .I bufp
151 and
152 .I len
153 arguments are ignored.
154 .TP
155 .BR SYSLOG_ACTION_CONSOLE_LEVEL " (8)"
156 The call sets the console log level to the value given in
157 .IR len ,
158 which must be an integer between 1 and 8 (inclusive).
159 See the
160 .B loglevel
161 section for details.
162 The
163 .I bufp
164 argument is ignored.
165 .TP
166 .BR SYSLOG_ACTION_SIZE_UNREAD " (9) (since Linux 2.4.10)"
167 The call
168 returns the number of bytes currently available to be read
169 from the kernel log buffer via command 2
170 .RB ( SYSLOG_ACTION_READ ).
171 The
172 .I bufp
173 and
174 .I len
175 arguments are ignored.
176 .TP
177 .BR SYSLOG_ACTION_SIZE_BUFFER " (10) (since Linux 2.6.6)"
178 This command returns the total size of the kernel log buffer.
179 The
180 .I bufp
181 and
182 .I len
183 arguments are ignored.
184 .PP
185 All commands except 3 and 10 require privilege.
186 In Linux kernels before 2.6.37,
187 command types 3 and 10 are allowed to unprivileged processes;
188 since Linux 2.6.37,
189 these commands are allowed to unprivileged processes only if
190 .IR /proc/sys/kernel/dmesg_restrict
191 has the value 0.
192 Before Linux 2.6.37, "privileged" means that the caller has the
193 .BR CAP_SYS_ADMIN
194 capability.
195 Since Linux 2.6.37,
196 "privileged" means that the caller has either the
197 .BR CAP_SYS_ADMIN
198 capability (now deprecated for this purpose) or the (new)
199 .BR CAP_SYSLOG
200 capability.
201 .SS The loglevel
202 The kernel routine
203 .BR printk ()
204 will only print a message on the
205 console, if it has a loglevel less than the value of the variable
206 .IR console_loglevel .
207 This variable initially has the value
208 .B DEFAULT_CONSOLE_LOGLEVEL
209 (7), but is set to 10 if the
210 kernel command line contains the word "debug", and to 15 in case
211 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
212 This variable is set (to a value in the range 1-8) by a
213 .BR syslog ()
214 call with a
215 .I type
216 of 8.
217 Calls to
218 .BR syslog ()
219 with
220 .I type
221 equal to 6 or 7 set the variable to 1 (kernel panics only)
222 or 7 (all except debugging messages), respectively.
223
224 Every text line in a message has its own loglevel.
225 This level is
226 .I "DEFAULT_MESSAGE_LOGLEVEL \- 1"
227 (6) unless the line starts with <d>
228 where \fId\fP is a digit in the range 1-7, in which case the level
229 is \fId\fP.
230 The conventional meaning of the loglevel is defined in
231 .I <linux/kernel.h>
232 as follows:
233
234 .nf
235 #define KERN_EMERG    "<0>"  /* system is unusable               */
236 #define KERN_ALERT    "<1>"  /* action must be taken immediately */
237 #define KERN_CRIT     "<2>"  /* critical conditions              */
238 #define KERN_ERR      "<3>"  /* error conditions                 */
239 #define KERN_WARNING  "<4>"  /* warning conditions               */
240 #define KERN_NOTICE   "<5>"  /* normal but significant condition */
241 #define KERN_INFO     "<6>"  /* informational                    */
242 #define KERN_DEBUG    "<7>"  /* debug-level messages             */
243 .fi
244 .SH RETURN VALUE
245 For \fItype\fP equal to 2, 3, or 4, a successful call to
246 .BR syslog ()
247 returns the number
248 of bytes read.
249 For \fItype\fP 9,
250 .BR syslog ()
251 returns the number of bytes currently
252 available to be read on the kernel log buffer.
253 For \fItype\fP 10,
254 .BR syslog ()
255 returns the total size of the kernel log buffer.
256 For other values of \fItype\fP, 0 is returned on success.
257
258 In case of error, \-1 is returned,
259 and \fIerrno\fP is set to indicate the error.
260 .SH ERRORS
261 .TP
262 .B EINVAL
263 Bad arguments (e.g.,
264 bad
265 .IR type ;
266 or for
267 .I type
268 2, 3, or 4,
269 .I buf
270 is NULL,
271 or
272 .I len
273 is less than zero; or for
274 .I type
275 8, the
276 .I level
277 is outside the range 1 to 8).
278 .TP
279 .B ENOSYS
280 This
281 .BR syslog ()
282 system call is not available, because the kernel was compiled with the
283 .BR CONFIG_PRINTK
284 kernel-configuration option disabled.
285 .TP
286 .B EPERM
287 An attempt was made to change console_loglevel or clear the kernel
288 message ring buffer by a process without sufficient privilege
289 (more precisely: without the
290 .B CAP_SYS_ADMIN
291 or
292 .BR CAP_SYSLOG
293 capability).
294 .TP
295 .B ERESTARTSYS
296 System call was interrupted by a signal; nothing was read.
297 (This can be seen only during a trace.)
298 .SH CONFORMING TO
299 This system call is Linux-specific and should not be used in programs
300 intended to be portable.
301 .SH NOTES
302 From the very start people noted that it is unfortunate that
303 a system call and a library routine of the same name are entirely
304 different animals.
305 .\" In libc4 and libc5 the number of this call was defined by
306 .\" .BR SYS_klog .
307 .\" In glibc 2.0 the syscall is baptized
308 .\" .BR klogctl ().
309 .SH SEE ALSO
310 .BR syslog (3),
311 .BR capabilities (7)
312 .SH COLOPHON
313 This page is part of release 3.67 of the Linux
314 .I man-pages
315 project.
316 A description of the project,
317 information about reporting bugs,
318 and the latest version of this page,
319 can be found at
320 \%http://www.kernel.org/doc/man\-pages/.