mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-02 11:45:58 +01:00
helpers: fix misuse of syscalls in sd namespace (#6379)
This commit is contained in:
parent
c62f0015ae
commit
bf75723f27
1 changed files with 6 additions and 6 deletions
|
@ -21,8 +21,8 @@ namespace Systemd {
|
||||||
}
|
}
|
||||||
|
|
||||||
int SdNotify(int unsetEnvironment, const char* state) {
|
int SdNotify(int unsetEnvironment, const char* state) {
|
||||||
int fd = socket(AF_UNIX, SOCK_DGRAM, 0);
|
int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||||
if (fd == -1)
|
if (fd < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
constexpr char envVar[] = "NOTIFY_SOCKET";
|
constexpr char envVar[] = "NOTIFY_SOCKET";
|
||||||
|
@ -47,12 +47,12 @@ namespace Systemd {
|
||||||
if (unixAddr.sun_path[0] == '@')
|
if (unixAddr.sun_path[0] == '@')
|
||||||
unixAddr.sun_path[0] = '\0';
|
unixAddr.sun_path[0] = '\0';
|
||||||
|
|
||||||
if (!connect(fd, (const sockaddr*)&unixAddr, sizeof(struct sockaddr_un)))
|
if (connect(fd, (const sockaddr*)&unixAddr, sizeof(struct sockaddr_un)) < 0)
|
||||||
return 1;
|
return -errno;
|
||||||
|
|
||||||
// arbitrary value which seems to be enough for s-d messages
|
// arbitrary value which seems to be enough for s-d messages
|
||||||
size_t stateLen = strnlen(state, 128);
|
ssize_t stateLen = strnlen(state, 128);
|
||||||
if (write(fd, state, stateLen) >= 0)
|
if (write(fd, state, stateLen) == stateLen)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
Loading…
Reference in a new issue