Skip to content

control: dbus: check EINTR for read

Alexandre Janniaux requested to merge alexandre-janniaux/vlc:dbus-read/1 into master

The definition of read() mandates from its prototype that the return value and errno must be checked since the syscall can be interrupted without being processed by a signal:

../../modules/control/dbus/dbus.c: In function ‘Run’:
../../modules/control/dbus/dbus.c:958:19: warning: ignoring return value of ‘read’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  958 |             (void)read( fds[0].fd, &buf, 1 );
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~

In practice, the read is not done on a slow device, but a UNIX pipe instead, and only when poll() notify that a read operation will be non-blocking, and we're not supposed to have a signal handler here in the normal execution (not using tools making use of SIGPROF for instance), so read() being interrupted is nearly impossible, as opposed to poll() being interrupted.

The read() call is also changed to use an anonymous compound litteral which doesn't need to be marked as used manually, since we didn't use the buffer variable at all.

In the future, using eventfd() to generate a semaphore compatible with poll() and making the event handling lock-free might be a better alternative, since read() will return the number of new events, and the lock would become redundant.

Merge request reports