summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/log/journal.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/libnetdata/log/journal.c (renamed from libnetdata/log/journal.c)14
1 files changed, 9 insertions, 5 deletions
diff --git a/libnetdata/log/journal.c b/src/libnetdata/log/journal.c
index 21978cf5f..0f1248de7 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;
@@ -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));