- descriptors except STDIN, STDOUT,
- STDERR (i.e. the first three file
+ descriptors except standard input, output,
+ and error (i.e. the first three file
descriptors 0, 1, 2). This ensures
that no accidentally passed file
descriptor stays around in the daemon
descriptors 0, 1, 2). This ensures
that no accidentally passed file
descriptor stays around in the daemon
<listitem><para>In the daemon process,
connect <filename>/dev/null</filename>
<listitem><para>In the daemon process,
connect <filename>/dev/null</filename>
<listitem><para>In the daemon process,
reset the umask to 0, so that the file
<listitem><para>In the daemon process,
reset the umask to 0, so that the file
(for a hypothetical daemon "foobar")
to ensure that the daemon cannot be
started more than once. This must be
(for a hypothetical daemon "foobar")
to ensure that the daemon cannot be
started more than once. This must be
it is verified at the same time that
the PID previously stored in the PID
file no longer exists or belongs to a
it is verified at the same time that
the PID previously stored in the PID
file no longer exists or belongs to a
- foreign process. Commonly, some kind of
- file locking is employed to implement
- this logic.</para></listitem>
+ foreign process.</para></listitem>
<listitem><para>In the daemon process,
drop privileges, if possible and
<listitem><para>In the daemon process,
drop privileges, if possible and
the environment block is sanitized, that the
signal handlers and mask is reset and that no
left-over file descriptors are passed. Daemons
the environment block is sanitized, that the
signal handlers and mask is reset and that no
left-over file descriptors are passed. Daemons
- will be executed in their own session, and
- STDIN/STDOUT/STDERR connected to
+ will be executed in their own session, with
+ standard input/output/error connected to
detect service errors and problems. It
is recommended to follow the exit code
scheme as defined in the <ulink
detect service errors and problems. It
is recommended to follow the exit code
scheme as defined in the <ulink
<listitem><para>Instead of using the
<function>syslog()</function> call to log directly to the
system syslog service, a new-style daemon may
<listitem><para>Instead of using the
<function>syslog()</function> call to log directly to the
system syslog service, a new-style daemon may
<function>fprintf()</function>, which is then forwarded to
syslog by the init system. If log
priorities are necessary, these can be
<function>fprintf()</function>, which is then forwarded to
syslog by the init system. If log
priorities are necessary, these can be
exclusively on boot (and manually by the
administrator) via SysV init scripts, as
detailed in the <ulink
exclusively on boot (and manually by the
administrator) via SysV init scripts, as
detailed in the <ulink
<programlisting>PKG_PROG_PKG_CONFIG
AC_ARG_WITH([systemdsystemunitdir],
<programlisting>PKG_PROG_PKG_CONFIG
AC_ARG_WITH([systemdsystemunitdir],
- AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),,
+ [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
[with_systemdsystemunitdir=auto])
AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
[with_systemdsystemunitdir=auto])
AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
[AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
[AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
with_systemdsystemunitdir=no],
[AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
[AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
with_systemdsystemunitdir=no],
AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
+ <refsect1>
+ <title>Placing Daemon Data</title>
+
+ <para>It is recommended to follow the genreal
+ guidelines for placing package files, as discussed in
+ <citerefentry><refentrytitle>file-hierarchy</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
+ </refsect1>
+
<citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
- <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>file-hierarchy</refentrytitle><manvolnum>7</manvolnum></citerefentry>