Skip to content

Commit

Permalink
0.7.1 (20210220)
Browse files Browse the repository at this point in the history
- Fixed make distclean/clobber on Debian (use debian-clobber instead of clobber) (spotted by Marc Haber)
- Fixed parallel make test (race condition creating test directory) (spotted by Marc Haber)
- Fixed manpage header and footer and various other minor fixes and improvements
- Minor improvements in a few module tests
- Added configure --prefix=/opt/local for macports (spotted by Kurt Hindenburg)
- Added mention of file locations on macOS/macports to the daemon(1) manpage
- Added checks for gcc -W options that fail on old macosx (e.g. 10.6.8) without macports
- Minor changes to usage error messages for consistency
- Improved config file parsing (skip spaces around commas and added more error messages)
- Added support for using $CC in configure (spotted by Ryan Schmidt)
- Fixed Makefile (wasn't inheriting CPPFLAGS, CFLAGS or LDFLAGS from caller) (spotted by Ryan Schmidt)
  • Loading branch information
raforg committed Feb 20, 2021
1 parent 837423f commit 6c7f5b1
Show file tree
Hide file tree
Showing 113 changed files with 3,146 additions and 2,230 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
CHANGELOG
=========

0.7.1 (20210220)

- Fixed make distclean/clobber on Debian (use debian-clobber instead of clobber) (spotted by Marc Haber)
- Fixed parallel make test (race condition creating test directory) (spotted by Marc Haber)
- Fixed manpage header and footer and various other minor fixes and improvements
- Minor improvements in a few module tests
- Added configure --prefix=/opt/local for macports (spotted by Kurt Hindenburg)
- Added mention of file locations on macOS/macports to the daemon(1) manpage
- Added checks for gcc -W options that fail on old macosx (e.g. 10.6.8) without macports
- Minor changes to usage error messages for consistency
- Improved config file parsing (skip spaces around commas and added more error messages)
- Added support for using $CC in configure (spotted by Ryan Schmidt)
- Fixed Makefile (wasn't inheriting CPPFLAGS, CFLAGS or LDFLAGS from caller) (spotted by Ryan Schmidt)

0.7 (20201111)

- Fixed bug: race condition causing failure with "exec daemon ..." (with Askar Safin safinaskar at mail.ru)
Expand Down Expand Up @@ -377,6 +391,6 @@ CHANGELOG
URL: http://libslack.org/daemon
URL: http://raf.org/daemon
GIT: https://github.com/raforg/daemon
Date: 20201111
Date: 20210220
Author: raf <raf@raf.org>

6 changes: 3 additions & 3 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ COPYING
=======
daemon - turns other processes into daemons

Copyright (C) 1999-2004, 2010, 2020 raf <raf@raf.org>
Copyright (C) 1999-2004, 2010, 2020-2021 raf <raf@raf.org>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -19,7 +19,7 @@ Copyright (C) 1999-2004, 2010, 2020 raf <raf@raf.org>

libslack - A UNIX/C library of general utilities for programmers with Slack

Copyright (C) 1999-2004, 2010, 2020 raf <raf@raf.org>
Copyright (C) 1999-2004, 2010, 2020-2021 raf <raf@raf.org>

This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -67,6 +67,6 @@ All rights reserved.
URL: http://libslack.org/daemon
URL: http://raf.org/daemon
GIT: https://github.com/raforg/daemon
Date: 20201111
Date: 20210220
Author: raf <raf@raf.org>

61 changes: 38 additions & 23 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This version is only known to work on the following systems:
OpenBSD 4.7 (i386, amd64), 6.6 (amd64)
FreeBSD 8.0 (i386, amd64), 12.1 (amd64)
NetBSD 5.0.2 (i386, amd64), 8.1 (amd64)
MacOSX 10.{4,5,6,11,14} (ppc, i386, x86_64)
MacOSX/macOS 10.{4,5,6,11,14,15}, 11 (ppc, i386, x86_64, arm64)
kFreeBSD 20090729 (i386)
GNU/Hurd (i386)

Expand Down Expand Up @@ -44,17 +44,32 @@ they have some very nasty bugs.

First, uninstall any previous version:

cd /usr/local/src/daemon-0.6.4
cd /usr/local/src/daemon-0.7
make uninstall

To build and test:

tar xzf daemon-0.7.tar.gz
cd daemon-0.7
tar xzf daemon-0.7.1.tar.gz
cd daemon-0.7.1
./configure # iff linux, openbsd, freebsd, netbsd, macosx, solaris, gnuhurd or kfreebsd
make # must be gnu make
make test # only tests libslack. to test daemon, see test/README

Note that the configure script is not a GNU autoconf script.
It just has hard-coded settings for certain platforms.
It does not accept all of the usual command line options.
However, it does accept certain options:

--prefix=/opt/local
Changes the installation prefix to a non-standard one (needed for macports).
This also changes the directory that the config file is installed in.
When --prefix=/usr or --prefix=default, the config file is installed in /etc.
Otherwise (e.g. --prefix=/usr/local or --prefix=/opt/local), the config
file is installed under the prefix.

--enable-test
Include backup implementations of several functions (unnecessary)

To install daemon and its manpage (in /usr/local by default):

make install
Expand Down Expand Up @@ -102,43 +117,43 @@ created.

To install from the Fedora RPM binary package (into /usr by default):

rpm -i daemon-0.7-1.x86_64.rpm # or
rpm -i daemon-0.7-1.i686.rpm
rpm -i daemon-0.7.1-1.x86_64.rpm # or
rpm -i daemon-0.7.1-1.i686.rpm

To install from the OpenBSD binary package (into /usr/local by default):

mv daemon-0.7-openbsd-amd64.tgz daemon-0.7.tgz # or
mv daemon-0.7-openbsd-i386.tgz daemon-0.7.tgz
mv daemon-0.7.1-openbsd-amd64.tgz daemon-0.7.1.tgz # or
mv daemon-0.7.1-openbsd-i386.tgz daemon-0.7.1.tgz
# then
pkg_add daemon-0.7.tar.gz
pkg_add daemon-0.7.1.tar.gz

To install from the FreeBSD binary package (into /usr/local by default):

pkg_add daemon-0.7-freebsd-amd64.tbz # or
pkg_add daemon-0.7-freebsd-i386.tbz
pkg_add daemon-0.7.1-freebsd-amd64.tbz # or
pkg_add daemon-0.7.1-freebsd-i386.tbz

To install from the NetBSD binary package (into /usr/local by default):

pkg_add daemon-0.7-netbsd-amd64.tgz # or
pkg_add daemon-0.7-netbsd-i386.tgz
pkg_add daemon-0.7.1-netbsd-amd64.tgz # or
pkg_add daemon-0.7.1-netbsd-i386.tgz

To install from the Mac OS X binary package (into /usr/local by default):

cd /usr/local
tar xzf /usr/local/src/daemon-0.7-macosx-universal.tar.gz # or
tar xzf /usr/local/src/daemon-0.7-macosx-x86_64.tar.gz # or
tar xzf /usr/local/src/daemon-0.7-macosx-i386.tar.gz # or
tar xzf /usr/local/src/daemon-0.7-macosx-powerpc.tar.gz
tar xzf /usr/local/src/daemon-0.7.1-macosx-universal.tar.gz # or
tar xzf /usr/local/src/daemon-0.7.1-macosx-x86_64.tar.gz # or
tar xzf /usr/local/src/daemon-0.7.1-macosx-i386.tar.gz # or
tar xzf /usr/local/src/daemon-0.7.1-macosx-powerpc.tar.gz

To install from the Solaris10 binary package (into /usr/local by default):

gunzip daemon-0.7-solaris-amd64.pkg.gz
pkgadd -d daemon-0.7-solaris-amd64.pkg
gunzip daemon-0.7.1-solaris-amd64.pkg.gz
pkgadd -d daemon-0.7.1-solaris-amd64.pkg

or

gunzip daemon-0.7-solaris-i386.pkg.gz
pkgadd -d daemon-0.7-solaris-i386.pkg
gunzip daemon-0.7.1-solaris-i386.pkg.gz
pkgadd -d daemon-0.7.1-solaris-i386.pkg

On debian/ubuntu systems you should be able to:

Expand Down Expand Up @@ -189,7 +204,7 @@ filesystem entry is needed for the client and it must be unlinked after use.
It's also possible for a malicious local user to deny a client access to the
server. The solution is to always use UNIX domain stream sockets.

Solaris has an inadequate snprintf() function so libslack provides it's own
Solaris has an inadequate snprintf() function so libslack provides its own
implementation. When configured for Solaris, this snprintf() function will
format exactly like the system's sprintf() function, even though it has
incorrect behaviour with respect to the ISO C standard. I thought this was
Expand All @@ -213,6 +228,6 @@ Probably has the same UNIX domain datagram problem as Solaris.
URL: http://libslack.org/daemon
URL: http://raf.org/daemon
GIT: https://github.com/raforg/daemon
Date: 20201111
Date: 20210220
Author: raf <raf@raf.org>

9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# daemon - http://libslack.org/daemon/
#
# Copyright (C) 1999-2004, 2010, 2020 raf <raf@raf.org>
# Copyright (C) 1999-2004, 2010, 2020-2021 raf <raf@raf.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -17,10 +17,11 @@
# along with this program; if not, see <https://www.gnu.org/licenses/>.
#

# 20201111 raf <raf@raf.org>
# 20210220 raf <raf@raf.org>

CC := gcc
# CC := cc
# CC := other
AR := ar
RANLIB := ranlib
POD2MAN := pod2man
Expand Down Expand Up @@ -161,8 +162,12 @@ depend: ready $(DEPEND_CFILES) $(DEPEND_HFILES)
clean::
@rm -rf $(CLEAN_FILES)

ifeq ($(shell uname -a 2>/dev/null | grep -i Debian),)
clobber::
@rm -rf $(CLEAN_FILES) $(CLOBBER_FILES)
else
clobber:: debian-clobber
endif

distclean:: clobber
@perl -pi -e 'last if /[D]O NOT DELETE/;' $(patsubst %, %/Makefile, $(DAEMON_SRCDIR) $(DAEMON_SUBDIRS))
Expand Down
130 changes: 72 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,111 +31,125 @@ Change the process `uid` and `gid` if the `--user` option was supplied. Only
*root* can use this option. Note that the `uid` of *daemon* itself is changed,
rather than just changing the `uid` of the client process.

Read the configuration file (`/etc/daemon.conf` by default, or specified
by the `--config` option). Note: The root directory and the user must be
set before access to the configuration file can be attempted so neither
`--chroot` nor `--user` options may appear in the configuration file.
Read the system configuration file(s) (`/etc/daemon.conf` and
`/etc/daemon.conf.d/*` by default, or specified by the `--config` option)
unless the C<--noconfig> option was supplied. Then read the user's personal
configuration file(s) (`~/.daemonrc` and `~/.daemonrc.d/*`), if any. Note:
The root directory and the user must be set before access to the
configuration file(s) can be attempted so neither `--chroot` nor `--user`
options may appear in the configuration file.

Disable core file generation to prevent leaking information in daemons run
by *root* (unless the `--core` option is supplied).
On *BSD* systems (except *macOS*), the system configuration file(s) are
`/usr/local/etc/daemon.conf` and `/usr/local/etc/daemon.conf.d/*` by
default.

On *macOS*, when installed via *macports*, the system configuration file(s)
are `/opt/local/etc/daemon.conf` and `/opt/local/etc/daemon.conf.d/*`.

Disable core file generation to prevent leaking potentially sensitive
information in daemons that are run by *root* (unless the `--core` option
was supplied).

Become a daemon process:

* If *daemon* was not invoked by *init(8)* (i.e. pid 1) or *inetd(8)*:

* Ignore `SIGHUP` signals in case the current process session leader
terminates while attached to a controlling terminal causing us to
terminates while attached to a controlling terminal, causing us to
receive a `SIGHUP` signal before we start our own process session below.
This can happen when *daemon* was invoked interactively via the shell
builtin `exec`. When this initial process terminates below, the terminal
emulator that invoked the shell also terminates.
emulator that invoked the shell also terminates, do *daemon* needs to
protect itself from that.

* Background the process to lose process group leadership.

* Start a new process session.

* Background the process again to lose process session leadership. Under
SVR4 this prevents the process from ever gaining a controlling terminal.
This is only necessary under SVR4 but is always done for simplicity. Note
that ignoring `SIGHUP` signals earlier means that when the newly created
process session leader terminates, then even if it has a controlling
terminal open, the newly backgrounded process won't receive the
corresponding `SIGHUP` signal that is sent to all processes in the process
session's foreground process group because it inherited signal dispositions
from the initial process.
* Background the process again to lose process session leadership. Under
*SVR4* this prevents the process from ever gaining a controlling
terminal. This is only necessary under *SVR4*, but is always done for
simplicity. Note that ignoring `SIGHUP` signals earlier means that
when the newly created process session leader terminates, then even if
it has a controlling terminal open, the newly backgrounded process
won't receive the corresponding `SIGHUP` signal that is sent to all
processes in the process session's foreground process group, because
it inherited signal dispositions from the initial process.

* Change directory to the root directory so as not to hamper umounts.
* Change the current directory to the root directory so as not to hamper
umounts.

* Clear the umask to enable explicit file creation modes.
* Clear the *umask* to enable explicit file creation modes.

* Close all open file descriptors. If *daemon* was invoked by *inetd(8)*,
`stdin`, `stdout` and `stderr` are left open since they are open to a
socket.
`stdin`, `stdout` and `stderr` are left open, because they are open to a
socket.

* Open `stdin`, `stdout` and `stderr` to `/dev/null` in case something
* Open `stdin`, `stdout` and `stderr` to `/dev/null`, in case something
requires them to be open. Of course, this is not done if *daemon* was
invoked by *inetd(8)*.

* If the `--name` option was supplied, create and lock a file containing the
process id of the *daemon* process. The presence of this locked file
prevents two instances of a daemon with the same name from running at the
same time. The standard location of the pidfile is `/var/run` for *root*
(`/etc` on *Solaris*) and `/tmp` for normal users. If the `--pidfiles`
option was supplied, its argument specifies the directory in which the
pidfile will be placed. If the `--pidfile` option was supplied, its
argument specifies the name of the pidfile and the directory in which it
will be placed.

If the `--umask` option was supplied, set the umask to its argument.
Otherwise, set the umask to `022` to prevent accidentally creating group or
world writable files.
process id of the *daemon* process. The presence of this locked file
prevents two instances of a daemon with the same name from running at
the same time. The default location of the pidfile is `/var/run` for
*root* (`/etc` on *Solaris*, `/opt/local/var/run` on *macOS* when
installed via *macports*), and `/tmp` for normal users. If the
`--pidfiles` option was supplied, its argument specifies the directory
in which the pidfile will be placed. If the `--pidfile` option was
supplied, its argument specifies the name of the pidfile and the
directory in which it will be placed.

If the `--umask` option was supplied, set the *umask* to its argument, which
must be a valid three-digit octal mode. Otherwise, set the *umask* to `022`,
to prevent accidentally creating group- or world-writable files.

Set the current directory if the `--chdir` option was supplied.

Spawn the client command and wait for it to terminate. The client command
may be specified as command line arguments or as the argument of the
can be specified as command line arguments, or as the argument of the
`--command` option. If both the `--command` option and command line
arguments are present, the client command is the result of appending the
command line arguments to the argument of the `--command` option.

If the `--output`, `--stdout` and/or `--stderr` option were supplied, the client's
standard output and/or standard error are captured by *daemon* and sent to the
standard output and/or standard error are captured by *daemon*, and sent to the
respective *syslog* destinations.

When the client terminates, *daemon* respawns it if the `--respawn` option
was supplied. If the client ran for less than 300 seconds (or the value of
the `--acceptable` option), then *daemon* sees this as an error. It will
was supplied. If the client ran for less than `300` seconds (or the value of
the `--acceptable` option), then *daemon* sees this as a failure. It will
attempt to restart the client up to five times (or the value of the
`--attempts` option) before waiting for 300 seconds (or the value of the
`--delay` option). This gives the administrator the chance to correct
whatever is preventing the client from running without overloading system
resources. If the `--limit` option was supplied, *daemon* terminates after
the specified number of spawn attempt bursts. The default is zero which
means never give up, never surrender.
`--attempts` option), before waiting for `300` seconds (or the value of the
`--delay` option). This gives the system administrator the chance to correct
whatever is preventing the client from running successfully without
overloading system resources. If the `--limit` option was supplied, *daemon*
terminates after the specified number of respawn attempt bursts. The default
is zero, which means never give up, never surrender.

When the client terminates and the `--respawn` option wasn't supplied,
*daemon* terminates.
When the client terminates, and the `--respawn` option wasn't supplied,
*daemon* terminates as well.

If *daemon* receives a `SIGTERM` signal (e.g. from another invocation of
*daemon* supplied with the `--stop` option), it propagates the signal to the
client and then terminates.
If *daemon* receives a `SIGTERM` signal (e.g. from a separate invocation of
*daemon* with the `--stop` option), it propagates the signal to the client
and then terminates.

If *daemon* receives a `SIGUSR1` signal (from another invocation of
*daemon* supplied with the `--restart` option), it sends a `SIGTERM`
signal to the client. If started with the `--respawn` option, the client
process will be restarted after it is killed by the `SIGTERM` signal.
If *daemon* receives a `SIGUSR1` signal (from a separate invocation of
*daemon* with the `--restart` option), it sends a `SIGTERM` signal to the
client. If it was started with the `--respawn` option, the client process
will be restarted after it is terminated by the `SIGTERM` signal.

If the `--foreground` option was supplied, the client process is run as a
foreground process and is not turned into a daemon. If *daemon* is
connected to a terminal, so will the client process. If *daemon* is not
connected to a terminal but the client needs to be connected to a terminal,
use the `--pty` option.
foreground process, and is not turned into a daemon at all. If *daemon* is
connected to a terminal, then the client process will also be connected to
it. If *daemon* is not connected to a terminal, but the client needs to be
connected to a terminal, use the `--pty` option.

--------------------------------------------------------------------------------

URL: http://libslack.org/daemon
URL: http://raf.org/daemon
GIT: https://github.com/raforg/daemon
Date: 20201111
Date: 20210220
Author: raf <raf@raf.org>

Loading

0 comments on commit 6c7f5b1

Please sign in to comment.