diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-06-23 00:31:54 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-06-23 00:31:54 +0200 |
commit | f9378423b9758861850748aeb49ae0d3300e56e6 (patch) | |
tree | ecf859a04ad64bde5fd3f17daa44c8931a6bcac1 | |
parent | a3723b97efba3f93dd06630e5315c4f8e626cdd7 (diff) | |
download | systemd-f9378423b9758861850748aeb49ae0d3300e56e6.tar.gz |
man: document sd-daemon.[ch]
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile.am | 36 | ||||
-rw-r--r-- | man/sd-daemon.xml | 162 | ||||
-rw-r--r-- | man/sd_booted.xml | 122 | ||||
-rw-r--r-- | man/sd_is_fifo.xml | 199 | ||||
-rw-r--r-- | man/sd_listen_fds.xml | 178 | ||||
-rw-r--r-- | man/sd_notify.xml | 277 | ||||
-rw-r--r-- | src/sd-daemon.h | 9 |
8 files changed, 980 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore index ed881d7856..7e44eaa1b4 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,10 @@ systemd-logger systemctl systemadm .dirstamp +*.3 *.5 *.7 +*.8 *.html *~ *.tar.gz @@ -45,4 +47,6 @@ stamp-* Makefile ltmain.sh *.tar.bz2 +*.tar.gz +*.tar.xz libtool diff --git a/Makefile.am b/Makefile.am index f1bc036907..0f9ef8eabc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -307,7 +307,13 @@ EXTRA_DIST += \ dist_man_MANS = \ man/systemd.unit.5 \ man/systemd.service.5 \ - man/daemon.7 + man/daemon.7 \ + man/systemd.8 \ + man/sd_notify.3 \ + man/sd_booted.3 \ + man/sd_listen_fds.3 \ + man/sd_is_fifo.3 \ + man/sd-daemon.7 nodist_man_MANS = \ man/systemd.special.7 @@ -315,7 +321,13 @@ nodist_man_MANS = \ dist_noinst_DATA = \ man/systemd.unit.html \ man/systemd.service.html \ - man/daemon.html + man/daemon.html \ + man/systemd.html \ + man/sd_notify.html \ + man/sd_booted.html \ + man/sd_listen_fds.html \ + man/sd_is_fifo.html \ + man/sd-daemon.html nodist_noinst_DATA = \ man/systemd.special.html @@ -326,7 +338,13 @@ EXTRA_DIST += \ man/systemd.special.xml.in \ man/systemd.special.7.in \ man/systemd.special.html.in \ - man/daemon.xml + man/daemon.xml \ + man/systemd.xml \ + man/sd_notify.xml \ + man/sd_booted.xml \ + man/sd_listen_fds.xml \ + man/sd_is_fifo.xml \ + man/sd-daemon.xml systemd_SOURCES = \ src/main.c @@ -570,6 +588,12 @@ XSLTPROC_PROCESS_HTML_IN = \ $(XSLTPROC) -o ${@:.in=} --nonet http://docbook.sourceforge.net/release/xsl/current/xhtml-1_1/docbook.xsl $< && \ mv ${@:.in=} $@ +man/%.3: man/%.xml + $(XSLTPROC_PROCESS_MAN) + +man/%.3.in: man/%.xml.in + $(XSLTPROC_PROCESS_MAN) + man/%.5: man/%.xml $(XSLTPROC_PROCESS_MAN) @@ -582,6 +606,12 @@ man/%.7: man/%.xml man/%.7.in: man/%.xml.in $(XSLTPROC_PROCESS_MAN_IN) +man/%.8: man/%.xml + $(XSLTPROC_PROCESS_MAN) + +man/%.8.in: man/%.xml.in + $(XSLTPROC_PROCESS_MAN_IN) + man/%.html: man/%.xml $(XSLTPROC_PROCESS_HTML) diff --git a/man/sd-daemon.xml b/man/sd-daemon.xml new file mode 100644 index 0000000000..2acc021041 --- /dev/null +++ b/man/sd-daemon.xml @@ -0,0 +1,162 @@ +<?xml version='1.0'?> <!--*-nxml-*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> + +<!-- + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> + +<refentry id="sd-daemon"> + + <refentryinfo> + <title>sd-daemon</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>sd-daemon</refentrytitle> + <manvolnum>7</manvolnum> + </refmeta> + + <refnamediv> + <refname>sd-daemon</refname> + <refpurpose>Reference implementation of APIs for + new-style daemons</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo>#include "sd-daemon.h"</funcsynopsisinfo> + </funcsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para><filename>sd-daemon.c</filename> and + <filename>sd-daemon.h</filename> provide a reference + implementation of various APIs for new-style daemons, + as implemented by the + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> + init system.</para> + + <para>See + <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry> + for more information about the functions + implemented. In addition to these functions a couple + of logging prefixes are defined as macros:</para> + + <programlisting>#define SD_EMERG "<0>" /* system is unusable */ +#define SD_ALERT "<1>" /* action must be taken immediately */ +#define SD_CRIT "<2>" /* critical conditions */ +#define SD_ERR "<3>" /* error conditions */ +#define SD_WARNING "<4>" /* warning conditions */ +#define SD_NOTICE "<5>" /* normal but significant condition */ +#define SD_INFO "<6>" /* informational */ +#define SD_DEBUG "<7>" /* debug-level messages */</programlisting> + + <para>These prefixes are intended to be used in + conjunction with STDERR-based logging as implemented + by systemd. If a systemd service definition file is + configured with <varname>StandardError=syslog</varname> + or <varname>StandardError=kmsg</varname> these + prefixes can be used to encode a log level in lines + printed. This is similar to the kernel + <function>printk()</function>-style logging. See + <citerefentry><refentrytitle>klogctl</refentrytitle><manvolnum>2</manvolnum></citerefentry> + for more information.</para> + + <para>The log levels are identical to + <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s + log level system. To use these prefixes simply prefix + every line with one of these strings. A line that is + not prefixed will be logged at the default log level + SD_INFO.</para> + + <example> + <title>Hello World</title> + + <para>A daemon may log with the log level + NOTICE by issuing this call:</para> + + <programlisting>fprintf(stderr, SD_NOTICE "Hello World!\n");</programlisting> + </example> + </refsect1> + + <refsect1> + <title>Notes</title> + + <para>These interfaces are provided by the reference + implementation of APIs for new-style daemons and + distributed with the systemd package. The algorithms + they implement are simple, and can easily be + reimplemented in daemons if it is important to support + this interface without using the reference + implementation. See the respective function man pages + for details.</para> + + <para>In addition, for details about the algorithms + check the liberally licensed reference implementation + sources: + <ulink url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c"/> + resp. <ulink url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.h"/></para> + + <para>These APIs are implemented in the reference + implementation's drop-in + <filename>sd-daemon.c</filename> and + <filename>sd-daemon.h</filename> files. It is + recommended that applications consuming these APIs copy + the implementation into their source tree, either + verbatim or in excerpts. These interfaces are + currently not available in a dynamic library.</para> + + <para>The functions directly related to new-style + daemons become NOPs when -DDISABLE_SYSTEMD is set + during compilation. In addition, if + <filename>sd-daemon.c</filename> is compiled on + non-Linux systems they become NOPs, too.</para> + </refsect1> + + <refsect1> + <title>See Also</title> + <para> + <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_booted</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>, + <citerefentry><refentrytitle>fprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/man/sd_booted.xml b/man/sd_booted.xml new file mode 100644 index 0000000000..6129a777c2 --- /dev/null +++ b/man/sd_booted.xml @@ -0,0 +1,122 @@ +<?xml version='1.0'?> <!--*-nxml-*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> + +<!-- + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> + +<refentry id="sd_booted"> + + <refentryinfo> + <title>sd_booted</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>sd_booted</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>sd_booted</refname> + <refpurpose>Test whether the system is running the systemd init system.</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo>#include "sd-daemon.h"</funcsynopsisinfo> + + <funcprototype> + <funcdef>int <function>sd_booted</function></funcdef> + <paramdef>void</paramdef> + </funcprototype> + </funcsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + <para><function>sd_booted()</function> checks whether + the system was booted up using the systemd init system.</para> + </refsect1> + + <refsect1> + <title>Return Value</title> + + <para>On failure, this call returns a negative + errno-style error code. If the system was booted up + with systemd as init system this call returns a + postive return value, zero otherwise.</para> + </refsect1> + + <refsect1> + <title>Notes</title> + + <para>This function is provided by the reference + implementation of APIs for new-style daemons and + distributed with the systemd package. The algorithm it + implements is simple, and can easily be reimplemented + in daemons if it is important to support this + interface without using the reference + implementation.</para> + + <para>Internally, this function checks whether the + <filename>/cgroup/systemd</filename> virtual file + system is mounted, by comparing the st_dev value of + the <function>stat()</function> data of + <filename>/cgroup</filename> and + <filename>/cgroup/systemd</filename>.</para> + + <para>For details about the algorithm check the + liberally licensed reference implementation sources: + <ulink url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c"/> + resp. <ulink + url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.h"/></para> + + <para><function>sd_booted()</function> is implemented + in the reference implementation's drop-in + <filename>sd-daemon.c</filename> and + <filename>sd-daemon.h</filename> files. It is + recommended that applications consuming these APIs + copy the implementation into their source tree. For + more details about the reference implementation see + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry></para> + + <para>If -DDISABLE_SYSTEMD is set during compilation + this function will always return 0 and otherwise + become a NOP.</para> + </refsect1> + + <refsect1> + <title>See Also</title> + <para> + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/man/sd_is_fifo.xml b/man/sd_is_fifo.xml new file mode 100644 index 0000000000..2389546130 --- /dev/null +++ b/man/sd_is_fifo.xml @@ -0,0 +1,199 @@ +<?xml version='1.0'?> <!--*-nxml-*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> + +<!-- + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> + +<refentry id="sd_is_fifo"> + + <refentryinfo> + <title>sd_is_fifo</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>sd_is_fifo</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>sd_is_fifo</refname> + <refname>sd_is_socket</refname> + <refname>sd_is_socket_inet</refname> + <refname>sd_is_socket_unix</refname> + <refpurpose>Check the type of a file descriptor</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo>#include "sd-daemon.h"</funcsynopsisinfo> + + <funcprototype> + <funcdef>int <function>sd_is_fifo</function></funcdef> + <paramdef>int <parameter>fd</parameter></paramdef> + <paramdef>const char *<parameter>path</parameter></paramdef> + </funcprototype> + + <funcprototype> + <funcdef>int <function>sd_is_socket</function></funcdef> + <paramdef>int <parameter>fd</parameter></paramdef> + <paramdef>int <parameter>family</parameter></paramdef> + <paramdef>int <parameter>type</parameter></paramdef> + <paramdef>int <parameter>listening</parameter></paramdef> + </funcprototype> + + <funcprototype> + <funcdef>int <function>sd_is_socket_inet</function></funcdef> + <paramdef>int <parameter>fd</parameter></paramdef> + <paramdef>int <parameter>family</parameter></paramdef> + <paramdef>int <parameter>type</parameter></paramdef> + <paramdef>int <parameter>listening</parameter></paramdef> + <paramdef>uint16_t <parameter>port</parameter></paramdef> + </funcprototype> + + <funcprototype> + <funcdef>int <function>sd_is_socket_unix</function></funcdef> + <paramdef>int <parameter>fd</parameter></paramdef> + <paramdef>int <parameter>type</parameter></paramdef> + <paramdef>int <parameter>listening</parameter></paramdef> + <paramdef>const char* <parameter>path</parameter></paramdef> + <paramdef>size_t <parameter>length</parameter></paramdef> + </funcprototype> + + </funcsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para><function>sd_is_fifo()</function> may be called + to check whether the specified file descriptor refers + to a FIFO or pipe. It the <parameter>path</parameter> + parameter is not NULL it is checked whether the FIFO + is bound to the specified file system path.</para> + + <para><function>sd_is_socket()</function> may be + called to check whether the specified file descriptor + refers to a socket. It the + <parameter>family</parameter> parameter is not + AF_UNSPEC it is checked whether the socket is of the + specified family (AF_UNIX, AF_INET, ...). If the + <parameter>type</parameter> parameter is not 0 it is + checked whether the socket is of the specified type + (SOCK_STREAM, SOCK_DGRAM, ...). If the + <parameter>listening</parameter> parameter is positive + it is checked whether the socket is in accepting mode, + i.e. <function>listen()</function> has been called for + it. If <parameter>listening</parameter> is 0, it is + checked whether the socket is not in this mode. If the + parameter is negative, no such check is made. The + <parameter>listening</parameter> parameter should only + be used for stream sockets and should be set to a + negative value otherwise.</para> + + <para><function>sd_is_socket_inet()</function> is + similar to <function>sd_is_socket()</function>, but + optionally checks the IPv4 or IPv6 port number the + socket is bound to, unless <parameter>port</parameter> + is zero. For this call <parameter>family</parameter> + must be passed as either AF_UNSPEC, AF_INET or + AF_INET6.</para> + + <para><function>sd_is_socket_unix()</function> is + similar to <function>sd_is_socket()</function>, but + optionally checks the AF_UNIX path the socket is bound + to, unless the <parameter>path</parameter> parameter + is NULL. For normal file system AF_UNIX sockets set + the <parameter>length</parameter> parameter to 0. For + Linux abstract namespace sockets set the + <parameter>length</parameter> to the size of the + address, including the initial 0 byte and set + <parameter>path</parameter> to the initial 0 byte of + the socket address.</para> + </refsect1> + + <refsect1> + <title>Return Value</title> + + <para>On failure, these calls return a negative + errno-style error code. If the file descriptor is of + the specified type and bound to the specified address + a positive return value is returned, otherwise + zero.</para> + </refsect1> + + <refsect1> + <title>Notes</title> + + <para>These functions are provided by the reference + implementation of APIs for new-style daemons and + distributed with the systemd package. The algorithms + they implement are simple, and can easily be + reimplemented in daemons if it is important to support + this interface without using the reference + implementation.</para> + + <para>Internally, these function use a combination of + <filename>fstat()</filename> and + <filename>getsockname()</filename> to check the file + descriptor type and where it is bound to.</para> + + <para>For details about the algorithm check the + liberally licensed reference implementation sources: + <ulink url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c"/> + resp. <ulink + url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.h"/></para> + + <para><function>sd_is_fifo()</function> and the + related functions are implemented in the reference + implementation's drop-in + <filename>sd-daemon.c</filename> and + <filename>sd-daemon.h</filename> files. It is + recommended that applications consuming these APIs + copy the implementation into their source tree. For + more details about the reference implementation see + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry></para> + + <para>These functions continue to work as described, + even if -DDISABLE_SYSTEMD is set during + compilation.</para> + </refsect1> + + <refsect1> + <title>See Also</title> + <para> + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/man/sd_listen_fds.xml b/man/sd_listen_fds.xml new file mode 100644 index 0000000000..10ea57c972 --- /dev/null +++ b/man/sd_listen_fds.xml @@ -0,0 +1,178 @@ +<?xml version='1.0'?> <!--*-nxml-*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> + +<!-- + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> + +<refentry id="sd_listen_fds"> + + <refentryinfo> + <title>sd_listen_fds</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>sd_listen_fds</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>sd_listen_fds</refname> + <refpurpose>Check for file descriptors passed by the init system.</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo>#include "sd-daemon.h"</funcsynopsisinfo> + + <funcsynopsisinfo>#define SD_LISTEN_FDS_START 3</funcsynopsisinfo> + + <funcprototype> + <funcdef>int <function>sd_listen_fds</function></funcdef> + <paramdef>int <parameter>unset_environment</parameter></paramdef> + </funcprototype> + </funcsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para><function>sd_listen_fds()</function> shall be + called by a daemon to check for file descriptors + passed by the init system as part of the socket-based + activation logic.</para> + + <para>If the <parameter>unset_environment</parameter> + parameter is non-zero + <function>sd_listen_fds()</function> will unset the + <varname>$LISTEN_FDS</varname>/<varname>$LISTEN_PID</varname> + environment variables before returning (regardless + whether the function call itself succeeded or + not). Further calls to + <function>sd_listen_fds()</function> will then fail, + but the variables are no longer inherited by child + processes.</para> + + <para>If a daemon receives more than one file + descriptor, they will be passed in the same order as + configured in the systemd socket definition + file. Nonetheless it is recommended to verify the + correct socket types before using them. To simplify + this checking the functions + <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_socket</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_socket_inet</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_socket_unix</refentrytitle><manvolnum>3</manvolnum></citerefentry> + are provided. In order to maximize flexibility it is + recommened to make these checks as loose as possible + without allowing incorrect setups. i.e. often the + actual port number a socket is bound to matters little + for the service to work, hence it should not be + verified. On the other hand, whether a socket is a + datagram or stream socket matters a lot for the most + common program logics and should hence be + checked.</para> + + <para>This function call will set the FD_CLOEXEC flag + for all passed file descriptors to avoid further + inheritance to children of the calling process.</para> + </refsect1> + + <refsect1> + <title>Return Value</title> + + <para>On failure, this call returns a negative + errno-style error code. If + <varname>$LISTEN_FDS</varname>/<varname>$LISTEN_PID</varname> + was not set or not correctly set for this daemon and + hence no file descriptors received 0 is + returned. Otherwise the number of file descriptors + passed is returned, the application may find them + starting with file descriptor SD_LISTEN_FDS_START, + i.e. file descriptor 3.</para> + </refsect1> + + <refsect1> + <title>Notes</title> + + <para>This function is provided by the reference + implementation of APIs for new-style daemons and + distributed with the systemd package. The algorithm it + implements is simple, and can easily be reimplemented + in daemons if it is important to support this + interface without using the reference + implementation.</para> + + <para>Internally, this function checks whether the + <varname>$LISTEN_PID</varname> environment variable + equals the daemon PID. If not, it returns + immediately. Otherwise it parses the number passed in + the <varname>$LISTEN_FDS</varname> environment + variable, then sets the FD_CLOEXEC flag for the parsed + number of file descriptors starting from + SD_LISTEN_FDS_START. Finally it returns the parsed + number.</para> + + <para>For details about the algorithm check the + liberally licensed reference implementation sources: + <ulink url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c"/> + resp. <ulink + url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.h"/></para> + + <para><function>sd_listen_fds()</function> is + implemented in the reference implementation's drop-in + <filename>sd-daemon.c</filename> and + <filename>sd-daemon.h</filename> files. It is + recommended that applications consuming these APIs + copy the implementation into their source tree. For + more details about the reference implementation see + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry></para> + + <para>If -DDISABLE_SYSTEMD is set during compilation + this function will always return 0 and otherwise + become a NOP.</para> + </refsect1> + + <refsect1> + <title>See Also</title> + + <para> + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_socket</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_socket_inet</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>sd_is_socket_unix</refentrytitle><manvolnum>3</manvolnum></citerefentry>, + <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/man/sd_notify.xml b/man/sd_notify.xml new file mode 100644 index 0000000000..140e795979 --- /dev/null +++ b/man/sd_notify.xml @@ -0,0 +1,277 @@ +<?xml version='1.0'?> <!--*-nxml-*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> + +<!-- + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> + +<refentry id="sd_notify"> + + <refentryinfo> + <title>sd_notify</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Lennart</firstname> + <surname>Poettering</surname> + <email>lennart@poettering.net</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>sd_notify</refentrytitle> + <manvolnum>3</manvolnum> + </refmeta> + + <refnamediv> + <refname>sd_notify</refname> + <refname>sd_notifyf</refname> + <refpurpose>Notify init system about start-up completion and other daemon status changes</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <funcsynopsis> + <funcsynopsisinfo>#include "sd-daemon.h"</funcsynopsisinfo> + + <funcprototype> + <funcdef>int <function>sd_notify</function></funcdef> + <paramdef>int <parameter>unset_environment</parameter></paramdef> + <paramdef>const char *<parameter>state</parameter></paramdef> + </funcprototype> + + <funcprototype> + <funcdef>int <function>sd_notifyf</function></funcdef> + <paramdef>int <parameter>unset_environment</parameter></paramdef> + <paramdef>const char *<parameter>format</parameter></paramdef> + <paramdef>...</paramdef> + </funcprototype> + </funcsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + <para><function>sd_notify()</function> shall be called + by a daemon to notify the init system about status + changes. It can be used to send arbitrary information, + encoded in an environment-block-like string. Most + importantly it can be used for start-up completion + notification.</para> + + <para>If the <parameter>unset_environment</parameter> + parameter is non-zero <function>sd_notify()</function> + will unset the <varname>$NOTIFY_SOCKET</varname> + environment variable before returning (regardless + whether the function call itself succeeded or + not). Further calls to + <function>sd_notify()</function> will then fail, but + the variable is no longer inherited by child + processes.</para> + + <para>The <parameter>state</parameter> parameter + should contain an newline-seperated list of variable + assignments, similar in style to an environment + block. A trailing newline is implied if none is + specified. The string may contain any kind of variable + assignments, but the following shall be considered + well-known:</para> + + <variablelist> + <varlistentry> + <term>READY=1</term> + + <listitem><para>Tells the init system + that daemon startup is finished. This + is only used by systemd if the service + definition file has Type=notify + set. The passed argument is a boolean + "1" or "0". Since there is little + value in signalling non-readiness the + only value daemons should send is + "READY=1".</para></listitem> + </varlistentry> + + <varlistentry> + <term>STATUS=...</term> + + <listitem><para>Passes a single-line + status string back to the init system + that describes the daemon state. This + is free-from and can be used for + various purposes: general state + feedback, fsck-like programs could + pass completion percentages and + failing programs could pass a human + readable error message. Example: + "STATUS=Completed 66% of file system + check..."</para></listitem> + </varlistentry> + + <varlistentry> + <term>ERRNO=...</term> + + <listitem><para>If a daemon fails, the + errno-style error code, formatted as + string. Example: "ERRNO=2" for + ENOENT.</para></listitem> + </varlistentry> + + <varlistentry> + <term>BUSERROR=...</term> + + <listitem><para>If a daemon fails, the + D-Bus error-style error code. Example: + "BUSERROR=org.freedesktop.DBus.Error.TimedOut"</para></listitem> + </varlistentry> + + <varlistentry> + <term>MAINPID=...</term> + + <listitem><para>The main pid of the + daemon, in case the init system did + not fork off the process + itself. Example: + "MAINPID=4711"</para></listitem> + </varlistentry> + </variablelist> + + <para>It is recommened to prefix variable names that + are not shown in the list above with + <varname>X_</varname> to avoid namespace + clashes.</para> + + <para>Note that systemd will accept status data sent + from a daemon only if the + <varname>NotifyAccess=</varname> option is correctly + set in the service definition file. See + <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> + for details.</para> + + <para><function>sd_notifyf()</function> is similar to + <function>sd_notifyf()</function> but takes a + <function>printf()</function>-like format string plus + arguments.</para> + </refsect1> + + <refsect1> + <title>Return Value</title> + + <para>On failure, these calls return a negative + errno-style error code. If + <varname>$NOTIFY_SOCKET</varname> was not set and + hence no status data could be sent 0 is returned. If + the status was sent these functions return with a + positive return value. In order to support both init + systems that implement this scheme and those which + don't it is generally recommended to ignore the return + value of this call.</para> + </refsect1> + + <refsect1> + <title>Notes</title> + + <para>These functions are provided by the reference + implementation of APIs for new-style daemons and + distributed with the systemd package. The algorithms + they implement are simple, and can easily be + reimplemented in daemons if it is important to support + this interface without using the reference + implementation.</para> + + <para>Internally, these functions send a single + datagram with the state string as payload to the + AF_UNIX socket referenced in the + <varname>$NOTIFY_SOCKET</varname> environment + variable. If the first character of + <varname>$NOTIFY_SOCKET</varname> is @ the string is + understood as Linux abstract namespace socket. The + datagram is accompanied by the process credentials of + the sending daemon, using SCM_CREDENTIALS.</para> + + <para>For details about the algorithm check the + liberally licensed reference implementation sources: + <ulink url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c"/> + resp. <ulink + url="http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.h"/></para> + + <para><function>sd_notify()</function> and + <function>sd_notifyf()</function> are implemented in + the reference implementation's drop-in + <filename>sd-daemon.c</filename> and + <filename>sd-daemon.h</filename> files. It is + recommended that applications consuming these APIs + copy the implementation into their source tree. For + more details about the reference implementation see + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry></para> + + <para>If -DDISABLE_SYSTEMD is set during compilation + this function will always return 0 and otherwise + become a NOP.</para> + </refsect1> + + <refsect1> + <title>Examples</title> + + <example> + <title>Start-up Notification</title> + + <para>When a daemon finished starting up, it + might issue the following call call to notify + the init system:</para> + + <programlisting>sd_notify(0, "READY=1");</programlisting> + </example> + + <example> + <title>Extended Start-up Notification</title> + + <para>A daemon could send the following after + completing initialization:</para> + + <programlisting>sd_notifyf(0, "READY=1\n" + "STATUS=Processing requests...\n" + "MAINPID=%lu", + (unsigned long) getpid());</programlisting> + </example> + + <example> + <title>Error Cause Notification</title> + + <para>A daemon could send the following shortly before exiting, on failure</para> + + <programlisting>sd_notifyf(0, "STATUS=Failed to start up: %s\n" + "ERRNO=%i", + strerror(errno), + errno);</programlisting> + </example> + </refsect1> + + <refsect1> + <title>See Also</title> + <para> + <citerefentry><refentrytitle>sd_daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/src/sd-daemon.h b/src/sd-daemon.h index dc18f42eaa..56fec98aa7 100644 --- a/src/sd-daemon.h +++ b/src/sd-daemon.h @@ -76,7 +76,7 @@ extern "C" { /* Log levels for usage on stderr: - fprintf(stderr, SD_NOTICE "Hello World!"); + fprintf(stderr, SD_NOTICE "Hello World!\n"); This is similar to printk() usage in the kernel. */ @@ -158,9 +158,9 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) _sd_hidden_; /* - Informs systemd about changed daemon state. This takes a numeber of + Informs systemd about changed daemon state. This takes a number of newline seperated environment-style variable assignments in a - string. The following strings are known: + string. The following variables are known: READY=1 Tells systemd that daemon startup is finished (only relevant for services of Type=notify). The passed @@ -185,7 +185,8 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t MAINPID=... The main pid of a daemon, in case systemd did not fork off the process itself. Example: "MAINPID=4711" - Daemons can choose to send additional variables. + Daemons can choose to send additional variables. However, it is + recommened to prefix variable names not listed above with X_. Returns a negative errno-style error code on failure. Returns > 0 if systemd could be notified, 0 if it couldn't possibly because |