summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-09-05 15:20:15 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-09-30 14:23:13 -0400
commit0260d1d542da73b3358fa659fb1fa634badbf00e (patch)
tree0eba0f98522c5e456c7edc4a9023bf8c2c192293 /src
parent7bbb5359c0a23061c9bd40e6f7c2a0afbf2906f8 (diff)
sd-daemon: fix sd_is_mq for non-mq fds
mq_getattr returns -1/EBADF for file descriptors which are not mq. But we should return 0 in this case. We first check that fd is a valid fd, so we can assume that if mq_getattr returns EBADF, it is simply a non-mq fd. There is a slight race, but there doesn't seem to be a nice way to fix it.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index ba7b8da85f..5fb0b73d02 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -310,10 +310,15 @@ _public_ int sd_is_socket_unix(int fd, int type, int listening, const char *path
_public_ int sd_is_mq(int fd, const char *path) {
struct mq_attr attr;
- assert_return(fd >= 0, -EBADF);
+ /* Check that the fd is valid */
+ assert_return(fcntl(fd, F_GETFD) >= 0, -errno);
- if (mq_getattr(fd, &attr) < 0)
+ if (mq_getattr(fd, &attr) < 0) {
+ if (errno == EBADF)
+ /* A non-mq fd (or an invalid one, but we ruled that out above) */
+ return 0;
return -errno;
+ }
if (path) {
char fpath[PATH_MAX];