On 2022-02-04 18:57:27 +0100, Vincent Lefevre wrote:
> 2. Due to the above minor issue, the timer was set at the present
> time 18:43:00 (1643996580). But for some reason, the pause()
> that follows it is not interrupted. This is the real issue.
> This also makes the patched "at" unreliable as this yields a
> race condition: the timer may still expire before pause() is
> called, though this is normally rather unlikely, I think.
Well, according to the timer_create(2) man page, that's a sleep()
that should be used, not pause().
New patch attached, which also fixes another issue when
HAVE_CLOCK_GETTIME is not defined: in atd_setalarm(), the value
of the subtraction could be negative (unexpected, but possible),
then implicitly converted to unsigned int for sleep(), which is
obviously incorrect.
--
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
Index: at-3.2.4/atd.c
===================================================================
--- at-3.2.4.orig/atd.c
+++ at-3.2.4/atd.c
@@ -804,7 +804,7 @@ void atd_setalarm(time_t next)
{
timeout.it_value.tv_sec = next;
timer_settime(timer, TIMER_ABSTIME, &timeout, NULL);
- pause();
+ sleep(next - now);
}
#else
void timer_setup()
@@ -818,7 +818,7 @@ time_t atd_gettime()
void atd_setalarm(time_t next)
{
- sleep(next - atd_gettime());
+ sleep(next - now);
}
#endif
/* Global functions */
@@ -953,7 +953,7 @@ main(int argc, char *argv[])
daemon_setup();
do {
- now = time(NULL);
+ now = atd_gettime();
next_invocation = run_loop();
if ((next_invocation > now) && (!hupped)) {
atd_setalarm(next_invocation);