Bug 199711

Summary: can getrandom return EINTR if SA_RESTART is specified on all signal handlers but the entropy buffer is not yet initialized
Product: Documentation Reporter: Alex Xu (Hello71) (alex_y_xu)
Component: man-pagesAssignee: documentation_man-pages (documentation_man-pages)
Status: NEW ---    
Severity: normal CC: tytso
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: Subsystem:
Regression: No Bisected commit-id:
Attachments: grnd-signal.c

Description Alex Xu (Hello71) 2018-05-13 15:01:54 UTC
the getrandom man page says:

       The behavior when a call to getrandom() that is blocked while reading
       from the urandom source is interrupted by a signal handler depends on
       the initialization state of the entropy buffer and on the request
       size, buflen.  If the entropy is not yet initialized, then the call
       fails with the EINTR error.  If the entropy pool has been initialized
       and the request size is large (buflen > 256), the call either
       succeeds, returning a partially filled buffer, or fails with the
       error EINTR.  If the entropy pool has been initialized and the
       request size is small (buflen <= 256), then getrandom() will not fail
       with EINTR.  Instead, it will return all of the bytes that have been
       requested.

this part clearly says that in this circumstance it will return EINTR. however, it also says:

       EINTR  The call was interrupted by a signal handler; see the
              description of how interrupted read(2) calls on "slow" devices
              are handled with and without the SA_RESTART flag in the
              signal(7) man page.

and in signal(7) it says:

       If a blocked call to one of the following interfaces is interrupted
       by a signal handler, then the call is automatically restarted after
       the signal handler returns if the SA_RESTART flag was used; otherwise
       the call fails with the error EINTR:

       * getrandom(2).

this strongly implies that if all signal handlers have SA_RESTART, then getrandom will never return EINTR.

so which is it? (I guess I could test it...)
Comment 1 Alex Xu (Hello71) 2018-05-13 15:03:15 UTC
but either way, the first part should be amended to either say "unless SA_RESTART was specified for the signal handler" or it should say "even if SA_RESTART ..."
Comment 2 Alex Xu (Hello71) 2018-05-14 02:56:21 UTC
Created attachment 275963 [details]
grnd-signal.c

I tested this program and found that getrandom respects SA_RESTART if the pool is not initialized.