<?xml version='1.0'?> <!--*-nxml-*-->
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-
-<!--
- SPDX-License-Identifier: LGPL-2.1+
--->
+<!-- SPDX-License-Identifier: LGPL-2.1+ -->
<refentry id="daemon">
<function>setsid()</function> to detach from any terminal and
create an independent session.</para></listitem>
- <listitem><para>In the child, call <function>fork()</function>
- again, to ensure that the daemon can never re-acquire a
- terminal again.</para></listitem>
+ <listitem><para>In the child, call <function>fork()</function> again, to ensure that the daemon can
+ never re-acquire a terminal again. (This relevant if the program — and all its dependencies — does
+ not carefully specify `O_NOCTTY` on each and every single `open()` call that might potentially open a
+ TTY device node.)</para></listitem>
<listitem><para>Call <function>exit()</function> in the first
child, so that only the second child (the actual daemon
<listitem><para>In the daemon process, write the daemon PID
(as returned by <function>getpid()</function>) to a PID file,
- for example <filename>/run/foobar.pid</filename> (for a
+ for example <filename index='false'>/run/foobar.pid</filename> (for a
hypothetical daemon "foobar") to ensure that the daemon cannot
be started more than once. This must be implemented in
race-free fashion so that the PID file is only updated when it
and
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para></listitem>
+ <listitem><para>As new-style daemons are invoked without a controlling TTY (but as their own session
+ leaders) care should be taken to always specify `O_NOCTTY` on `open()` calls that possibly reference
+ a TTY device node, so that no controlling TTY is accidentally acquired.</para></listitem>
+
</orderedlist>
<para>These recommendations are similar but not identical to the
special target unit <filename>sockets.target</filename>. It is
recommended to place a
<varname>WantedBy=sockets.target</varname> directive in the
- <literal>[Install]</literal> section to automatically add such a
+ [Install] section to automatically add such a
dependency on installation of a socket unit. Unless
<varname>DefaultDependencies=no</varname> is set, the necessary
ordering dependencies are implicitly created for all socket
operating system-independent.</para></listitem>
<listitem><para>Make sure to include an
- <literal>[Install]</literal> section including installation
+ [Install] section including installation
information for the unit file. See
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. To activate your service on boot, make sure to