[Toybox] [landley/toybox] timeout: use the monotonic clock. (81859b8)

Rob Landley rob at landley.net
Sat Sep 25 14:43:45 PDT 2021


On 9/25/21 3:01 PM, enh-google wrote:
> E5ten said:
> > As far as I know, passing NULL for the 2nd parameter is equivalent to using
> > a sigevent that specifies delivery of SIGALRM, so I think this can be
> > removed and the 2nd parameter would be changed to 0.
>
> i think you're right about the SIGEV_SIGNAL half, but POSIX leaves the specific
> signal implementation-defined:

Posix has a terrible habit of not specifying things that are actually standard.

> "If the evp argument is NULL, the effect is as if the evp argument pointed to a
> sigevent structure with the sigev_notify member having the value SIGEV_SIGNAL,
> the sigev_signo having a default signal number, and the sigev_value member
> having the value of the timer ID."
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
> <https://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html>
> 
> on /Linux/ that is indeed SIGALRM (do_timer_create() in
> kernel/time/posix-timers.c), but i don't know whether we want to depend on that?

alarm() was the first "signal sent by a timer" API back in the bell labs days.
Posix compains that the one in Unix v7 rounded down so could happen up to a
second early.

Go ahead and test mac but I would be highly surprised if it sends anything OTHER
than SIGALRM by default.

I note that
https://pubs.opengroup.org/onlinepubs/9699919799/functions/setitimer.html lets
you set three different timers that deliver three different signals, but the one
that's measuring time passing (instead of CPU time consumed) sends SIGALRM there
too.

(That said, CPU time consumed might be a fun option for timeout. Give it a
quota. Not sure how fork works in here, possibly a container thing...)

Rob



More information about the Toybox mailing list