1.\" $OpenBSD: sendsyslog.2,v 1.13 2021/03/09 15:08:23 bluhm Exp $ 2.\" 3.\" Copyright (c) 2017 Alexander Bluhm <bluhm@openbsd.org> 4.\" Copyright (c) 2014 Theo de Raadt 5.\" 6.\" Permission to use, copy, modify, and distribute this software for any 7.\" purpose with or without fee is hereby granted, provided that the above 8.\" copyright notice and this permission notice appear in all copies. 9.\" 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" 18.Dd $Mdocdate: March 9 2021 $ 19.Dt SENDSYSLOG 2 20.Os 21.Sh NAME 22.Nm sendsyslog 23.Nd send a message to syslogd 24.Sh SYNOPSIS 25.In sys/syslog.h 26.In sys/types.h 27.Ft int 28.Fn sendsyslog "const char *msg" "size_t len" "int flags" 29.Sh DESCRIPTION 30The 31.Fn sendsyslog 32function is used to transmit a 33.Xr syslog 3 34formatted message direct to 35.Xr syslogd 8 36without requiring the allocation of a socket. 37The 38.Fa msg 39is not NUL terminated and its 40.Fa len 41is limited to 8192 bytes. 42If 43.Dv LOG_CONS 44is specified in the 45.Fa flags 46argument, and 47.Xr syslogd 8 48is not accepting messages, the message will be sent to the console. 49This is used internally by 50.Xr syslog_r 3 , 51so that messages can be sent during difficult situations. 52If sending to 53.Xr syslogd 8 54fails, up to 100 messages are stashed in the kernel. 55After that, dropped messages are counted. 56When 57.Xr syslogd 8 58works again, before the next message, stashed messages and possibly 59a warning with the drop counter, error number, and pid is logged. 60.Pp 61To receive messages from the kernel, 62.Xr syslogd 8 63has to create a datagram socket pair and register one end. 64This registration is done by opening the 65.Pa /dev/klog 66device and passing one file descriptor of the socket pair as argument 67to 68.Xr ioctl 2 Dv LIOCSFD 69invoked on the klog file descriptor. 70After that the messages can be read from the other end of the 71socket pair. 72By utilizing 73.Pa /dev/klog 74the access to log messages is limited to processes that may open 75this device. 76.Sh RETURN VALUES 77.Rv -std 78.Sh ERRORS 79.Fn sendsyslog 80can fail if: 81.Bl -tag -width Er 82.It Bq Er EFAULT 83An invalid user space address was specified for a parameter. 84.It Bq Er EMSGSIZE 85The socket requires that message be sent atomically, 86and the size of the message to be sent made this impossible. 87.It Bq Er ENOBUFS 88The system was unable to allocate an internal buffer. 89The operation may succeed when buffers become available. 90.It Bq Er ENOTCONN 91The message cannot be sent, likely because 92.Xr syslogd 8 93is not running. 94.El 95.Sh SEE ALSO 96.Xr syslog_r 3 , 97.Xr syslogd 8 98.Sh HISTORY 99The 100.Fn sendsyslog 101function call appeared in 102.Ox 5.6 . 103The 104.Fa flags 105argument was added in 106.Ox 6.0 . 107