1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd-daemon">
27 <title>sd-daemon</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd-daemon</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd-daemon</refname>
47 <refname>SD_EMERG</refname>
48 <refname>SD_ALERT</refname>
49 <refname>SD_CRIT</refname>
50 <refname>SD_ERR</refname>
51 <refname>SD_WARNING</refname>
52 <refname>SD_NOTICE</refname>
53 <refname>SD_INFO</refname>
54 <refname>SD_DEBUG</refname>
55 <refpurpose>Reference implementation of APIs for
56 new-style daemons</refpurpose>
61 <funcsynopsisinfo>#include <systemd/sd-daemon.h></funcsynopsisinfo>
65 <command>pkg-config --cflags --libs libsystemd-daemon</command>
71 <title>Description</title>
73 <para><filename>sd-daemon.c</filename> and
74 <filename>sd-daemon.h</filename> provide a reference
75 implementation of various APIs for new-style daemons,
77 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
81 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
82 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
83 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
84 <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>
85 for more information about the functions
86 implemented. In addition to these functions a couple
87 of logging prefixes are defined as macros:</para>
89 <programlisting>#define SD_EMERG "<0>" /* system is unusable */
90 #define SD_ALERT "<1>" /* action must be taken immediately */
91 #define SD_CRIT "<2>" /* critical conditions */
92 #define SD_ERR "<3>" /* error conditions */
93 #define SD_WARNING "<4>" /* warning conditions */
94 #define SD_NOTICE "<5>" /* normal but significant condition */
95 #define SD_INFO "<6>" /* informational */
96 #define SD_DEBUG "<7>" /* debug-level messages */</programlisting>
98 <para>These prefixes are intended to be used in
99 conjunction with STDERR-based logging as implemented
100 by systemd. If a systemd service definition file is
101 configured with <varname>StandardError=syslog</varname>
102 or <varname>StandardError=kmsg</varname> these
103 prefixes can be used to encode a log level in lines
104 printed. This is similar to the kernel
105 <function>printk()</function>-style logging. See
106 <citerefentry><refentrytitle>klogctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
107 for more information.</para>
109 <para>The log levels are identical to
110 <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s
111 log level system. To use these prefixes simply prefix
112 every line with one of these strings. A line that is
113 not prefixed will be logged at the default log level
117 <title>Hello World</title>
119 <para>A daemon may log with the log level
120 NOTICE by issuing this call:</para>
122 <programlisting>fprintf(stderr, SD_NOTICE "Hello World!\n");</programlisting>
129 <para>These interfaces are provided by the reference
130 implementation of APIs for new-style daemons and
131 distributed with the systemd package. The algorithms
132 they implement are simple, and can easily be
133 reimplemented in daemons if it is important to support
134 this interface without using the reference
135 implementation. See the respective function man pages
138 <para>In addition, for details about the algorithms
139 check the liberally licensed reference implementation
141 <ulink url="http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c"/>
142 and <ulink url="http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h"/></para>
144 <para>These APIs are implemented in the reference
145 implementation's <filename>sd-daemon.c</filename> and
146 <filename>sd-daemon.h</filename> files. These
147 interfaces are available as shared library, which can
148 be compiled and linked to with the
149 <literal>libsystemd-daemon</literal>
150 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
151 file. Alternatively, applications consuming these APIs
152 may copy the implementation into their source tree,
153 either verbatim or in excerpts.</para>
155 <para>The functions directly related to new-style
156 daemons become NOPs when -DDISABLE_SYSTEMD is set
157 during compilation and the reference implementation is
158 used as drop-in files. In addition, if
159 <filename>sd-daemon.c</filename> is compiled on
160 non-Linux systems they become NOPs.</para>
164 <title>See Also</title>
166 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
167 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
169 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
170 <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
173 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
174 <citerefentry><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
175 <citerefentry><refentrytitle>sd-readahead</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
176 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>