X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsd-daemon.c;h=b30db5d5b33ab259a4649108b049798b78424930;hb=9131f660eedb29d18a29e6efff49c485e683c56c;hp=e12fb0483abfb8c4d690ffc62ee51622daa245fb;hpb=0e098b15c76e222f7de381203c0c35a75a5b2f24;p=elogind.git diff --git a/src/sd-daemon.c b/src/sd-daemon.c index e12fb0483..b30db5d5b 100644 --- a/src/sd-daemon.c +++ b/src/sd-daemon.c @@ -41,6 +41,11 @@ #include #include #include +#include + +#if defined(__linux__) +#include +#endif #include "sd-daemon.h" @@ -228,7 +233,7 @@ int sd_is_socket(int fd, int family, int type, int listening) { if (getsockname(fd, &sockaddr.sa, &l) < 0) return -errno; - if (l < offsetof(struct sockaddr_un, sun_path)) + if (l < sizeof(sa_family_t)) return -EINVAL; return sockaddr.sa.sa_family == family; @@ -254,7 +259,7 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port if (getsockname(fd, &sockaddr.sa, &l) < 0) return -errno; - if (l < offsetof(struct sockaddr_un, sun_path)) + if (l < sizeof(sa_family_t)) return -EINVAL; if (sockaddr.sa.sa_family != AF_INET && @@ -296,7 +301,7 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t if (getsockname(fd, &sockaddr.sa, &l) < 0) return -errno; - if (l < offsetof(struct sockaddr_un, sun_path)) + if (l < sizeof(sa_family_t)) return -EINVAL; if (sockaddr.sa.sa_family != AF_UNIX) @@ -325,6 +330,43 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t return 1; } +int sd_is_mq(int fd, const char *path) { +#if !defined(__linux__) + return 0; +#else + struct mq_attr attr; + + if (fd < 0) + return -EINVAL; + + if (mq_getattr(fd, &attr) < 0) + return -errno; + + if (path) { + char fpath[PATH_MAX]; + struct stat a, b; + + if (path[0] != '/') + return -EINVAL; + + if (fstat(fd, &a) < 0) + return -errno; + + strncpy(stpcpy(fpath, "/dev/mqueue"), path, sizeof(fpath) - 12); + fpath[sizeof(fpath)-1] = 0; + + if (stat(fpath, &b) < 0) + return -errno; + + if (a.st_dev != b.st_dev || + a.st_ino != b.st_ino) + return 0; + } + + return 1; +#endif +} + int sd_notify(int unset_environment, const char *state) { #if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC) return 0;