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