diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2010-10-07 14:59:11 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2010-10-07 14:59:11 +0200 |
commit | 392ef7a28a7003a11f5e1e56617551ff5b9eabf9 (patch) | |
tree | b3ba7c6060f6f9d69323c46780e74f20db63a90c /udev/udevd.c | |
parent | d8b9a5c12b1ba238ed8165d11c498a3bd9f13f9f (diff) |
udevd: add sd-daemon.c
Diffstat (limited to 'udev/udevd.c')
-rw-r--r-- | udev/udevd.c | 63 |
1 files changed, 2 insertions, 61 deletions
diff --git a/udev/udevd.c b/udev/udevd.c index 0ec3c3d4ec..2efab5b39d 100644 --- a/udev/udevd.c +++ b/udev/udevd.c @@ -45,6 +45,7 @@ #include <sys/utsname.h> #include "udev.h" +#include "sd-daemon.h" #define UDEVD_PRIORITY -4 #define UDEV_PRIORITY -2 @@ -959,66 +960,6 @@ static int mem_size_mb(void) return memsize; } -static int init_notify(const char *state) -{ - int fd = -1, r; - struct msghdr msghdr; - struct iovec iovec; - union { - struct sockaddr sa; - struct sockaddr_un un; - } sockaddr; - const char *e; - - if (!(e = getenv("NOTIFY_SOCKET"))) { - r = 0; - goto finish; - } - - /* Must be an abstract socket, or an absolute path */ - if ((e[0] != '@' && e[0] != '/') || e[1] == 0) { - r = -EINVAL; - goto finish; - } - - if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) { - r = -errno; - goto finish; - } - - memset(&sockaddr, 0, sizeof(sockaddr)); - sockaddr.sa.sa_family = AF_UNIX; - strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path)); - - if (sockaddr.un.sun_path[0] == '@') - sockaddr.un.sun_path[0] = 0; - - memset(&iovec, 0, sizeof(iovec)); - iovec.iov_base = (char*) state; - iovec.iov_len = strlen(state); - - memset(&msghdr, 0, sizeof(msghdr)); - msghdr.msg_name = &sockaddr; - msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e); - if (msghdr.msg_namelen > sizeof(struct sockaddr_un)) - msghdr.msg_namelen = sizeof(struct sockaddr_un); - msghdr.msg_iov = &iovec; - msghdr.msg_iovlen = 1; - - if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) { - r = -errno; - goto finish; - } - - r = 0; - -finish: - if (fd >= 0) - close(fd); - - return r; -} - int main(int argc, char *argv[]) { struct udev *udev; @@ -1271,7 +1212,7 @@ int main(int argc, char *argv[]) goto exit; } } else { - init_notify("READY=1"); + sd_notify(1, "READY=1"); } /* set scheduling priority for the main daemon process */ |