Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers: fix misuse of syscalls in sd namespace #6379

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/helpers/SdDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
Loading