diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/github.com/ssgreg/journald@v1.0.0/write_msg.go | |
parent | Initial commit. (diff) | |
download | icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.tar.xz icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dependencies/pkg/mod/github.com/ssgreg/journald@v1.0.0/write_msg.go')
-rw-r--r-- | dependencies/pkg/mod/github.com/ssgreg/journald@v1.0.0/write_msg.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/ssgreg/journald@v1.0.0/write_msg.go b/dependencies/pkg/mod/github.com/ssgreg/journald@v1.0.0/write_msg.go new file mode 100644 index 0000000..fe9e15e --- /dev/null +++ b/dependencies/pkg/mod/github.com/ssgreg/journald@v1.0.0/write_msg.go @@ -0,0 +1,50 @@ +// +build !go1.9 + +package journald + +import ( + "net" + "syscall" + "unsafe" + + "golang.org/x/sys/unix" +) + +// Go implementation of sendmsg (UnixConn.WriteMsgUnix) is not suitable +// for systemd's Journal in case of sending file descriptors. It always +// sends a dummy data byte, but journal does not expect to get it: +// +// n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC); +// ... +// if (n > 0 && n_fds == 0) +// server_process_native_message(...); +// else if (n == 0 && n_fds == 1) +// server_process_native_file(...); +// else if (n_fds > 0) +// log_warning("Got too many file descriptors via native socket. Ignoring."); +// +// So we get a warning message (the last line) instead of the new log +// entry. +// +func writeMsgUnix(c *net.UnixConn, oob []byte, addr *net.UnixAddr) (oobn int, err error) { + ptr, salen := sockaddr(addr) + + var msg syscall.Msghdr + msg.Name = (*byte)(ptr) + msg.Namelen = uint32(salen) + msg.Control = (*byte)(unsafe.Pointer(&oob[0])) + msg.SetControllen(len(oob)) + + f, err := c.File() + if err != nil { + return 0, err + } + defer f.Close() + + _, n, errno := syscall.Syscall(unix.SYS_SENDMSG, f.Fd(), uintptr(unsafe.Pointer(&msg)), 0) + if errno != 0 { + return int(n), errno + } + + return int(n), nil +} |