1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"sd_event_now" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
12 <title>sd_event_now
</title>
13 <productname>systemd
</productname>
17 <contrib>Developer
</contrib>
18 <firstname>Lennart
</firstname>
19 <surname>Poettering
</surname>
20 <email>lennart@poettering.net
</email>
26 <refentrytitle>sd_event_now
</refentrytitle>
27 <manvolnum>3</manvolnum>
31 <refname>sd_event_now
</refname>
33 <refpurpose>Retrieve current event loop iteration timestamp
</refpurpose>
38 <funcsynopsisinfo>#include
<systemd/sd-event.h
></funcsynopsisinfo>
41 <funcdef>int
<function>sd_event_now
</function></funcdef>
42 <paramdef>sd_event *
<parameter>event
</parameter></paramdef>
43 <paramdef>clockid_t
<parameter>clock
</parameter></paramdef>
44 <paramdef>uint64_t *
<parameter>usec
</parameter></paramdef>
51 <title>Description
</title>
53 <para><function>sd_event_now()
</function> returns the time when
54 the most recent event loop iteration began. A timestamp
55 is taken right after returning from the event sleep, and before
56 dispatching any event sources. The
<parameter>event
</parameter>
57 parameter specifies the event loop object to retrieve the timestamp
58 from. The
<parameter>clock
</parameter> parameter specifies the clock to
59 retrieve the timestamp for, and is one of
60 <constant>CLOCK_REALTIME
</constant> (or equivalently
61 <constant>CLOCK_REALTIME_ALARM
</constant>),
62 <constant>CLOCK_MONOTONIC
</constant>, or
63 <constant>CLOCK_BOOTTIME
</constant> (or equivalently
64 <constant>CLOCK_BOOTTIME_ALARM
</constant>), see
65 <citerefentry project='man-pages'
><refentrytitle>clock_gettime
</refentrytitle><manvolnum>2</manvolnum></citerefentry>
66 for more information on the various clocks. The retrieved
67 timestamp is stored in the
<parameter>usec
</parameter> parameter,
68 in µs since the clock's epoch. If this function is invoked before
69 the first event loop iteration, the current time is returned, as
70 reported by
<function>clock_gettime()
</function>. To distinguish
71 this case from a regular invocation the return value will be
72 positive, and zero when the returned timestamp refers to an actual
73 event loop iteration.
</para>
77 <title>Return Value
</title>
79 <para>If the first event loop iteration has not run yet
80 <function>sd_event_now()
</function> writes current time to
81 <parameter>usec
</parameter> and returns a positive return value.
82 Otherwise, it will write the requested timestamp to
<parameter>usec
</parameter>
83 and return
0. On failure, the call returns a negative errno-style
90 <para>Returned values may indicate the following problems:
</para>
94 <term><constant>-EINVAL
</constant></term>
96 <listitem><para>An invalid parameter was
97 passed.
</para></listitem>
102 <term><constant>-EOPNOTSUPP
</constant></term>
104 <listitem><para>Unsupported clock type.
109 <term><constant>-ECHILD
</constant></term>
111 <listitem><para>The event loop object was created in a
112 different process.
</para></listitem>
117 <xi:include href=
"libsystemd-pkgconfig.xml" />
120 <title>See Also
</title>
123 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
124 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
125 <citerefentry><refentrytitle>sd_event_new
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
126 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
127 <citerefentry project='man-pages'
><refentrytitle>clock_gettime
</refentrytitle><manvolnum>2</manvolnum></citerefentry>