]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man2/syslog.2
pipe.2: Note that 'pipefd' is left unchanged in the event of an error
[thirdparty/man-pages.git] / man2 / syslog.2
index fb018a6377bc2ad7df2065aac5527ccb3f361df5..99d4ff854f809a012f6a253190b6e061f51abc55 100644 (file)
@@ -1,5 +1,8 @@
+'\" t
 .\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
+.\" and Copyright (C) 2012, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
 .\"
+.\" %%%LICENSE_START(VERBATIM)
 .\" Permission is granted to make and distribute verbatim copies of this
 .\" manual provided the copyright notice and this permission notice are
 .\" preserved on all copies.
@@ -19,6 +22,7 @@
 .\"
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
 .\"
 .\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
 .\" 2008-02-15, Jeremy Kerr <jk@ozlabs.org>
@@ -26,7 +30,7 @@
 .\" 2008-02-15, Michael Kerrisk <mtk.manpages@gmail.com>
 .\"     Update LOG_BUF_LEN details; update RETURN VALUE section.
 .\"
-.TH SYSLOG 2  2008-06-20 "Linux" "Linux Programmer's Manual"
+.TH SYSLOG 2  2017-09-15 "Linux" "Linux Programmer's Manual"
 .SH NAME
 syslog, klogctl \- read and/or clear kernel message ring buffer;
 set console_loglevel
@@ -34,163 +38,285 @@ set console_loglevel
 .nf
 .BI "int syslog(int " type ", char *" bufp ", int " len );
 .B  "                /* No wrapper provided in glibc */"
-.sp
+.PP
 /* The glibc interface */
-.br
 .B "#include <sys/klog.h>"
-.sp
+.PP
 .BI "int klogctl(int " type ", char *" bufp ", int " len );
 .fi
 .SH DESCRIPTION
-If you need the C library function
+.IR Note :
+Probably, you are looking for the C library function
+.BR syslog (),
+which talks to
+.BR syslogd (8);
+see
+.BR syslog (3)
+for details.
+.PP
+This page describes the kernel
 .BR syslog ()
-(which talks to
-.BR syslogd (8)),
-then look at
-.BR syslog (3).
-The system call of this name is about controlling the kernel
+system call, which is used to control the kernel
 .IR printk ()
-buffer, and the glibc version is called
+buffer; the glibc wrapper function for the system call is called
 .BR klogctl ().
-
-The \fItype\fP argument determines the action taken by this function.
-
-Quoting from
-.IR kernel/printk.c :
-.nf
-/*
- * Commands to sys_syslog:
- *
- *      0 \-\- Close the log.  Currently a NOP.
- *      1 \-\- Open the log. Currently a NOP.
- *      2 \-\- Read from the log.
- *      3 \-\- Read all messages remaining in the ring buffer.
- *      4 \-\- Read and clear all messages remaining in the ring buffer
- *      5 \-\- Clear ring buffer.
- *      6 \-\- Disable printk to console
- *      7 \-\- Enable printk to console
- *      8 \-\- Set level of messages printed to console
- *      9 \-\- Return number of unread characters in the log buffer
- *     10 \-\- Return size of the log buffer
- */
-.fi
-
-Only command types 3 and 10 are allowed to unprivileged processes.
-Type 9 was added in 2.4.10; type 10 in 2.6.6.
 .SS The kernel log buffer
 The kernel has a cyclic buffer of length
 .B LOG_BUF_LEN
 in which messages given as arguments to the kernel function
 .BR printk ()
-are stored (regardless of their loglevel).
+are stored (regardless of their log level).
 In early kernels,
 .B LOG_BUF_LEN
 had the value 4096;
 from kernel 1.3.54, it was 8192;
-from kernel 2.1.113 it was 16384;
-since 2.4.23/2.6 the value is a kernel configuration option.
+from kernel 2.1.113, it was 16384;
+since kernel 2.4.23/2.6, the value is a kernel configuration option
+.RB ( CONFIG_LOG_BUF_SHIFT ,
+default value dependent on the architecture).
 .\" Under "General setup" ==> "Kernel log buffer size"
 .\" For 2.6, precisely the option seems to have appeared in 2.5.55.
-In recent kernels the size can be queried with command type 10.
-
+Since Linux 2.6.6, the size can be queried with command type 10 (see below).
+.SS Commands
+The \fItype\fP argument determines the action taken by this function.
+The list below specifies the values for
+.IR type .
+The symbolic names are defined in the kernel source,
+but are not exported to user space;
+you will either need to use the numbers, or define the names yourself.
+.TP
+.BR SYSLOG_ACTION_CLOSE " (0)"
+Close the log.
+Currently a NOP.
+.TP
+.BR SYSLOG_ACTION_OPEN " (1)"
+Open the log.
+Currently a NOP.
+.TP
+.BR SYSLOG_ACTION_READ " (2)"
+Read from the log.
 The call
-.I "syslog(2,buf,len)"
-waits until this kernel log buffer is nonempty, and then reads
-at most \fIlen\fP bytes into the buffer \fIbuf\fP.
-It returns
-the number of bytes read.
-Bytes read from the log disappear from
-the log buffer: the information can only be read once.
-This is the function executed by the kernel when a user program
-reads
+waits until the kernel log buffer is nonempty, and then reads
+at most \fIlen\fP bytes into the buffer pointed to by
+.IR bufp .
+The call returns the number of bytes read.
+Bytes read from the log disappear from the log buffer:
+the information can be read only once.
+This is the function executed by the kernel when a user program reads
 .IR /proc/kmsg .
-
-The call
-.I syslog(3,buf,len)
-will read the last \fIlen\fP bytes from the log buffer (nondestructively),
+.TP
+.BR SYSLOG_ACTION_READ_ALL " (3)"
+Read all messages remaining in the ring buffer,
+placing them in the buffer pointed to by
+.IR bufp .
+The call reads the last \fIlen\fP
+bytes from the log buffer (nondestructively),
 but will not read more than was written into the buffer since the
-last "clear ring buffer" command (which does not clear the buffer at all).
-It returns the number of bytes read.
-
-The call
-.I syslog(4,buf,len)
-does precisely the same, but also executes the "clear ring buffer" command.
-
-The call
-.I syslog(5,dummy,dummy)
-executes just the "clear ring buffer" command.
-(In each call where
-.I buf
-or
+last "clear ring buffer" command (see command 5 below)).
+The call returns the number of bytes read.
+.TP
+.BR SYSLOG_ACTION_READ_CLEAR " (4)"
+Read and clear all messages remaining in the ring buffer.
+The call does precisely the same as for a
+.I type
+of 3, but also executes the "clear ring buffer" command.
+.TP
+.BR SYSLOG_ACTION_CLEAR " (5)"
+The call executes just the "clear ring buffer" command.
+The
+.I bufp
+and
 .I len
-is shown as "dummy", the value of the argument is ignored by the call.)
-
-The call
-.I syslog(6,dummy,dummy)
-sets the console log level to minimum, so that no messages are printed
-to the console.
-
-The call
-.I syslog(7,dummy,dummy)
-sets the console log level to default, so that messages are printed
-to the console.
-
-The call
-.I syslog(8,dummy,level)
-sets the console log level to
-.IR level ,
+arguments are ignored.
+.IP
+This command does not really clear the ring buffer.
+Rather, it sets a kernel bookkeeping variable that
+determines the results returned by commands 3
+.RB ( SYSLOG_ACTION_READ_ALL )
+and 4
+.RB ( SYSLOG_ACTION_READ_CLEAR ).
+This command has no effect on commands 2
+.RB ( SYSLOG_ACTION_READ )
+and 9
+.RB ( SYSLOG_ACTION_SIZE_UNREAD ).
+.TP
+.BR SYSLOG_ACTION_CONSOLE_OFF " (6)"
+The command saves the current value of
+.I console_loglevel
+and then sets
+.I console_loglevel
+to
+.IR minimum_console_loglevel ,
+so that no messages are printed to the console.
+Before Linux 2.6.32,
+.\" commit 1aaad49e856ce41adc07d8ae0c8ef35fc4483245
+the command simply sets
+.I console_loglevel
+to
+.IR minimum_console_loglevel .
+See the discussion of
+.IR /proc/sys/kernel/printk ,
+below.
+.IP
+The
+.I bufp
+and
+.I len
+arguments are ignored.
+.TP
+.BR SYSLOG_ACTION_CONSOLE_ON " (7)"
+If a previous
+.B SYSLOG_ACTION_CONSOLE_OFF
+command has been performed,
+this command restores
+.I console_loglevel
+to the value that was saved by that command.
+Before Linux 2.6.32,
+.\" commit 1aaad49e856ce41adc07d8ae0c8ef35fc4483245
+this command simply sets
+.I console_loglevel
+to
+.IR default_console_loglevel .
+See the discussion of
+.IR /proc/sys/kernel/printk ,
+below.
+.IP
+The
+.I bufp
+and
+.I len
+arguments are ignored.
+.TP
+.BR SYSLOG_ACTION_CONSOLE_LEVEL " (8)"
+The call sets
+.I console_loglevel
+to the value given in
+.IR len ,
 which must be an integer between 1 and 8 (inclusive).
+The kernel silently enforces a minimum value of
+.IR minimum_console_loglevel
+for
+.IR len .
 See the
-.B loglevel
+.IR "log level"
 section for details.
-
+The
+.I bufp
+argument is ignored.
+.TP
+.BR SYSLOG_ACTION_SIZE_UNREAD " (9) (since Linux 2.4.10)"
 The call
-.I syslog(9,dummy,dummy)
 returns the number of bytes currently available to be read
-on the kernel log buffer.
-
-The call
-.I syslog(10,dummy,dummy)
-returns the total size of the kernel log buffer.
-.SS The loglevel
-The kernel routine
-.BR printk ()
-will only print a message on the
-console, if it has a loglevel less than the value of the variable
-.IR console_loglevel .
-This variable initially has the value
+from the kernel log buffer via command 2
+.RB ( SYSLOG_ACTION_READ ).
+The
+.I bufp
+and
+.I len
+arguments are ignored.
+.TP
+.BR SYSLOG_ACTION_SIZE_BUFFER " (10) (since Linux 2.6.6)"
+This command returns the total size of the kernel log buffer.
+The
+.I bufp
+and
+.I len
+arguments are ignored.
+.PP
+All commands except 3 and 10 require privilege.
+In Linux kernels before 2.6.37,
+command types 3 and 10 are allowed to unprivileged processes;
+since Linux 2.6.37,
+these commands are allowed to unprivileged processes only if
+.IR /proc/sys/kernel/dmesg_restrict
+has the value 0.
+Before Linux 2.6.37, "privileged" means that the caller has the
+.BR CAP_SYS_ADMIN
+capability.
+Since Linux 2.6.37,
+"privileged" means that the caller has either the
+.BR CAP_SYS_ADMIN
+capability (now deprecated for this purpose) or the (new)
+.BR CAP_SYSLOG
+capability.
+.\"
+.\"
+.SS /proc/sys/kernel/printk
+.I /proc/sys/kernel/printk
+is a writable file containing four integer values that influence kernel
+.I printk()
+behavior when printing or logging error messages.
+The four values are:
+.TP
+.I console_loglevel
+Only messages with a log level lower than this value will
+be printed to the console.
+The default value for this field is
 .B DEFAULT_CONSOLE_LOGLEVEL
-(7), but is set to 10 if the
-kernel command line contains the word "debug", and to 15 in case
+(7), but it is set to
+4 if the kernel command line contains the word "quiet", \" since Linux 2.4
+10 if the kernel command line contains the word "debug",
+and to 15 in case
 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
-This variable is set (to a value in the range 1-8) by the call
-.IR syslog(8,dummy,value) .
-The calls
-.I syslog(type,dummy,dummy)
-with \fItype\fP equal to 6 or 7, set it to 1 (kernel panics only)
-or 7 (all except debugging messages), respectively.
-
-Every text line in a message has its own loglevel.
-This level is
-.I "DEFAULT_MESSAGE_LOGLEVEL \- 1"
-(6) unless the line starts with <d>
-where \fId\fP is a digit in the range 1-7, in which case the level
-is \fId\fP.
-The conventional meaning of the loglevel is defined in
-.I <linux/kernel.h>
-as follows:
-
-.nf
-#define KERN_EMERG    "<0>"  /* system is unusable               */
-#define KERN_ALERT    "<1>"  /* action must be taken immediately */
-#define KERN_CRIT     "<2>"  /* critical conditions              */
-#define KERN_ERR      "<3>"  /* error conditions                 */
-#define KERN_WARNING  "<4>"  /* warning conditions               */
-#define KERN_NOTICE   "<5>"  /* normal but significant condition */
-#define KERN_INFO     "<6>"  /* informational                    */
-#define KERN_DEBUG    "<7>"  /* debug-level messages             */
-.fi
-.SH "RETURN VALUE"
+The value of
+.IR console_loglevel
+can be set (to a value in the range 1\(en8) by a
+.BR syslog ()
+call with a
+.I type
+of 8.
+.TP
+.I default_message_loglevel
+This value will be used as the log level for
+.IR printk()
+messages that do not have an explicit level.
+Up to and including Linux 2.6.38,
+the hard-coded default value for this field was 4
+.RB ( KERN_WARNING );
+since Linux 2.6.39,
+.\" commit 5af5bcb8d37f99ba415a1adc6da71051b84f93a5
+the default value is a defined by the kernel configuration option
+.BR CONFIG_DEFAULT_MESSAGE_LOGLEVEL ,
+which defaults to 4.
+.TP
+.I minimum_console_loglevel
+The value in this field is the minimum value to which
+.I console_loglevel
+can be set.
+.TP
+.I default_console_loglevel
+This is the default value for
+.IR console_loglevel .
+.\"
+.\"
+.SS The log level
+Every
+.IR printk ()
+message has its own log level.
+If the log level is not explicitly specified as part of the message,
+it defaults to
+.IR default_message_loglevel .
+The conventional meaning of the log level is as follows:
+.TS
+lB lB lB
+lB c l.
+Kernel constant        Level value     Meaning
+KERN_EMERG     0       System is unusable
+KERN_ALERT     1       Action must be taken immediately
+KERN_CRIT      2       Critical conditions
+KERN_ERR       3       Error conditions
+KERN_WARNING   4       Warning conditions
+KERN_NOTICE    5       Normal but significant condition
+KERN_INFO      6       Informational
+KERN_DEBUG     7       Debug-level messages
+.TE
+.sp 1
+The kernel
+.IR printk()
+routine will print a message on the
+console only if it has a log level less than the value of
+.IR console_loglevel .
+.SH RETURN VALUE
 For \fItype\fP equal to 2, 3, or 4, a successful call to
 .BR syslog ()
 returns the number
@@ -203,7 +329,7 @@ For \fItype\fP 10,
 .BR syslog ()
 returns the total size of the kernel log buffer.
 For other values of \fItype\fP, 0 is returned on success.
-
+.PP
 In case of error, \-1 is returned,
 and \fIerrno\fP is set to indicate the error.
 .SH ERRORS
@@ -233,25 +359,31 @@ system call is not available, because the kernel was compiled with the
 kernel-configuration option disabled.
 .TP
 .B EPERM
-An attempt was made to change console_loglevel or clear the kernel
+An attempt was made to change
+.I console_loglevel
+or clear the kernel
 message ring buffer by a process without sufficient privilege
 (more precisely: without the
 .B CAP_SYS_ADMIN
+or
+.BR CAP_SYSLOG
 capability).
 .TP
 .B ERESTARTSYS
 System call was interrupted by a signal; nothing was read.
 (This can be seen only during a trace.)
-.SH "CONFORMING TO"
+.SH CONFORMING TO
 This system call is Linux-specific and should not be used in programs
 intended to be portable.
 .SH NOTES
-From the very start people noted that it is unfortunate that
+From the very start, people noted that it is unfortunate that
 a system call and a library routine of the same name are entirely
 different animals.
-In libc4 and libc5 the number of this call was defined by
-.BR SYS_klog .
-In glibc 2.0 the syscall is baptized
-.BR klogctl ().
-.SH "SEE ALSO"
-.BR syslog (3)
+.\" In libc4 and libc5 the number of this call was defined by
+.\" .BR SYS_klog .
+.\" In glibc 2.0 the syscall is baptized
+.\" .BR klogctl ().
+.SH SEE ALSO
+.BR dmesg (1),
+.BR syslog (3),
+.BR capabilities (7)