From: HAMANO Tsukasa Date: Wed, 8 May 2024 23:26:41 +0000 (+0900) Subject: refactoring X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=995a2d45bccd1dbeee2a60c5121f80b08e49e1ec;p=thirdparty%2Fopenldap.git refactoring - remove __attribute__ destructor - use sendto instead of connect/write --- diff --git a/include/sd-notify.h b/include/sd-notify.h index 7775d20d46..be284f681f 100644 --- a/include/sd-notify.h +++ b/include/sd-notify.h @@ -12,14 +12,6 @@ #include #include -#define _cleanup_(f) __attribute__((cleanup(f))) -static void closep(int *fd) { - if (!fd || *fd < 0) - return; - close(*fd); - *fd = -1; -} - static int sd_notify(int ignore, const char *message) { union sockaddr_union { struct sockaddr sa; @@ -28,8 +20,9 @@ static int sd_notify(int ignore, const char *message) { .sun.sun_family = AF_UNIX, }; size_t path_length, message_length; - _cleanup_(closep) int fd = -1; const char *socket_path; + int fd = -1; + int rc = 1; socket_path = getenv("NOTIFY_SOCKET"); if (!socket_path) @@ -61,12 +54,11 @@ static int sd_notify(int ignore, const char *message) { if (fd < 0) return -errno; - if (connect(fd, &socket_addr.sa, offsetof(struct sockaddr_un, sun_path) + path_length) != 0) - return -errno; - - ssize_t written = write(fd, message, message_length); + ssize_t written = sendto(fd, message, message_length, 0, + &socket_addr.sa, offsetof(struct sockaddr_un, sun_path) + path_length); if (written != (ssize_t) message_length) - return written < 0 ? -errno : -EPROTO; + rc = written < 0 ? -errno : -EPROTO; - return 1; /* Notified! */ + close(fd); + return rc; }