Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F95912729
D32230.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D32230.diff
View Options
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -798,13 +798,13 @@
return (EINVAL);
*to = timer2sbintime(kn->kn_sdata, kn->kn_sfflags);
+ if (*to < 0)
+ return (EINVAL);
if ((kn->kn_sfflags & NOTE_ABSTIME) != 0) {
getboottimebin(&bt);
sbt = bttosbt(bt);
- *to -= sbt;
+ *to = MAX(0, *to - sbt);
}
- if (*to < 0)
- return (EINVAL);
return (0);
}
@@ -815,9 +815,14 @@
sbintime_t to;
int error;
+ to = -1;
error = filt_timervalidate(kn, &to);
if (error != 0)
return (error);
+ KASSERT((kn->kn_flags & EV_ONESHOT) != 0 || to > 0,
+ ("%s: periodic timer has a calculated zero timeout", __func__));
+ KASSERT(to >= 0,
+ ("%s: timer has a calculated negative timeout", __func__));
if (atomic_fetchadd_int(&kq_ncallouts, 1) + 1 > kq_calloutmax) {
atomic_subtract_int(&kq_ncallouts, 1);
diff --git a/tests/sys/kqueue/libkqueue/timer.c b/tests/sys/kqueue/libkqueue/timer.c
--- a/tests/sys/kqueue/libkqueue/timer.c
+++ b/tests/sys/kqueue/libkqueue/timer.c
@@ -247,6 +247,88 @@
success();
}
+static void
+test_abstime_preboot(void)
+{
+ const char *test_id = "kevent(EVFILT_TIMER (PREBOOT), EV_ONESHOT, NOTE_ABSTIME)";
+ struct kevent kev;
+ struct timespec btp;
+ uint64_t end, start, stop;
+
+ test_begin(test_id);
+
+ test_no_kevents();
+
+ /*
+ * We'll expire it at just before system boot (roughly) with the hope that
+ * we'll get an ~immediate expiration, just as we do for any value specified
+ * between system boot and now.
+ */
+ start = now();
+ if (clock_gettime(CLOCK_BOOTTIME, &btp) != 0)
+ err(1, "%s", test_id);
+
+ end = start - SEC_TO_US(btp.tv_sec + 1);
+ EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
+ NOTE_ABSTIME | NOTE_USECONDS, end, NULL);
+ if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
+ err(1, "%s", test_id);
+
+ /* Retrieve the event */
+ kev.flags = EV_ADD | EV_ONESHOT;
+ kev.data = 1;
+ kev.fflags = 0;
+ kevent_cmp(&kev, kevent_get(kqfd));
+
+ stop = now();
+ if (stop < end)
+ err(1, "too early %jd %jd", (intmax_t)stop, (intmax_t)end);
+ /* Check if the event occurs again */
+ sleep(3);
+ test_no_kevents();
+
+ success();
+}
+
+static void
+test_abstime_postboot(void)
+{
+ const char *test_id = "kevent(EVFILT_TIMER (POSTBOOT), EV_ONESHOT, NOTE_ABSTIME)";
+ struct kevent kev;
+ uint64_t end, start, stop;
+ const int timeout_sec = 1;
+
+ test_begin(test_id);
+
+ test_no_kevents();
+
+ /*
+ * Set a timer for 1 second ago, it should fire immediately rather than
+ * being rejected.
+ */
+ start = now();
+ end = start - SEC_TO_US(timeout_sec);
+ EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
+ NOTE_ABSTIME | NOTE_USECONDS, end, NULL);
+ if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
+ err(1, "%s", test_id);
+
+ /* Retrieve the event */
+ kev.flags = EV_ADD | EV_ONESHOT;
+ kev.data = 1;
+ kev.fflags = 0;
+ kevent_cmp(&kev, kevent_get(kqfd));
+
+ stop = now();
+ if (stop < end)
+ err(1, "too early %jd %jd", (intmax_t)stop, (intmax_t)end);
+ /* Check if the event occurs again */
+ sleep(3);
+ test_no_kevents();
+
+ success();
+}
+
static void
test_update(void)
{
@@ -517,6 +599,8 @@
test_oneshot();
test_periodic();
test_abstime();
+ test_abstime_preboot();
+ test_abstime_postboot();
test_update();
test_update_equal();
test_update_expired();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 24, 12:26 AM (12 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
12557903
Default Alt Text
D32230.diff (3 KB)
Attached To
Mode
D32230: kqueue: don't arbitrarily restrict long-past values for NOTE_ABSTIME
Attached
Detach File
Event Timeline
Log In to Comment