From patchwork Sun Oct 7 11:46:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 980127 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=datacom.com.br Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42ShXm0159zB2xn for ; Sun, 7 Oct 2018 22:46:31 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id B56AE8685D; Sun, 7 Oct 2018 11:46:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UgxqmeX+zGgU; Sun, 7 Oct 2018 11:46:26 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 6D2FC868DC; Sun, 7 Oct 2018 11:46:26 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 888851BF429 for ; Sun, 7 Oct 2018 11:46:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 85BB721561 for ; Sun, 7 Oct 2018 11:46:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1iTUg6-YrGut for ; Sun, 7 Oct 2018 11:46:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.datacom.com.br (mx.datacom.ind.br [177.66.5.10]) by silver.osuosl.org (Postfix) with ESMTPS id 6E9E921578 for ; Sun, 7 Oct 2018 11:46:18 +0000 (UTC) Received: from mail.datacom.com.br (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTPS id 4A0891BA0F26; Sun, 7 Oct 2018 08:46:25 -0300 (-03) Received: from localhost (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTP id 2AECC1BA0F05; Sun, 7 Oct 2018 08:46:25 -0300 (-03) Received: from mail.datacom.com.br ([127.0.0.1]) by localhost (mail.datacom.com.br [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id IWUEBXfpGpiX; Sun, 7 Oct 2018 08:46:25 -0300 (-03) Received: from p7-1130br.casantos.org (unknown [191.32.32.249]) by mail.datacom.com.br (Postfix) with ESMTPSA id 9D0881BA0F31; Sun, 7 Oct 2018 08:46:24 -0300 (-03) From: Carlos Santos To: buildroot@buildroot.org Date: Sun, 7 Oct 2018 08:46:02 -0300 Message-Id: <20181007114605.18153-6-casantos@datacom.com.br> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181007114605.18153-1-casantos@datacom.com.br> References: <20181007114605.18153-1-casantos@datacom.com.br> Subject: [Buildroot] [PATCH v3 5/8] sysklogd: update S01logging X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Adam Duskett MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Reformat and fix syslogd/klogd startup script for better quality and code style: - Implement start, stop, restart and reload as functions, like in other S01logging scripts, using start-stop-daemon. - Indent with tabs, not spaces. - Detect and report start/stop errors (previous version ignored them and always reported OK). - Support a configuration file at /etc/default (an example file will be added in forthcomming patch). - Support a configuration variable that completely disables the service and issues a warning message on any invocation. - Do not kill syslogd in "reload". Send a SIGHUP signal, instructing it to perform a re-initialization. Also do not kill klogd. Send a signal (default 0, which does nothing). Users can configure this signal in /etc/default/logging to either SIGUSR1 or SIGUSR2. Signed-off-by: Carlos Santos --- Changes v1->v2 - Implement suggestions made by Arnout Vandecappelle Changes v2->v3 - Include /etc/default/logging, not /etc/default/$DAEMON. --- package/sysklogd/S01logging | 90 ++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 20 deletions(-) diff --git a/package/sysklogd/S01logging b/package/sysklogd/S01logging index 1cbfe869fa..9b6e879d8a 100644 --- a/package/sysklogd/S01logging +++ b/package/sysklogd/S01logging @@ -1,25 +1,75 @@ #!/bin/sh -case "$1" in - start) - printf "Starting logging: " - /sbin/syslogd -m 0 - /sbin/klogd +DAEMON="sysklogd" +SPIDFILE="/var/run/syslogd.pid" +KPIDFILE="/var/run/klogd.pid" + +SYSLOGD_ARGS="-m 0" +KLOGD_ARGS="" +KLOGD_RELOAD="0" +ENABLED="yes" + +# shellcheck source=/dev/null +[ -r "/etc/default/logging" ] && . "/etc/default/logging" + +if [ "$ENABLED" != "yes" ]; then + printf '%s is disabled\n' "$DAEMON" + exit 0 +fi + +start() { + printf 'Starting %s: ' "$DAEMON" + status=0 + # shellcheck disable=SC2086 # we need the word splitting + start-stop-daemon -S -q -p "$SPIDFILE" -x /sbin/syslogd -- $SYSLOGD_ARGS || status=$? + start-stop-daemon -S -q -p "$KPIDFILE" -x /sbin/klogd -- $KLOGD_ARGS || status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +stop() { + printf 'Stopping %s: ' "$DAEMON" + status=0 + start-stop-daemon -K -q -p "$SPIDFILE" || status=$? + start-stop-daemon -K -q -p "$KPIDFILE" || status=$? + if [ "$status" -eq 0 ]; then echo "OK" - ;; - stop) - printf "Stopping logging: " - [ -f /var/run/klogd.pid ] && kill `cat /var/run/klogd.pid` - [ -f /var/run/syslogd.pid ] && kill `cat /var/run/syslogd.pid` + else + echo "FAIL" + fi + return "$status" +} + +restart() { + stop + sleep 1 + start +} + +# SIGHUP makes syslogd reload its configuration +# SIGUSR1 makes klogd reload kernel module symbols +# SIGUSR2 makes klogd reload static kernel symbols and kernel module symbols +reload() { + printf 'Reloading %s: ' "$DAEMON" + status=0 + start-stop-daemon -K -s HUP -q -p "$SPIDFILE" || status=$? + start-stop-daemon -K -s "$KLOGD_RELOAD" -q -p "$KPIDFILE" || status=$? + if [ "$status" -eq 0 ]; then echo "OK" - ;; - restart|reload) - $0 stop - $0 start - ;; - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac + else + echo "FAIL" + fi + return "$status" +} -exit $? +case "$1" in + start|stop|restart|reload) + "$1";; + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 +esac