From patchwork Wed May 1 23:11:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1093933 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.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rqj8+LS4"; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44vZ0Z4Kzgz9s9N for ; Thu, 2 May 2019 09:11:58 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id E754787F0C; Wed, 1 May 2019 23:11:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OirM9z+ySxhX; Wed, 1 May 2019 23:11:52 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id C325787EE7; Wed, 1 May 2019 23:11:52 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id E3AC41BF2CE for ; Wed, 1 May 2019 23:11:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id E05C2871EB for ; Wed, 1 May 2019 23:11:50 +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 TK6geHKX1aUK for ; Wed, 1 May 2019 23:11:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by whitealder.osuosl.org (Postfix) with ESMTPS id 4826B86DF4 for ; Wed, 1 May 2019 23:11:49 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id b7so404572qkl.2 for ; Wed, 01 May 2019 16:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=12/3l2fxtLbQstekHTAvFTCLov0CiQoNFbLrWrKo/K8=; b=rqj8+LS4K5XNmqnI+gBaXES5ogGVd9DqoMcbG00o7iP3D5zmtNUp/IQ9R/gBn85InN 5/p/sFoRpmk/f1FwLPqA0q8DXOTe8hGWtRTYj3hD0KIvAGy0J+NX35l9ZgZRadryPWca v0TW7oPWrR70zOARCCgQJFKB64wAqg2Q7JU25Ee2PKPktZAyqjL75sqpaMAZLtfics3G NZZZM7htHyl9kjsUBL5vvcrb+Qs83O0Dqj2tClDfrBZJ1Z1brnUnjsTLLbSDJMpPAVwu vSDdkOFQ1ZI6uH2mi7QZydDykyK1uQJZ0TMexfSX04mIJ7DLmoNyDdTy9dmFYCMWaA+f QTXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=12/3l2fxtLbQstekHTAvFTCLov0CiQoNFbLrWrKo/K8=; b=fqT3IiewDhHZ5+ys4FNExIoLZrxbyrWQIJSjia1k/qlLNlkA1qVWmvU+ZHSu9hk5mS eyOKo7kQRp/mmFqXQemT/UyCBGwzs7ENCHsOSJ9LMrfflzKdbJ3DWYr/vbNx9lrQWb/4 ZYy1mYDEc34MeZzavFMuyJ0Loy38hSd8UPw30myyplt9XpwZh1DdWNnYQ9iwusrukDZe X4jiNlMKo9FwPmGBOw26Y34mNv2bHtG/AkTDLp8GeNssr+HBdd6cW+sr3yDJCEmEUCeW G9vRoJzr9olEC6RFNO5pUoqHkAjrvEIWgiBEAtEwsl7JpI414Jlx+IKAYWp4i/YcUirK 5BnQ== X-Gm-Message-State: APjAAAVmb2XwC4u2YC3hjY8Z2MurPcoZgIONBsa2WXEp9Zl6SBWw2Z17 6M02pBxMdbAw5bLUCsDVXzeHMpQhiJglqA== X-Google-Smtp-Source: APXvYqzGkgKlROLa1vpB+bgXfoKvFvNt2atW17HLCmj51yqGW+FXl6w2vpYN8KIkQlIOr7EOeRH4cQ== X-Received: by 2002:ae9:dcc3:: with SMTP id q186mr602599qkf.114.1556752308186; Wed, 01 May 2019 16:11:48 -0700 (PDT) Received: from p7-1130br.casantos.org ([177.156.131.99]) by smtp.gmail.com with ESMTPSA id f1sm10232380qkc.50.2019.05.01.16.11.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 May 2019 16:11:47 -0700 (PDT) From: unixmania@gmail.com To: buildroot@buildroot.org Date: Wed, 1 May 2019 20:11:40 -0300 Message-Id: <20190501231140.6365-2-unixmania@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190501231140.6365-1-unixmania@gmail.com> References: <20190501231140.6365-1-unixmania@gmail.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH v3 2/2] package/busybox: 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: Carlos Santos , Adam Duskett Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Carlos Santos 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 A file may be used more than once, since there can be multiple symlinks to it. No attempt is made to prevent this. Signed-off-by: Carlos Santos Reviewed-by: Matthew Weber --- Changes v2->v3: - Update SOB, since I don't work for DATACOM anymore. Changes v1->v2: - Use a while loop to process all files. - 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 "-q" 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/busybox/S02sysctl | 66 ++++++++++++++++++++++++++++++++++++++ package/busybox/busybox.mk | 12 +++++++ 2 files changed, 78 insertions(+) create mode 100644 package/busybox/S02sysctl --- package/busybox/S02sysctl | 66 ++++++++++++++++++++++++++++++++++++++ package/busybox/busybox.mk | 12 +++++++ 2 files changed, 78 insertions(+) create mode 100644 package/busybox/S02sysctl diff --git a/package/busybox/S02sysctl b/package/busybox/S02sysctl new file mode 100644 index 0000000000..6bb2fa165e --- /dev/null +++ b/package/busybox/S02sysctl @@ -0,0 +1,66 @@ +#!/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" + +# Use some scripting to mimic the --system option of the sysctl provided by +# procps-ng 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. +# +# Testing the sysctl exit code is fruitless, as at the moment, since it ends +# with status zero even if errors happen. Hopefully this will be fixed in a +# future version of Busybox. +# +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/busybox/busybox.mk b/package/busybox/busybox.mk index 67b91500e9..416b6f9bae 100644 --- a/package/busybox/busybox.mk +++ b/package/busybox/busybox.mk @@ -259,6 +259,17 @@ define BUSYBOX_INSTALL_LOGGING_SCRIPT endef endif +# Only install our sysctl scripts if no other package does it. +ifeq ($(BR2_PACKAGE_PROCPS_NG),) +define BUSYBOX_INSTALL_SYSCTL_SCRIPT + if grep -q CONFIG_BB_SYSCTL=y $(@D)/.config; \ + then \ + $(INSTALL) -m 0755 -D package/busybox/S02sysctl \ + $(TARGET_DIR)/etc/init.d/S02sysctl ; \ + fi +endef +endif + ifeq ($(BR2_INIT_BUSYBOX),y) define BUSYBOX_INSTALL_INITTAB $(INSTALL) -D -m 0644 package/busybox/inittab $(TARGET_DIR)/etc/inittab @@ -340,6 +351,7 @@ define BUSYBOX_INSTALL_INIT_SYSV $(BUSYBOX_INSTALL_MDEV_SCRIPT) $(BUSYBOX_INSTALL_LOGGING_SCRIPT) $(BUSYBOX_INSTALL_WATCHDOG_SCRIPT) + $(BUSYBOX_INSTALL_SYSCTL_SCRIPT) $(BUSYBOX_INSTALL_TELNET_SCRIPT) $(BUSYBOX_INSTALL_INDIVIDUAL_BINARIES) endef