diff options
Diffstat (limited to '')
-rw-r--r-- | src/libnetdata/log/journal.c (renamed from libnetdata/log/journal.c) | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libnetdata/log/journal.c b/src/libnetdata/log/journal.c index 21978cf5f..2182212f6 100644 --- a/libnetdata/log/journal.c +++ b/src/libnetdata/log/journal.c @@ -3,15 +3,12 @@ #include "journal.h" bool is_path_unix_socket(const char *path) { + // Check if the path is valid if(!path || !*path) return false; struct stat statbuf; - // Check if the path is valid - if (!path || !*path) - return false; - // Use stat to check if the file exists and is a socket if (stat(path, &statbuf) == -1) // The file does not exist or cannot be accessed @@ -51,9 +48,11 @@ int journal_direct_fd(const char *path) { if(!is_path_unix_socket(path)) return -1; - int fd = socket(AF_UNIX, SOCK_DGRAM, 0); + int fd = socket(AF_UNIX, SOCK_DGRAM| DEFAULT_SOCKET_FLAGS, 0); if (fd < 0) return -1; + sock_setcloexec(fd); + struct sockaddr_un addr; memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; @@ -68,7 +67,7 @@ int journal_direct_fd(const char *path) { return fd; } -static inline bool journal_send_with_memfd(int fd, const char *msg, size_t msg_len) { +static inline bool journal_send_with_memfd(int fd __maybe_unused, const char *msg __maybe_unused, size_t msg_len __maybe_unused) { #if defined(__NR_memfd_create) && defined(MFD_ALLOW_SEALING) && defined(F_ADD_SEALS) && defined(F_SEAL_SHRINK) && defined(F_SEAL_GROW) && defined(F_SEAL_WRITE) // Create a memory file descriptor int memfd = (int)syscall(__NR_memfd_create, "journald", MFD_ALLOW_SEALING); @@ -97,6 +96,11 @@ static inline bool journal_send_with_memfd(int fd, const char *msg, size_t msg_l msghdr.msg_controllen = sizeof(cmsgbuf); cmsghdr = CMSG_FIRSTHDR(&msghdr); + if(!cmsghdr) { + close(memfd); + return false; + } + cmsghdr->cmsg_level = SOL_SOCKET; cmsghdr->cmsg_type = SCM_RIGHTS; cmsghdr->cmsg_len = CMSG_LEN(sizeof(int)); |