diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rwxr-xr-x | fifo-cronolog-setup | 17 | ||||
-rw-r--r-- | fifo-cronolog.c | 27 | ||||
-rw-r--r-- | openrc/fifo-cronolog.confd (renamed from fifo-cronolog.confd) | 0 | ||||
-rw-r--r-- | openrc/fifo-cronolog.initd (renamed from fifo-cronolog.initd) | 0 | ||||
-rw-r--r-- | systemd/README.md | 4 | ||||
-rw-r--r-- | systemd/fifo-cronolog@.service | 10 | ||||
-rw-r--r-- | systemd/fifo-cronolog@example.service.env | 4 |
8 files changed, 41 insertions, 24 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29b8ac9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +*.o +fifo-cronolog diff --git a/fifo-cronolog-setup b/fifo-cronolog-setup new file mode 100755 index 0000000..55f46f0 --- /dev/null +++ b/fifo-cronolog-setup @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2024-2024, Gentoo Foundation +# SPDX-License-Identifier: BSD-2-Clause +FIFO=$1 +FIFO_OWNER=$2 +FIFO_PERMS=$3 +if [ ! -e "${FIFO}" ]; then + mkfifo "$FIFO" || exit 1 +fi +if [ -p "${FIFO}" ]; then + chown "$FIFO_OWNER" "$FIFO" || exit 1 + chmod "$FIFO_PERMS" "$FIFO" || exit 1 +else + echo "${FIFO} is not a valid FIFO!" 1>&2 + exit 1 +fi +exit 0 diff --git a/fifo-cronolog.c b/fifo-cronolog.c index de87827..f7ff19f 100644 --- a/fifo-cronolog.c +++ b/fifo-cronolog.c @@ -1,27 +1,6 @@ /* -Copyright (c) 2007-2010, Gentoo Foundation -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. +Copyright 2010-2024, Gentoo Foundation +SPDX-License-Identifier: BSD-2-Clause */ #include <stdlib.h> @@ -35,7 +14,7 @@ POSSIBILITY OF SUCH DAMAGE. #include <errno.h> #include <string.h> -#define VERSION "1.1.1" +#define VERSION "1.2.0" char *pidfile; diff --git a/fifo-cronolog.confd b/openrc/fifo-cronolog.confd index a73e291..a73e291 100644 --- a/fifo-cronolog.confd +++ b/openrc/fifo-cronolog.confd diff --git a/fifo-cronolog.initd b/openrc/fifo-cronolog.initd index 30812e6..30812e6 100644 --- a/fifo-cronolog.initd +++ b/openrc/fifo-cronolog.initd diff --git a/systemd/README.md b/systemd/README.md new file mode 100644 index 0000000..1d88021 --- /dev/null +++ b/systemd/README.md @@ -0,0 +1,4 @@ +1. Put env into `/etc/systemd-env/`, using the entire name of the unit, with instance suffix, and an extra `.env`, + e.g. `/etc/systemd-env/fifo-cronolog@example.service.env` +2. `systemctl enable fifo-cronolog@example` +3. Use systemd overrides if you need to add dependencies. diff --git a/systemd/fifo-cronolog@.service b/systemd/fifo-cronolog@.service new file mode 100644 index 0000000..0ab0962 --- /dev/null +++ b/systemd/fifo-cronolog@.service @@ -0,0 +1,10 @@ +[Unit] +Description=fifo-cronolog.%i +[Service] +Type=forking +EnvironmentFile=/etc/systemd-env/%n.env +PIDFile=/run/%N.pid +ExecStartPre=/usr/sbin/fifo-cronolog-setup $FIFO $FIFO_OWNER $FIFO_PERMS +ExecStart=/usr/sbin/fifo-cronolog /run/%N.pid $FIFO $LOGS +[Install] +WantedBy=multi-user.target diff --git a/systemd/fifo-cronolog@example.service.env b/systemd/fifo-cronolog@example.service.env new file mode 100644 index 0000000..370d157 --- /dev/null +++ b/systemd/fifo-cronolog@example.service.env @@ -0,0 +1,4 @@ +FIFO="/tmp/example.fifo" +FIFO_OWNER="somebody:somegroup" +FIFO_PERMS="0600" +LOGS="/var/log/example/%Y%m%d.log" |