1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd-daemon</title><meta name="generator" content="DocBook XSL Stylesheets V1.77.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><a href="index.html">Index </a>·
2
<a href="systemd.directives.html">Directives </a>·
3
<a href="../python-systemd/index.html">Python </a>·
4
<a href="../libudev/index.html">libudev </a>·
5
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 202</span><hr><div class="refentry"><a name="sd-daemon"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd-daemon, SD_EMERG, SD_ALERT, SD_CRIT, SD_ERR, SD_WARNING, SD_NOTICE, SD_INFO, SD_DEBUG — Reference implementation of APIs for
6
new-style daemons</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <systemd/sd-daemon.h></pre></div><div class="cmdsynopsis"><p><code class="command">pkg-config --cflags --libs libsystemd-daemon</code> </p></div></div><div class="refsect1"><a name="idp3912992"></a><h2>Description</h2><p><code class="filename">sd-daemon.c</code> and
7
<code class="filename">sd-daemon.h</code> provide a reference
8
implementation of various APIs for new-style daemons,
10
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>
11
init system.</p><p>See
12
<a href="sd_listen_fds.html"><span class="citerefentry"><span class="refentrytitle">sd_listen_fds</span>(3)</span></a>,
13
<a href="sd_notify.html"><span class="citerefentry"><span class="refentrytitle">sd_notify</span>(3)</span></a>,
14
<a href="sd_booted.html"><span class="citerefentry"><span class="refentrytitle">sd_booted</span>(3)</span></a>,
15
<a href="sd_is_fifo.html"><span class="citerefentry"><span class="refentrytitle">sd_is_fifo</span>(3)</span></a>
16
for more information about the functions
17
implemented. In addition to these functions a couple
18
of logging prefixes are defined as macros:</p><pre class="programlisting">#define SD_EMERG "<0>" /* system is unusable */
19
#define SD_ALERT "<1>" /* action must be taken immediately */
20
#define SD_CRIT "<2>" /* critical conditions */
21
#define SD_ERR "<3>" /* error conditions */
22
#define SD_WARNING "<4>" /* warning conditions */
23
#define SD_NOTICE "<5>" /* normal but significant condition */
24
#define SD_INFO "<6>" /* informational */
25
#define SD_DEBUG "<7>" /* debug-level messages */</pre><p>These prefixes are intended to be used in
26
conjunction with STDERR-based logging as implemented
27
by systemd. If a systemd service definition file is
28
configured with <code class="varname">StandardError=syslog</code>
29
or <code class="varname">StandardError=kmsg</code> these
30
prefixes can be used to encode a log level in lines
31
printed. This is similar to the kernel
32
<code class="function">printk()</code>-style logging. See
33
<a href="klogctl.html"><span class="citerefentry"><span class="refentrytitle">klogctl</span>(2)</span></a>
34
for more information.</p><p>The log levels are identical to
35
<a href="syslog.html"><span class="citerefentry"><span class="refentrytitle">syslog</span>(3)</span></a>'s
36
log level system. To use these prefixes simply prefix
37
every line with one of these strings. A line that is
38
not prefixed will be logged at the default log level
39
SD_INFO.</p><div class="example"><a name="idp25744"></a><p class="title"><b>Example 1. Hello World</b></p><div class="example-contents"><p>A daemon may log with the log level
40
NOTICE by issuing this call:</p><pre class="programlisting">fprintf(stderr, SD_NOTICE "Hello World!\n");</pre></div></div><br class="example-break"></div><div class="refsect1"><a name="idp27872"></a><h2>Notes</h2><p>These interfaces are provided by the reference
41
implementation of APIs for new-style daemons and
42
distributed with the systemd package. The algorithms
43
they implement are simple, and can easily be
44
reimplemented in daemons if it is important to support
45
this interface without using the reference
46
implementation. See the respective function man pages
47
for details.</p><p>In addition, for details about the algorithms
48
check the liberally licensed reference implementation
50
<a class="ulink" href="http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c" target="_top">http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c</a>
51
and <a class="ulink" href="http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h" target="_top">http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h</a></p><p>These APIs are implemented in the reference
52
implementation's <code class="filename">sd-daemon.c</code> and
53
<code class="filename">sd-daemon.h</code> files. These
54
interfaces are available as shared library, which can
55
be compiled and linked to with the
56
<code class="literal">libsystemd-daemon</code>
57
<a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
58
file. Alternatively, applications consuming these APIs
59
may copy the implementation into their source tree,
60
either verbatim or in excerpts.</p><p>The functions directly related to new-style
61
daemons become NOPs when -DDISABLE_SYSTEMD is set
62
during compilation and the reference implementation is
63
used as drop-in files. In addition, if
64
<code class="filename">sd-daemon.c</code> is compiled on
65
non-Linux systems they become NOPs.</p></div><div class="refsect1"><a name="idp35984"></a><h2>See Also</h2><p>
66
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
67
<a href="sd_listen_fds.html"><span class="citerefentry"><span class="refentrytitle">sd_listen_fds</span>(3)</span></a>,
68
<a href="sd_notify.html"><span class="citerefentry"><span class="refentrytitle">sd_notify</span>(3)</span></a>,
69
<a href="sd_booted.html"><span class="citerefentry"><span class="refentrytitle">sd_booted</span>(3)</span></a>,
70
<a href="sd_is_fifo.html"><span class="citerefentry"><span class="refentrytitle">sd_is_fifo</span>(3)</span></a>,
71
<a href="daemon.html"><span class="citerefentry"><span class="refentrytitle">daemon</span>(7)</span></a>,
72
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>,
73
<a href="systemd.socket.html"><span class="citerefentry"><span class="refentrytitle">systemd.socket</span>(5)</span></a>,
74
<a href="fprintf.html"><span class="citerefentry"><span class="refentrytitle">fprintf</span>(3)</span></a>,
75
<a href="sd-readahead.html"><span class="citerefentry"><span class="refentrytitle">sd-readahead</span>(3)</span></a>,
76
<a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
77
</p></div></div></body></html>