chiark / gitweb /
update TODO
[elogind.git] / man / sd-daemon.xml
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">
4
5 <!--
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
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.
14
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.
19
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/>.
22 -->
23
24 <refentry id="sd-daemon">
25
26         <refentryinfo>
27                 <title>sd-daemon</title>
28                 <productname>systemd</productname>
29
30                 <authorgroup>
31                         <author>
32                                 <contrib>Developer</contrib>
33                                 <firstname>Lennart</firstname>
34                                 <surname>Poettering</surname>
35                                 <email>lennart@poettering.net</email>
36                         </author>
37                 </authorgroup>
38         </refentryinfo>
39
40         <refmeta>
41                 <refentrytitle>sd-daemon</refentrytitle>
42                 <manvolnum>3</manvolnum>
43         </refmeta>
44
45         <refnamediv>
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>
57         </refnamediv>
58
59         <refsynopsisdiv>
60                 <funcsynopsis>
61                         <funcsynopsisinfo>#include &lt;systemd/sd-daemon.h&gt;</funcsynopsisinfo>
62                 </funcsynopsis>
63
64                 <cmdsynopsis>
65                         <command>pkg-config --cflags --libs libsystemd-daemon</command>
66                 </cmdsynopsis>
67
68         </refsynopsisdiv>
69
70         <refsect1>
71                 <title>Description</title>
72
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,
76                 as implemented by the
77                 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
78                 init system.</para>
79
80                 <para>See
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>
88
89                 <programlisting>#define SD_EMERG   "&lt;0&gt;"  /* system is unusable */
90 #define SD_ALERT   "&lt;1&gt;"  /* action must be taken immediately */
91 #define SD_CRIT    "&lt;2&gt;"  /* critical conditions */
92 #define SD_ERR     "&lt;3&gt;"  /* error conditions */
93 #define SD_WARNING "&lt;4&gt;"  /* warning conditions */
94 #define SD_NOTICE  "&lt;5&gt;"  /* normal but significant condition */
95 #define SD_INFO    "&lt;6&gt;"  /* informational */
96 #define SD_DEBUG   "&lt;7&gt;"  /* debug-level messages */</programlisting>
97
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>
108
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
114                 SD_INFO.</para>
115
116                 <example>
117                         <title>Hello World</title>
118
119                         <para>A daemon may log with the log level
120                         NOTICE by issuing this call:</para>
121
122                         <programlisting>fprintf(stderr, SD_NOTICE "Hello World!\n");</programlisting>
123                 </example>
124         </refsect1>
125
126         <refsect1>
127                 <title>Notes</title>
128
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
136                 for details.</para>
137
138                 <para>In addition, for details about the algorithms
139                 check the liberally licensed reference implementation
140                 sources:
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>
143
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                 <constant>libsystemd-daemon</constant> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
150                 file. Alternatively, applications consuming these APIs
151                 may copy the implementation into their source tree,
152                 either verbatim or in excerpts.</para>
153
154                 <para>The functions directly related to new-style
155                 daemons become NOPs when -DDISABLE_SYSTEMD is set
156                 during compilation and the reference implementation is
157                 used as drop-in files. In addition, if
158                 <filename>sd-daemon.c</filename> is compiled on
159                 non-Linux systems they become NOPs.</para>
160         </refsect1>
161
162         <refsect1>
163                 <title>See Also</title>
164                 <para>
165                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
166                         <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
167                         <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168                         <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
169                         <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
170                         <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
171                         <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
172                         <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
173                         <citerefentry><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
174                         <citerefentry><refentrytitle>sd-readahead</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
175                         <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
176                 </para>
177         </refsect1>
178
179 </refentry>