Hey, this is a followup of this. The bug and my investigation is explained in detail there. I wanted to fix the issue but I need some clarification first.
From the Linux man page you see that the timer is defined as:
struct itimerval {
struct timeval it_interval; /* next value */
struct timeval it_value; /* current value */
};
So in the case where it_value = 2 secs and it_interval = 5 secs, this would result in SIGALARM to be fired after 2 seconds, then repeated signals are delivered every 5 seconds. However, since proc_raise_interval only supports a single interval value, this behaviour is not possible. And this creates a problem because for example: alarm function creates a delayed single shot signal. Hence it uses it_value only. This causes the signal to be never fired in WASIX.
Another confusion im seeing is although both the setitimer in non-WASIX libc and proc_raise_interval allows non-repeated signals, repetition is forcibly enabled in the WASIX implementation.
Possible paths
1. Support it_value and it_interval in proc_raise_interval
Change proc_raise_interval from:
(@interface func (export "proc_raise_interval")
(param $sig $signal)
(param $interval $timestamp)
(param $repeat $bool)
(result $error (expected (error $errno)))
)
to:
(@interface func (export "proc_raise_interval")
(param $sig $signal)
(param $value $timestamp)
(param $interval $timestamp)
(result $error (expected (error $errno)))
)
The new implementation will raise the signal after value milliseconds (disarm the timer if 0). If the interval is zero, the prior interval for that signal is cancelled, otherwise the signal is repeated every interval milliseconds.
Pros:
- The logic is almost identical to
setitimer.
Cons:
2. Allow it_value == it_interval
Instead of only parsing the interval in the setitimer implementation and hardcoding repeat to be true, do:
repeat = it_interval != 0;
int ts = 0;
if it_value == 0:
ts = 0; // disarm any timers
else if it_interval != 0:
ts = it_interval;
else:
ts = it_value;
int ret = __wasi_proc_raise_interval((__wasi_signal_t)__WASI_SIGNAL_ALRM, ts, repeat);
Pros:
- Supports both the single shot and repeated signals with interval.
- Requires no change to the WASIX API.
Cons:
- No support for different
it_value and it_interval which might cause unexpected effects in the programs that rely on this.
Hey, this is a followup of this. The bug and my investigation is explained in detail there. I wanted to fix the issue but I need some clarification first.
From the Linux man page you see that the timer is defined as:
So in the case where
it_value = 2 secsandit_interval = 5 secs, this would result inSIGALARMto be fired after 2 seconds, then repeated signals are delivered every 5 seconds. However, since proc_raise_interval only supports a single interval value, this behaviour is not possible. And this creates a problem because for example: alarm function creates a delayed single shot signal. Hence it usesit_valueonly. This causes the signal to be never fired in WASIX.Another confusion im seeing is although both the
setitimerin non-WASIX libc andproc_raise_intervalallows non-repeated signals,repetitionis forcibly enabled in the WASIX implementation.Possible paths
1. Support
it_valueandit_intervalinproc_raise_intervalChange
proc_raise_intervalfrom:to:
The new implementation will raise the signal after
valuemilliseconds (disarm the timer if 0). If theintervalis zero, the prior interval for that signal is cancelled, otherwise the signal is repeated everyintervalmilliseconds.Pros:
setitimer.Cons:
2. Allow
it_value == it_intervalInstead of only parsing the
intervalin thesetitimerimplementation and hardcodingrepeatto betrue, do:Pros:
Cons:
it_valueandit_intervalwhich might cause unexpected effects in the programs that rely on this.