diff --git a/src/linux/timer.c b/src/linux/timer.c index dfb0b4c..1de25dc 100644 --- a/src/linux/timer.c +++ b/src/linux/timer.c @@ -210,10 +210,16 @@ int evfilt_timer_knote_modify(struct filter *filt, struct knote *kn, const struct kevent64_s *kev) { - (void)filt; - (void)kn; - (void)kev; - return (0); /* STUB */ + struct itimerspec ts; + int tfd = kn->data.pfd; + + convert_to_itimerspec(&ts, kn->kev.data, kn->kev.flags & EV_ONESHOT, kn->kev.fflags); + if (timerfd_settime(tfd, 0, &ts, NULL) < 0) { + dbg_printf("timerfd_settime(2): %s", strerror(errno)); + return (-1); + } + + return (0); } int @@ -240,13 +246,23 @@ evfilt_timer_knote_delete(struct filter *filt, struct knote *kn) int evfilt_timer_knote_enable(struct filter *filt, struct knote *kn) { - return evfilt_timer_knote_create(filt, kn); + return evfilt_timer_knote_modify(filt, kn, &kn->kev); } int evfilt_timer_knote_disable(struct filter *filt, struct knote *kn) { - return evfilt_timer_knote_delete(filt, kn); + struct itimerspec ts; + int tfd = kn->data.pfd; + + memset(&ts, 0, sizeof(ts)); + + if (timerfd_settime(tfd, 0, &ts, NULL) < 0) { + dbg_printf("timerfd_settime(2): %s", strerror(errno)); + return (-1); + } + + return 0; } const struct filter evfilt_timer = {