sd_notify.xml revision 3122633a91375c8a8dc783b3b91482e60810181f
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<!--
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This file is part of systemd.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Copyright 2010 Lennart Poettering
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync systemd is free software; you can redistribute it and/or modify it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync under the terms of the GNU Lesser General Public License as published by
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync the Free Software Foundation; either version 2.1 of the License, or
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (at your option) any later version.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync systemd is distributed in the hope that it will be useful, but
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync WITHOUT ANY WARRANTY; without even the implied warranty of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Lesser General Public License for more details.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync You should have received a copy of the GNU Lesser General Public License
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync along with systemd; If not, see <http://www.gnu.org/licenses/>.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync-->
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync<refentry id="sd_notify"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync xmlns:xi="http://www.w3.org/2001/XInclude">
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refentryinfo>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>sd_notify</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <productname>systemd</productname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <authorgroup>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <author>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <contrib>Developer</contrib>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <firstname>Lennart</firstname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <surname>Poettering</surname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <email>lennart@poettering.net</email>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </author>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </authorgroup>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refentryinfo>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refmeta>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refentrytitle>sd_notify</refentrytitle>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <manvolnum>3</manvolnum>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refmeta>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refnamediv>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refname>sd_notify</refname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refname>sd_notifyf</refname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refname>sd_pid_notify</refname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refname>sd_pid_notifyf</refname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refname>sd_pid_notify_with_fds</refname>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refpurpose>Notify service manager about start-up completion and other service status changes</refpurpose>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refnamediv>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refsynopsisdiv>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcsynopsis>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcsynopsisinfo>#include &lt;systemd/sd-daemon.h&gt;</funcsynopsisinfo>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcdef>int <function>sd_notify</function></funcdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>int <parameter>unset_environment</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>const char *<parameter>state</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcdef>int <function>sd_notifyf</function></funcdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>int <parameter>unset_environment</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>const char *<parameter>format</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>...</paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcdef>int <function>sd_pid_notify</function></funcdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>pid_t <parameter>pid</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>int <parameter>unset_environment</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>const char *<parameter>state</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcdef>int <function>sd_pid_notifyf</function></funcdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>pid_t <parameter>pid</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>int <parameter>unset_environment</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>const char *<parameter>format</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>...</paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <funcdef>int <function>sd_pid_notify_with_fds</function></funcdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>pid_t <parameter>pid</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>int <parameter>unset_environment</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>const char *<parameter>state</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>const int *<parameter>fds</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <paramdef>unsigned <parameter>n_fds</parameter></paramdef>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </funcprototype>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </funcsynopsis>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refsynopsisdiv>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Description</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para><function>sd_notify()</function> may be called by a service
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to notify the service manager about state changes. It can be used
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to send arbitrary information, encoded in an
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync environment-block-like string. Most importantly it can be used for
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync start-up completion notification.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>If the <parameter>unset_environment</parameter> parameter is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync non-zero, <function>sd_notify()</function> will unset the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varname>$NOTIFY_SOCKET</varname> environment variable before
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync returning (regardless of whether the function call itself
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync succeeded or not). Further calls to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_notify()</function> will then fail, but the variable
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync is no longer inherited by child processes.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>The <parameter>state</parameter> parameter should contain a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync newline-separated list of variable assignments, similar in style
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to an environment block. A trailing newline is implied if none is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync specified. The string may contain any kind of variable
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync assignments, but the following shall be considered
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync well-known:</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <variablelist>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>READY=1</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>Tells the service manager that service startup
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync is finished. This is only used by systemd if the service
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync definition file has Type=notify set. Since there is little
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync value in signaling non-readiness, the only value services
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync should send is <literal>READY=1</literal> (i.e.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <literal>READY=0</literal> is not defined).</para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>RELOADING=1</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>Tells the service manager that the service is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync reloading its configuration. This is useful to allow the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync service manager to track the service's internal state, and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync present it to the user. Note that a service that sends this
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync notification must also send a <literal>READY=1</literal>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync notification when it completed reloading its
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync configuration.</para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>STOPPING=1</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>Tells the service manager that the service is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync beginning its shutdown. This is useful to allow the service
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync manager to track the service's internal state, and present it
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to the user.</para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>STATUS=...</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>Passes a single-line UTF-8 status string back
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to the service manager that describes the service state. This
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync is free-form and can be used for various purposes: general
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync state feedback, fsck-like programs could pass completion
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync percentages and failing programs could pass a human readable
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync error message. Example: <literal>STATUS=Completed 66% of file
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync system check...</literal></para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>ERRNO=...</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>If a service fails, the errno-style error
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync code, formatted as string. Example: <literal>ERRNO=2</literal>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync for ENOENT.</para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>BUSERROR=...</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>If a service fails, the D-Bus error-style
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync error code. Example:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <literal>BUSERROR=org.freedesktop.DBus.Error.TimedOut</literal></para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>MAINPID=...</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>The main process ID (PID) of the service, in
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync case the service manager did not fork off the process itself.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Example: <literal>MAINPID=4711</literal></para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>WATCHDOG=1</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>Tells the service manager to update the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync watchdog timestamp. This is the keep-alive ping that services
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync need to issue in regular intervals if
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varname>WatchdogSec=</varname> is enabled for it. See
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync for information how to enable this functionality and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync for the details of how the service can check whether the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync watchdog is enabled. </para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>FDSTORE=1</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>Stores additional file descriptors in the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync service manager. File descriptors sent this way will be
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync maintained per-service by the service manager and be passed
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync again using the usual file descriptor passing logic on the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync next invocation of the service (see
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>).
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This is useful for implementing service restart schemes where
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync services serialize their state to <filename>/run</filename>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync push their file descriptors to the system manager, and are
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync then restarted, retrieving their state again via socket
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync passing and <filename>/run</filename>. Note that the service
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync manager will accept messages for a service only if
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varname>FileDescriptorStoreMax=</varname> is set to non-zero
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync for it (defaults to zero). See
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync for details. Multiple arrays of file descriptors may be sent
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync in separate messages, in which case the arrays are combined.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync Note that the service manager removes duplicate file
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync descriptors before passing them to the service. Use
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_pid_notify_with_fds()</function> to send messages
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync with <literal>FDSTORE=1</literal>, see
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync below.</para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term>FDNAME=...</term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>When used in combination with
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varname>FDSTORE=1</varname> specifies a name for the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync submitted file descriptors. This name is passed to the service
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync during activation, and may be queried using
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>. File
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync descriptors submitted without this field set, will implicitly
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync get the name <literal>stored</literal> assigned. Note that if
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync multiple file descriptors are submitted at once the specified
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync name will be assigned to all of them. In order to assign
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync different names to submitted file descriptors, submit them in
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync seperate invocations of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_pid_notify_with_fds()</function>. The name may
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync consist of any ASCII characters, but must not contain control
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync characters or <literal>:</literal>. It may not be longer than
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync 255 characters. If a submitted name does not follow these
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync restrictions it is ignored.</para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </variablelist>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>It is recommended to prefix variable names that are not
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync listed above with <varname>X_</varname> to avoid namespace
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync clashes.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>Note that systemd will accept status data sent from a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync service only if the <varname>NotifyAccess=</varname> option is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync correctly set in the service definition file. See
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync for details.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para><function>sd_notifyf()</function> is similar to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_notify()</function> but takes a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>printf()</function>-like format string plus
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync arguments.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para><function>sd_pid_notify()</function> and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_pid_notifyf()</function> are similar to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_notify()</function> and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_notifyf()</function> but take a process ID (PID) to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync use as originating PID for the message as first argument. This is
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync useful to send notification messages on behalf of other processes,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync provided the appropriate privileges are available. If the PID
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync argument is specified as 0 the process ID of the calling process
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync is used, in which case the calls are fully equivalent to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_notify()</function> and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_notifyf()</function>.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para><function>sd_pid_notify_with_fds()</function> is similar to
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_pid_notify()</function> but takes an additional array
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync of file descriptors. These file descriptors are sent along the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync notification message to the service manager. This is particularly
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync useful for sending <literal>FDSTORE=1</literal> messages, as
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync described above. The additional arguments are a pointer to the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync file descriptor array plus the number of file descriptors in the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync array. If the number of file descriptors is passed as 0, the call
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync is fully equivalent to <function>sd_pid_notify()</function>, i.e.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync no file descriptors are passed. Note that sending file descriptors
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync to the service manager on messages that do not expect them (i.e.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync without <literal>FDSTORE=1</literal>) they are immediately closed
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync on reception.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Return Value</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>On failure, these calls return a negative errno-style error
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync code. If <varname>$NOTIFY_SOCKET</varname> was not set and hence
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync no status data could be sent, 0 is returned. If the status was
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync sent, these functions return with a positive return value. In
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync order to support both, init systems that implement this scheme and
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync those which do not, it is generally recommended to ignore the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync return value of this call.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Notes</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>These functions send a single datagram with the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync state string as payload to the <constant>AF_UNIX</constant> socket
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync referenced in the <varname>$NOTIFY_SOCKET</varname> environment
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync variable. If the first character of
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varname>$NOTIFY_SOCKET</varname> is <literal>@</literal>, the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync string is understood as Linux abstract namespace socket. The
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync datagram is accompanied by the process credentials of the sending
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync service, using SCM_CREDENTIALS.</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Environment</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <variablelist class='environment-variables'>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <term><varname>$NOTIFY_SOCKET</varname></term>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <listitem><para>Set by the service manager for supervised
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync processes for status and start-up completion notification.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync This environment variable specifies the socket
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <function>sd_notify()</function> talks to. See above for
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync details.</para></listitem>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </varlistentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </variablelist>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Examples</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Start-up Notification</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>When a service finished starting up, it might issue the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync following call to notify the service manager:</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <programlisting>sd_notify(0, "READY=1");</programlisting>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Extended Start-up Notification</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>A service could send the following after completing
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync initialization:</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <programlisting>sd_notifyf(0, "READY=1\n"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync "STATUS=Processing requests...\n"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync "MAINPID=%lu",
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (unsigned long) getpid());</programlisting>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Error Cause Notification</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>A service could send the following shortly before exiting, on failure:</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <programlisting>sd_notifyf(0, "STATUS=Failed to start up: %s\n"
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync "ERRNO=%i",
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync strerror(errno),
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync errno);</programlisting>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>Store a File Descriptor in the Service Manager</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>To store an open file descriptor in the service manager,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync in order to continue operation after a service restart without
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync losing state use <literal>FDSTORE=1</literal>:</para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <programlisting>sd_pid_notify_with_fds(0, 0, "FDSTORE=1\nFDNAME=foobar", &amp;fd, 1);</programlisting>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </example>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <title>See Also</title>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>sd_listen_fds_with_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </para>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync </refsect1>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync</refentry>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync