From 916abb21d0a6653e0187b91591e492026886b0a4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 17 May 2011 19:37:03 +0200 Subject: socket: add POSIX mqueue support --- src/sd-daemon.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/sd-daemon.c') diff --git a/src/sd-daemon.c b/src/sd-daemon.c index 6d1eebff07..b30db5d5b3 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" @@ -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; -- cgit v1.2.3-54-g00ecf