]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/syslog.2
Convert to American spelling conventions
[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 .TH SYSLOG 2 2007-06-01 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 syslog, klogctl \- read and/or clear kernel message ring buffer;
27 set console_loglevel
28 .SH SYNOPSIS
29 .nf
30 .BI "int syslog(int " type ", char *" bufp ", int " len );
31 .B " /* No wrapper provided in glibc */
32 .sp
33 /* The glibc interface */
34 .br
35 .B "#include <sys/klog.h>"
36 .sp
37 .BI "int klogctl(int " type ", char *" bufp ", int " len );
38 .fi
39 .SH DESCRIPTION
40 If you need the libc function
41 .BR syslog ()
42 (which talks to
43 .BR syslogd (8)),
44 then look at
45 .BR syslog (3).
46 The system call of this name is about controlling the kernel
47 .IR printk ()
48 buffer, and the glibc version is called
49 .BR klogctl ().
50
51 The \fItype\fP argument determines the action taken by this function.
52
53 Quoting from
54 .IR kernel/printk.c :
55 .nf
56 /*
57 * Commands to sys_syslog:
58 *
59 * 0 \-\- Close the log. Currently a NOP.
60 * 1 \-\- Open the log. Currently a NOP.
61 * 2 \-\- Read from the log.
62 * 3 \-\- Read up to the last 4k of messages in the ring buffer.
63 * 4 \-\- Read and clear last 4k of messages in the ring buffer
64 * 5 \-\- Clear ring buffer.
65 * 6 \-\- Disable printk's to console
66 * 7 \-\- Enable printk's to console
67 * 8 \-\- Set level of messages printed to console
68 * 9 \-\- Return number of unread characters in the log buffer
69 */
70 .fi
71
72 Only function 3 is allowed to non-root processes.
73 (Function 9 was added in 2.4.10.)
74
75 .B The kernel log buffer
76 .br
77 The kernel has a cyclic buffer of length LOG_BUF_LEN
78 (4096, since 1.3.54: 8192, since 2.1.113: 16384; in recent kernels
79 the size can be set at compile time) in which messages given as argument
80 to the kernel function
81 .BR printk ()
82 are stored
83 (regardless of their loglevel).
84
85 The call
86 .BR syslog ()
87 .RI (2, buf , len )
88 waits until this kernel log buffer is nonempty, and then reads
89 at most \fIlen\fP bytes into the buffer \fIbuf\fP.
90 It returns
91 the number of bytes read.
92 Bytes read from the log disappear from
93 the log buffer: the information can only be read once.
94 This is the function executed by the kernel when a user program
95 reads
96 .IR /proc/kmsg .
97
98 The call
99 .BR syslog ()
100 .RI (3, buf , len )
101 will read the last \fIlen\fP bytes from the log buffer (nondestructively),
102 but will not read more than was written into the buffer since the
103 last `clear ring buffer' command (which does not clear the buffer at all).
104 It returns the number of bytes read.
105
106 The call
107 .BR syslog ()
108 .RI (4, buf , len )
109 does precisely the same, but also executes the `clear ring buffer' command.
110
111 The call
112 .BR syslog ()
113 .RI (5, dummy , idummy )
114 only executes the `clear ring buffer' command.
115
116 .B The loglevel
117 .br
118 The kernel routine
119 .BR printk ()
120 will only print a message on the
121 console, if it has a loglevel less than the value of the variable
122 .IR console_loglevel .
123 This variable initially has the value DEFAULT_CONSOLE_LOGLEVEL (7),
124 but is set to 10 if the
125 kernel command line contains the word `debug', and to 15 in case
126 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
127 This variable is set (to a value in the range 1-8) by the call
128 .BR syslog ()
129 .RI (8, dummy , value ).
130 The calls
131 .BR syslog ()
132 .RI ( type , dummy , idummy )
133 with \fItype\fP equal to 6 or 7, set it to 1 (kernel panics only)
134 or 7 (all except debugging messages), respectively.
135
136 Every text line in a message has its own loglevel.
137 This level is
138 DEFAULT_MESSAGE_LOGLEVEL \- 1 (6) unless the line starts with <d>
139 where \fId\fP is a digit in the range 1-7, in which case the level
140 is \fId\fP.
141 The conventional meaning of the loglevel is defined in
142 .I <linux/kernel.h>
143 as follows:
144
145 .nf
146 #define KERN_EMERG "<0>" /* system is unusable */
147 #define KERN_ALERT "<1>" /* action must be taken immediately */
148 #define KERN_CRIT "<2>" /* critical conditions */
149 #define KERN_ERR "<3>" /* error conditions */
150 #define KERN_WARNING "<4>" /* warning conditions */
151 #define KERN_NOTICE "<5>" /* normal but significant condition */
152 #define KERN_INFO "<6>" /* informational */
153 #define KERN_DEBUG "<7>" /* debug-level messages */
154 .fi
155 .SH "RETURN VALUE"
156 In case of error, \-1 is returned, and \fIerrno\fP is set.
157 Otherwise,
158 for \fItype\fP equal to 2, 3 or 4,
159 .BR syslog ()
160 returns the number
161 of bytes read, and otherwise 0.
162 .SH ERRORS
163 .TP
164 .B EINVAL
165 Bad parameters.
166 .TP
167 .B EPERM
168 An attempt was made to change console_loglevel or clear the kernel
169 message ring buffer by a process without root permissions.
170 .TP
171 .B ERESTARTSYS
172 System call was interrupted by a signal; nothing was read.
173 (This can be seen only during a trace.)
174 .SH "CONFORMING TO"
175 This system call is Linux specific and should not be used in programs
176 intended to be portable.
177 .SH NOTES
178 From the very start people noted that it is unfortunate that
179 kernel call and library routine of the same name are entirely
180 different animals.
181 In libc4 and libc5 the number of this call was defined by
182 .BR SYS_klog .
183 In glibc 2.0 the syscall is baptized
184 .BR klogctl ().
185 .SH "SEE ALSO"
186 .BR syslog (3)