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