[vlc-commits] [Git][videolan/vlc][master] interrupt: check EINTR for IO operations

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Nov 10 13:40:40 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
e374f506 by Alexandre Janniaux at 2023-11-10T13:24:56+00:00
interrupt: check EINTR for IO operations

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


    ../../src/misc/interrupt.c: In function 'vlc_poll_i11e_inner':
    WARNING : ../../src/misc/interrupt.c:358: 9:  ignoring return value of 'read' declared with attribute 'warn_unused_result' [-Wunused-result]
      358 |         read(fd[0], &dummy, sizeof (dummy));
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../src/misc/interrupt.c: In function 'vlc_poll_i11e_wake':
    WARNING : ../../src/misc/interrupt.c:299: 5:  ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
      299 |     write(fd[1], &value, sizeof (value));
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In practice, we write and read into an eventfd or a pipe descriptor, and
we only read when poll() notify that a read operation will be
non-blocking, so the interruption can mostly never happen in production,
but it can happen when using different tools, like ones using SIGPROF
for instance.

See also commit 2f2a47874029706f0b0ef37ec8d23c8256ceb07c.

- - - - -


1 changed file:

- src/misc/interrupt.c


Changes:

=====================================
src/misc/interrupt.c
=====================================
@@ -2,6 +2,10 @@
  * interrupt.c:
  *****************************************************************************
  * Copyright (C) 2015 Rémi Denis-Courmont
+ * Copyright (C) 2023 Videolabs
+ *
+ * Authors: Rémi Denis-Courmont
+ *          Alexandre Janniaux <ajanni at videolabs.io>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -296,7 +300,12 @@ static void vlc_poll_i11e_wake(void *opaque)
     int canc;
 
     canc = vlc_savecancel();
-    write(fd[1], &value, sizeof (value));
+    while (write(fd[1], &value, sizeof (value)) == -1)
+    {
+        /* Only EINTR can happen here, so ignore the error.
+         * We still need to ensure we really wrote the value to trigger
+         * the interruption check though. */
+    }
     vlc_restorecancel(canc);
 }
 
@@ -355,7 +364,12 @@ static int vlc_poll_i11e_inner(struct pollfd *restrict fds, unsigned nfds,
     {
         uint64_t dummy;
 
-        read(fd[0], &dummy, sizeof (dummy));
+        while (read(fd[0], &dummy, sizeof (dummy)) == -1)
+        {
+            /* Only EINTR can happen here, so ignore the error.
+             * We still need to read() the value though, to ensure
+             * that the interruption is correctly acknowledged. */
+        }
         ret--;
     }
     vlc_cleanup_pop();



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e374f506a18a29129ca5fc8bd164979cddf9ed3f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e374f506a18a29129ca5fc8bd164979cddf9ed3f
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