From patchwork Thu Dec 20 02:31:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1016463 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.137; helo=fraxinus.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 fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43KwlF0hl6z9s3q for ; Thu, 20 Dec 2018 13:32:23 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0A0C085704; Thu, 20 Dec 2018 02:32:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y0XrWF6PjYB6; Thu, 20 Dec 2018 02:32:19 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 24E5585E6E; Thu, 20 Dec 2018 02:32:19 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id A15A21C31D6 for ; Thu, 20 Dec 2018 02:32:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 9F24785F30 for ; Thu, 20 Dec 2018 02:32:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TbH58toN_dIC for ; Thu, 20 Dec 2018 02:32:15 +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 fraxinus.osuosl.org (Postfix) with ESMTPS id 1CE0085E6E for ; Thu, 20 Dec 2018 02:32:14 +0000 (UTC) Received: from mail.datacom.com.br (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTPS id A93FD1BA55DC; Thu, 20 Dec 2018 00:32:25 -0200 (-02) Received: from localhost (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTP id 708C31BA54D2; Thu, 20 Dec 2018 00:32:25 -0200 (-02) 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 ZRbV3oW_QItB; Thu, 20 Dec 2018 00:32:25 -0200 (-02) Received: from p7-1130br.casantos.org (unknown [177.18.41.165]) by mail.datacom.com.br (Postfix) with ESMTPSA id C8B591BA55E8; Thu, 20 Dec 2018 00:32:24 -0200 (-02) From: Carlos Santos To: buildroot@buildroot.org Date: Thu, 20 Dec 2018 00:31:59 -0200 Message-Id: <20181220023200.17119-2-casantos@datacom.com.br> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181220023200.17119-1-casantos@datacom.com.br> References: <20181220023200.17119-1-casantos@datacom.com.br> MIME-Version: 1.0 Subject: [Buildroot] [PATCH v2 1/2] package/procps-ng: add init script for sysctl 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 , Matthew Weber Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Add a simple init script that invokes sysctl early in the initialization process to configure kernel parameters. This is already performed by systemd (systemd-sysctl) but there is no sysvinit/busybox counterpart. Files are read from directories in the following list in the given order from top to bottom: /run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf Signed-off-by: Carlos Santos --- Changes v1->v2: - The "--system" option activates "--ignore", which is bad because invalid variable settings in the configuration files will not be reported on the system log. Use some scripting to mimic the --system behavior but still reporting errors. - Redirect sysctl's standard output to syslog with facility.level "kern.info" and standard error to syslog with facility.level "kern.err". - Do not pass "--quiet" to sysctl, since we wanto to see the results. - Use "Running" and "Rerunning" instead of "Starting", since we do not really start anything, just run a program. - Do nothing on "stop", since ther is no running daemon to stop. --- package/procps-ng/S02sysctl | 64 ++++++++++++++++++++++++++++++++++ package/procps-ng/procps-ng.mk | 5 +++ 2 files changed, 69 insertions(+) create mode 100644 package/procps-ng/S02sysctl diff --git a/package/procps-ng/S02sysctl b/package/procps-ng/S02sysctl new file mode 100644 index 0000000000..3a58578de4 --- /dev/null +++ b/package/procps-ng/S02sysctl @@ -0,0 +1,64 @@ +#!/bin/sh + +PROGRAM="sysctl" + +SYSCTL_ARGS="" + +# shellcheck source=/dev/null +[ -r "/etc/default/$PROGRAM" ] && . "/etc/default/$PROGRAM" + +# Files are read from directories in the SYSCTL_SOURCES list, in the given +# order. A file may be used more than once, since there can be multiple +# symlinks to it. No attempt is made to prevent this. +SYSCTL_SOURCES="/etc/sysctl.d/ /usr/local/lib/sysctl.d/ /usr/lib/sysctl.d/ /lib/sysctl.d/ /etc/sysctl.conf" + +# The "--system" option activates "--ignore", which is bad because invalid +# variable settings in the configuration files will not be reported on the +# system log. Use some scripting to mimic the --system behavior but still +# reporting errors. Users not interested on error report can put "-e" in +# SYSCTL_ARGS. +# +# The file redirections do the following: +# +# - stdout is redirected to syslog with facility.level "kern.info" +# - stderr is redirected to syslog with facility.level "kern.err" +# - file dscriptor 4 is used to pass the result to the "start" function. +# +run_program() { + # shellcheck disable=SC2086 # we need the word splitting + find $SYSCTL_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \ + xargs -0 -r -n 1 readlink -f | { + prog_status="OK" + while :; do + read -r file + if [ -z "$file" ]; then + echo "$prog_status" >&4 + break + fi + echo "* Applying $file ..." + /sbin/sysctl -p "$file" $SYSCTL_ARGS || prog_status="FAIL" + done 2>&1 >&3 | /usr/bin/logger -t sysctl -p kern.err + } 3>&1 | /usr/bin/logger -t sysctl -p kern.info +} + +start() { + printf '%s %s: ' "$1" "$PROGRAM" + status=$(run_program 4>&1) + echo "$status" + if [ "$status" = "OK" ]; then + return 0 + fi + return 1 +} + +case "$1" in + start) + start "Running";; + restart|reload) + start "Rerunning";; + stop) + :;; + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 +esac diff --git a/package/procps-ng/procps-ng.mk b/package/procps-ng/procps-ng.mk index 03b74784d2..6a41e9b322 100644 --- a/package/procps-ng/procps-ng.mk +++ b/package/procps-ng/procps-ng.mk @@ -44,4 +44,9 @@ ifeq ($(BR2_STATIC_LIBS),y) PROCPS_NG_CONF_OPTS += --disable-numa endif +define PROCPS_NG_INSTALL_INIT_SYSV + $(INSTALL) -D -m 755 package/procps-ng/S02sysctl \ + $(TARGET_DIR)/etc/init.d/S02sysctl +endef + $(eval $(autotools-package))