summaryrefslogtreecommitdiff
path: root/src/sd-daemon.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-05-17 19:37:03 +0200
committerLennart Poettering <lennart@poettering.net>2011-05-17 19:37:03 +0200
commit916abb21d0a6653e0187b91591e492026886b0a4 (patch)
tree8bce3407f16ec391c9e707dace2077024501d609 /src/sd-daemon.c
parentfff2e5b58bab7a5ffbb7593742d462197b06728c (diff)
socket: add POSIX mqueue support
Diffstat (limited to 'src/sd-daemon.c')
-rw-r--r--src/sd-daemon.c42
1 files changed, 42 insertions, 0 deletions
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 <stdarg.h>
#include <stdio.h>
#include <stddef.h>
+#include <limits.h>
+
+#if defined(__linux__)
+#include <mqueue.h>
+#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;