chiark / gitweb /
sd-event: check clock argument to sd_event_now()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 11 Jan 2016 22:19:25 +0000 (17:19 -0500)
committerSven Eden <yamakuzure@gmx.net>
Wed, 17 May 2017 13:22:15 +0000 (15:22 +0200)
sd_event_now() is a public function, so we must check all
arguments for validity. Update man page and add tests.

Sample debug message:
Assertion 'IN_SET(clock, CLOCK_REALTIME, CLOCK_REALTIME_ALARM, CLOCK_MONOTONIC, CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM)' failed at src/libelogind/sd-event/sd-event.c:2719, function sd_event_now(). Ignoring.

man/sd_event_now.xml
src/libelogind/sd-event/sd-event.c

index 4491677c90652b60617e9e868796d0c456bba066..578213cd7cdf14db846865eb5bbba081eaae4b0d 100644 (file)
 
       </varlistentry>
 
+      <varlistentry>
+        <term><constant>-EOPNOTSUPP</constant></term>
+
+        <listitem><para>Unsupported clock type.
+        </para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><constant>-ECHILD</constant></term>
 
         <listitem><para>The event loop object was created in a
         different process.</para></listitem>
       </varlistentry>
-
     </variablelist>
   </refsect1>
 
index 79788ea3fd349bb90322b49756a2c8bdd1fbae2e..4d7f4620684f941df8b5867284e55f8c19240690 100644 (file)
@@ -2771,6 +2771,12 @@ _public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) {
         assert_return(e, -EINVAL);
         assert_return(usec, -EINVAL);
         assert_return(!event_pid_changed(e), -ECHILD);
+        assert_return(IN_SET(clock,
+                             CLOCK_REALTIME,
+                             CLOCK_REALTIME_ALARM,
+                             CLOCK_MONOTONIC,
+                             CLOCK_BOOTTIME,
+                             CLOCK_BOOTTIME_ALARM), -EOPNOTSUPP);
 
         if (!dual_timestamp_is_set(&e->timestamp)) {
                 /* Implicitly fall back to now() if we never ran
@@ -2790,8 +2796,7 @@ _public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) {
                 *usec = e->timestamp.monotonic;
                 break;
 
-        case CLOCK_BOOTTIME:
-        case CLOCK_BOOTTIME_ALARM:
+        default:
                 *usec = e->timestamp_boottime;
                 break;
         }