summaryrefslogtreecommitdiff
path: root/src/helpers/SdDaemon.cpp
diff options
context:
space:
mode:
authorMykola Perehudov <nexec@users.noreply.github.com>2024-06-09 10:43:39 +0300
committerGitHub <noreply@github.com>2024-06-09 09:43:39 +0200
commitbf75723f2742973d4820f3f5378dff8c99333660 (patch)
tree57d3030ec1739710bd5f33b17d304fed5e4332ee /src/helpers/SdDaemon.cpp
parentc62f0015aed0c0918281b1ce17def00d7025041b (diff)
helpers: fix misuse of syscalls in sd namespace (#6379)
Diffstat (limited to 'src/helpers/SdDaemon.cpp')
-rw-r--r--src/helpers/SdDaemon.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/helpers/SdDaemon.cpp b/src/helpers/SdDaemon.cpp
index 497101e4..25e0ca3b 100644
--- a/src/helpers/SdDaemon.cpp
+++ b/src/helpers/SdDaemon.cpp
@@ -21,8 +21,8 @@ namespace Systemd {
}
int SdNotify(int unsetEnvironment, const char* state) {
- int fd = socket(AF_UNIX, SOCK_DGRAM, 0);
- if (fd == -1)
+ int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if (fd < 0)
return -errno;
constexpr char envVar[] = "NOTIFY_SOCKET";
@@ -47,12 +47,12 @@ namespace Systemd {
if (unixAddr.sun_path[0] == '@')
unixAddr.sun_path[0] = '\0';
- if (!connect(fd, (const sockaddr*)&unixAddr, sizeof(struct sockaddr_un)))
- return 1;
+ if (connect(fd, (const sockaddr*)&unixAddr, sizeof(struct sockaddr_un)) < 0)
+ return -errno;
// arbitrary value which seems to be enough for s-d messages
- size_t stateLen = strnlen(state, 128);
- if (write(fd, state, stateLen) >= 0)
+ ssize_t stateLen = strnlen(state, 128);
+ if (write(fd, state, stateLen) == stateLen)
return 1;
return -errno;