chiark / gitweb /
sd-event: don't touch fd's accross forks
authorTom Gundersen <teg@jklm.no>
Thu, 4 Jun 2015 14:54:45 +0000 (16:54 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:01:47 +0000 (10:01 +0100)
We protect most of the API from use accross forks, but we still allow both
sd_event and sd_event_source objects to be unref'ed. This would cause
problems as it would unregister sources from the underlying eventfd, hence
also affecting the original instance in the parent process.

This fixes the issue by not touching the fds on unref when done accross a fork,
but still free the memory.

This fixes a regression introduced by
        "udevd: move main-loop to sd-event": 693d371d30fee

where the worker processes were disabling the inotify event source in the
main daemon.

src/libelogind/sd-event/sd-event.c

index cc8bc50c04a8abca55400a50b66a4037687ccdc4..2b8d1b87ed3925c9c3462eb57b097cee798f835a 100644 (file)
@@ -474,6 +474,9 @@ static int source_io_unregister(sd_event_source *s) {
         assert(s);
         assert(s->type == SOURCE_IO);
 
+        if (event_pid_changed(s->event))
+                return 0;
+
         if (!s->io.registered)
                 return 0;
 
@@ -604,6 +607,9 @@ static int event_update_signal_fd(sd_event *e) {
 
         assert(e);
 
+        if (event_pid_changed(e))
+                return 0;
+
         add_to_epoll = e->signal_fd < 0;
 
         r = signalfd(e->signal_fd, &e->sigset, SFD_NONBLOCK|SFD_CLOEXEC);