diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c index 51ed6ed4c8..8b29b589d8 100644 --- a/criu/pie/restorer.c +++ b/criu/pie/restorer.c @@ -2210,7 +2210,7 @@ __visible long __export_restore_task(struct task_restore_args *args) * code below doesn't fail due to bad timing values. */ -#define itimer_armed(args, i) (args->itimers[i].it_interval.tv_sec || args->itimers[i].it_interval.tv_usec) +#define itimer_armed(args, i) (args->itimers[i].it_interval.tv_sec || args->itimers[i].it_interval.tv_usec || args->itimers[i].it_value.tv_sec || args->itimers[i].it_value.tv_usec) if (itimer_armed(args, 0)) sys_setitimer(ITIMER_REAL, &args->itimers[0], NULL); diff --git a/criu/timer.c b/criu/timer.c index e94cf0280d..64d79704de 100644 --- a/criu/timer.c +++ b/criu/timer.c @@ -16,7 +16,7 @@ static inline int timeval_valid(struct timeval *tv) static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val) { - if (ie->isec == 0 && ie->iusec == 0) { + if (ie->isec == 0 && ie->iusec == 0 && ie->vsec == 0 && ie->vusec == 0) { memzero_p(val); return 0; } @@ -29,17 +29,8 @@ static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val) return -1; } - if (ie->vsec == 0 && ie->vusec == 0) { - /* - * Remaining time was too short. Set it to - * interval to make the timer armed and work. - */ - val->it_value.tv_sec = ie->isec; - val->it_value.tv_usec = ie->iusec; - } else { - val->it_value.tv_sec = ie->vsec; - val->it_value.tv_usec = ie->vusec; - } + val->it_value.tv_sec = ie->vsec; + val->it_value.tv_usec = ie->vusec; if (!timeval_valid(&val->it_value)) { pr_err("Invalid timer value\n"); diff --git a/test/zdtm/static/timers.c b/test/zdtm/static/timers.c index e5f7f2a022..5a919f2b5c 100644 --- a/test/zdtm/static/timers.c +++ b/test/zdtm/static/timers.c @@ -33,13 +33,9 @@ static void timer_tick(int sig) } } -static void setup_timers(void) +static void setup_timers(const struct itimerval *tv) { int i; - struct itimerval tv = { - .it_interval = { .tv_sec = 0, .tv_usec = 100000 }, - .it_value = { .tv_sec = 0, .tv_usec = 100 }, - }; for (i = 0; i < NUM_TIMERS; i++) { if (signal(timer_tests[i].signal, timer_tick) == SIG_ERR) { @@ -47,7 +43,7 @@ static void setup_timers(void) exit(1); } - if (setitimer(timer_tests[i].timer_type, &tv, NULL) < 0) { + if (setitimer(timer_tests[i].timer_type, tv, NULL) < 0) { pr_perror("can't set timer %d", i); exit(1); } @@ -77,13 +73,27 @@ static void check_timers(void) int main(int argc, char **argv) { - test_init(argc, argv); + const struct itimerval tv = { + .it_interval = { .tv_sec = 0, .tv_usec = 100000 }, + .it_value = { .tv_sec = 0, .tv_usec = 100 }, + }; + const struct itimerval oneshot_tv = { + .it_interval = { .tv_sec = 0, .tv_usec = 0 }, + .it_value = { .tv_sec = 1, .tv_usec = 100 }, + }; + const struct itimerval tvs[2] = { + tv, + oneshot_tv, + }; - setup_timers(); + test_init(argc, argv); + for (int i = 0; i < 2; i++) { + setup_timers(&tvs[i]); - test_daemon(); - test_waitsig(); + test_daemon(); + test_waitsig(); - check_timers(); + check_timers(); + } return 0; }