OSDN Git Service

fb018a6377bc2ad7df2065aac5527ccb3f361df5
[linuxjm/LDP_man-pages.git] / original / 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  2008-06-20 "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 version is called
54 .BR klogctl ().
55
56 The \fItype\fP argument determines the action taken by this function.
57
58 Quoting from
59 .IR kernel/printk.c :
60 .nf
61 /*
62  * Commands to sys_syslog:
63  *
64  *      0 \-\- Close the log.  Currently a NOP.
65  *      1 \-\- Open the log. Currently a NOP.
66  *      2 \-\- Read from the log.
67  *      3 \-\- Read all messages remaining in the ring buffer.
68  *      4 \-\- Read and clear all messages remaining in the ring buffer
69  *      5 \-\- Clear ring buffer.
70  *      6 \-\- Disable printk to console
71  *      7 \-\- Enable printk to console
72  *      8 \-\- Set level of messages printed to console
73  *      9 \-\- Return number of unread characters in the log buffer
74  *     10 \-\- Return size of the log buffer
75  */
76 .fi
77
78 Only command types 3 and 10 are allowed to unprivileged processes.
79 Type 9 was added in 2.4.10; type 10 in 2.6.6.
80 .SS The kernel log buffer
81 The kernel has a cyclic buffer of length
82 .B LOG_BUF_LEN
83 in which messages given as arguments to the kernel function
84 .BR printk ()
85 are stored (regardless of their loglevel).
86 In early kernels,
87 .B LOG_BUF_LEN
88 had the value 4096;
89 from kernel 1.3.54, it was 8192;
90 from kernel 2.1.113 it was 16384;
91 since 2.4.23/2.6 the value is a kernel configuration option.
92 .\" Under "General setup" ==> "Kernel log buffer size"
93 .\" For 2.6, precisely the option seems to have appeared in 2.5.55.
94 In recent kernels the size can be queried with command type 10.
95
96 The call
97 .I "syslog(2,buf,len)"
98 waits until this kernel log buffer is nonempty, and then reads
99 at most \fIlen\fP bytes into the buffer \fIbuf\fP.
100 It returns
101 the number of bytes read.
102 Bytes read from the log disappear from
103 the log buffer: the information can only be read once.
104 This is the function executed by the kernel when a user program
105 reads
106 .IR /proc/kmsg .
107
108 The call
109 .I syslog(3,buf,len)
110 will read the last \fIlen\fP bytes from the log buffer (nondestructively),
111 but will not read more than was written into the buffer since the
112 last "clear ring buffer" command (which does not clear the buffer at all).
113 It returns the number of bytes read.
114
115 The call
116 .I syslog(4,buf,len)
117 does precisely the same, but also executes the "clear ring buffer" command.
118
119 The call
120 .I syslog(5,dummy,dummy)
121 executes just the "clear ring buffer" command.
122 (In each call where
123 .I buf
124 or
125 .I len
126 is shown as "dummy", the value of the argument is ignored by the call.)
127
128 The call
129 .I syslog(6,dummy,dummy)
130 sets the console log level to minimum, so that no messages are printed
131 to the console.
132
133 The call
134 .I syslog(7,dummy,dummy)
135 sets the console log level to default, so that messages are printed
136 to the console.
137
138 The call
139 .I syslog(8,dummy,level)
140 sets the console log level to
141 .IR level ,
142 which must be an integer between 1 and 8 (inclusive).
143 See the
144 .B loglevel
145 section for details.
146
147 The call
148 .I syslog(9,dummy,dummy)
149 returns the number of bytes currently available to be read
150 on the kernel log buffer.
151
152 The call
153 .I syslog(10,dummy,dummy)
154 returns the total size of the kernel log buffer.
155 .SS The loglevel
156 The kernel routine
157 .BR printk ()
158 will only print a message on the
159 console, if it has a loglevel less than the value of the variable
160 .IR console_loglevel .
161 This variable initially has the value
162 .B DEFAULT_CONSOLE_LOGLEVEL
163 (7), but is set to 10 if the
164 kernel command line contains the word "debug", and to 15 in case
165 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
166 This variable is set (to a value in the range 1-8) by the call
167 .IR syslog(8,dummy,value) .
168 The calls
169 .I syslog(type,dummy,dummy)
170 with \fItype\fP equal to 6 or 7, set it to 1 (kernel panics only)
171 or 7 (all except debugging messages), respectively.
172
173 Every text line in a message has its own loglevel.
174 This level is
175 .I "DEFAULT_MESSAGE_LOGLEVEL \- 1"
176 (6) unless the line starts with <d>
177 where \fId\fP is a digit in the range 1-7, in which case the level
178 is \fId\fP.
179 The conventional meaning of the loglevel is defined in
180 .I <linux/kernel.h>
181 as follows:
182
183 .nf
184 #define KERN_EMERG    "<0>"  /* system is unusable               */
185 #define KERN_ALERT    "<1>"  /* action must be taken immediately */
186 #define KERN_CRIT     "<2>"  /* critical conditions              */
187 #define KERN_ERR      "<3>"  /* error conditions                 */
188 #define KERN_WARNING  "<4>"  /* warning conditions               */
189 #define KERN_NOTICE   "<5>"  /* normal but significant condition */
190 #define KERN_INFO     "<6>"  /* informational                    */
191 #define KERN_DEBUG    "<7>"  /* debug-level messages             */
192 .fi
193 .SH "RETURN VALUE"
194 For \fItype\fP equal to 2, 3, or 4, a successful call to
195 .BR syslog ()
196 returns the number
197 of bytes read.
198 For \fItype\fP 9,
199 .BR syslog ()
200 returns the number of bytes currently
201 available to be read on the kernel log buffer.
202 For \fItype\fP 10,
203 .BR syslog ()
204 returns the total size of the kernel log buffer.
205 For other values of \fItype\fP, 0 is returned on success.
206
207 In case of error, \-1 is returned,
208 and \fIerrno\fP is set to indicate the error.
209 .SH ERRORS
210 .TP
211 .B EINVAL
212 Bad arguments (e.g.,
213 bad
214 .IR type ;
215 or for
216 .I type
217 2, 3, or 4,
218 .I buf
219 is NULL,
220 or
221 .I len
222 is less than zero; or for
223 .I type
224 8, the
225 .I level
226 is outside the range 1 to 8).
227 .TP
228 .B ENOSYS
229 This
230 .BR syslog ()
231 system call is not available, because the kernel was compiled with the
232 .BR CONFIG_PRINTK
233 kernel-configuration option disabled.
234 .TP
235 .B EPERM
236 An attempt was made to change console_loglevel or clear the kernel
237 message ring buffer by a process without sufficient privilege
238 (more precisely: without the
239 .B CAP_SYS_ADMIN
240 capability).
241 .TP
242 .B ERESTARTSYS
243 System call was interrupted by a signal; nothing was read.
244 (This can be seen only during a trace.)
245 .SH "CONFORMING TO"
246 This system call is Linux-specific and should not be used in programs
247 intended to be portable.
248 .SH NOTES
249 From the very start people noted that it is unfortunate that
250 a system call and a library routine of the same name are entirely
251 different animals.
252 In libc4 and libc5 the number of this call was defined by
253 .BR SYS_klog .
254 In glibc 2.0 the syscall is baptized
255 .BR klogctl ().
256 .SH "SEE ALSO"
257 .BR syslog (3)