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 General Public License as published by
12 the Free Software Foundation; either version 2 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 General Public License for more details.
20 You should have received a copy of the GNU 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>7</manvolnum>
46 <refname>sd-daemon</refname>
47 <refpurpose>Reference implementation of APIs for
48 new-style daemons</refpurpose>
53 <funcsynopsisinfo>#include <systemd/sd-daemon.h></funcsynopsisinfo>
57 <command>pkg-config --cflags --libs libsystemd-daemon</command>
63 <title>Description</title>
65 <para><filename>sd-daemon.c</filename> and
66 <filename>sd-daemon.h</filename> provide a reference
67 implementation of various APIs for new-style daemons,
69 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
73 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
74 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
75 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
76 <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>
77 for more information about the functions
78 implemented. In addition to these functions a couple
79 of logging prefixes are defined as macros:</para>
81 <programlisting>#define SD_EMERG "<0>" /* system is unusable */
82 #define SD_ALERT "<1>" /* action must be taken immediately */
83 #define SD_CRIT "<2>" /* critical conditions */
84 #define SD_ERR "<3>" /* error conditions */
85 #define SD_WARNING "<4>" /* warning conditions */
86 #define SD_NOTICE "<5>" /* normal but significant condition */
87 #define SD_INFO "<6>" /* informational */
88 #define SD_DEBUG "<7>" /* debug-level messages */</programlisting>
90 <para>These prefixes are intended to be used in
91 conjunction with STDERR-based logging as implemented
92 by systemd. If a systemd service definition file is
93 configured with <varname>StandardError=syslog</varname>
94 or <varname>StandardError=kmsg</varname> these
95 prefixes can be used to encode a log level in lines
96 printed. This is similar to the kernel
97 <function>printk()</function>-style logging. See
98 <citerefentry><refentrytitle>klogctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
99 for more information.</para>
101 <para>The log levels are identical to
102 <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s
103 log level system. To use these prefixes simply prefix
104 every line with one of these strings. A line that is
105 not prefixed will be logged at the default log level
109 <title>Hello World</title>
111 <para>A daemon may log with the log level
112 NOTICE by issuing this call:</para>
114 <programlisting>fprintf(stderr, SD_NOTICE "Hello World!\n");</programlisting>
121 <para>These interfaces are provided by the reference
122 implementation of APIs for new-style daemons and
123 distributed with the systemd package. The algorithms
124 they implement are simple, and can easily be
125 reimplemented in daemons if it is important to support
126 this interface without using the reference
127 implementation. See the respective function man pages
130 <para>In addition, for details about the algorithms
131 check the liberally licensed reference implementation
133 <ulink url="http://cgit.freedesktop.org/systemd/systemd/plain/src/sd-daemon.c"/>
134 resp. <ulink url="http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h"/></para>
136 <para>These APIs are implemented in the reference
137 implementation's <filename>sd-daemon.c</filename> and
138 <filename>sd-daemon.h</filename> files. These
139 interfaces are available as shared library, which can
140 be compiled and linked to with the
141 <literal>libsystemd-daemon</literal>
142 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
143 file. Alternatively, applications consuming these APIs
144 may copy the implementation into their source tree,
145 either verbatim or in excerpts.</para>
147 <para>The functions directly related to new-style
148 daemons become NOPs when -DDISABLE_SYSTEMD is set
149 during compilation and the reference implementation is
150 used as drop-in files. In addition, if
151 <filename>sd-daemon.c</filename> is compiled on
152 non-Linux systems they become NOPs.</para>
156 <title>See Also</title>
158 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161 <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
163 <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
164 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
165 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
166 <citerefentry><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
167 <citerefentry><refentrytitle>sd-readahead</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
168 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>