CVSROOT:        /cvs
Module name:    src
Changes by:     chel...@cvs.openbsd.org 2020/10/13 11:33:39

Modified files:
        sys/kern       : kern_time.c 

Log message:
setitimer(2): zero itv.it_interval if itv.it_value is zero

If itv.it_value is zero we cancel the timer.  When we cancel the timer
we don't care about itv.it_interval because the timer is not running:
we don't use it, we don't look at it, etc.

To be on the paranoid side, I think we should zero itv.it_interval
when itv.it_value is zero.  No need to write arbitrary values into the
process struct if we aren't required to.  The standard is ambiguous
about what should happen in this case, i.e. the value of olditv after
the following code executes is unspecified:

struct itimerval newitv, olditv;

newitv.it_value.tv_sec = newitv.it_value.tv_usec = 0;
newitv.it_interval.tv_sec = newitv.it_interval.tv_usec = 1;
setitimer(ITIMER_REAL, &newitv, NULL);
getitimer(ITIMER_REAL, &olditv);

This change should not break any real code.

Reply via email to