[systemd-devel] Bug in source_io_register?

Lennart Poettering lennart at poettering.net
Mon Oct 14 08:39:49 PDT 2013


On Sun, 13.10.13 22:24, David Strauss (david at davidstrauss.net) wrote:

> source_io_register errors out with EEXIST, but that's supposed to be
> harmless for epoll [1]:
> 
> Q1: What happens if you add the same fd to an epoll_set twice?
> A1: You will probably get EEXIST. However, it is possible that two
> threads may add the same fd twice. This is a harmless condition.
> 
> I assume we should ignore it in the event library?

The kernel will only attach one userdata pointer to each fd, hence we
cannot really pretend that adding the same fd twice could ever work:
because the callback/userdata attached to it will be dropped for one of
them, and that's a problem.

So, we really should return EEXIST if the fd is already added. The fact
that if epollctl() is invoked for the same fd from two threads at the
same time the EEXIST might not be generated isn't really a problem as
libsystemd-event is explicitly *not* thread safe (though threads-aware)
so that it is never OK to to use it from two threads at the same
time. Users of the API always have to do their own locking around it.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list