[vlc-commits] [Git][videolan/vlc][master] control: dbus: check EINTR for read
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Thu Aug 10 15:59:52 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
2f2a4787 by Alexandre Janniaux at 2023-08-10T15:46:34+00:00
control: dbus: check EINTR for read
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.
- - - - -
1 changed file:
- modules/control/dbus/dbus.c
Changes:
=====================================
modules/control/dbus/dbus.c
=====================================
@@ -954,8 +954,10 @@ static void *Run( void *data )
/* Was the main loop woken up manually ? */
if (fds[0].revents & POLLIN)
{
- char buf;
- (void)read( fds[0].fd, &buf, 1 );
+ while (read(fds[0].fd, &(char){' '}, 1) == -1)
+ {
+ /* Only EINTR can happen here, so ignore the error. */
+ }
}
/* We need to lock the mutex while building lists of events,
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2f2a47874029706f0b0ef37ec8d23c8256ceb07c
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2f2a47874029706f0b0ef37ec8d23c8256ceb07c
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list