diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-09-05 15:20:15 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-29 10:45:08 +0200 |
commit | 9277945f9aca8ed56f8575ab3c6bab5ace859d3a (patch) | |
tree | 9042ec52910c1493d7269a40dcbeb744f0203cf2 /src | |
parent | d7834101faf86dfa00e2ac3d9c3dd746852402eb (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/libelogind/sd-daemon/sd-daemon.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libelogind/sd-daemon/sd-daemon.c b/src/libelogind/sd-daemon/sd-daemon.c index af3dab7e4..7639b6d3b 100644 --- a/src/libelogind/sd-daemon/sd-daemon.c +++ b/src/libelogind/sd-daemon/sd-daemon.c @@ -315,10 +315,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]; |