diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2020-10-13 17:33:40 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2020-10-13 17:33:40 +0000 |
commit | 5a41812b1748ad14f05d4d8a4296e6c34a86066a (patch) | |
tree | dd738efdba6b849f344ef589f3aee22398a98d10 /sys | |
parent | e1de68e12c24ff27e38b96feaccff4b37aa1f09b (diff) |
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.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_time.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index a56986bcaac..11d4e4c7b95 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.145 2020/10/13 16:43:44 cheloha Exp $ */ +/* $OpenBSD: kern_time.c,v 1.146 2020/10/13 17:33:39 cheloha Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -616,6 +616,8 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) return error; if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval)) return EINVAL; + if (!timerisset(&aitv.it_value)) + timerclear(&aitv.it_interval); newitvp = &aitv; } if (SCARG(uap, oitv) != NULL) { |