From patchwork Sat Apr 18 22:14:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1272738 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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.a=rsa-sha256 header.s=20161025 header.b=HSDuFyaM; 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 494S1N0DM7z9sRN for ; Sun, 19 Apr 2020 08:14:30 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 7296287B77; Sat, 18 Apr 2020 22:14:27 +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 Us-2uc8lJ7iP; Sat, 18 Apr 2020 22:14:25 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 600D687B5E; Sat, 18 Apr 2020 22:14:25 +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 6B04E1BF577 for ; Sat, 18 Apr 2020 22:14:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 667F485CFF for ; Sat, 18 Apr 2020 22:14:24 +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 li-MHjRhVJoQ for ; Sat, 18 Apr 2020 22:14:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 23FF185AE9 for ; Sat, 18 Apr 2020 22:14:22 +0000 (UTC) Received: by mail-qv1-f68.google.com with SMTP id w18so2397073qvs.3 for ; Sat, 18 Apr 2020 15:14:22 -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; bh=TNXo+243M8qhsQGaQUuj1RBQ5Qe8r2XEVf+n5O0PFCU=; b=HSDuFyaMKnLAeaPYqmRt3zqkawinCNI3cWaKfx3anh2lv8A8SDN+WtEgfStr9v4nZJ y6DT+80VNYJGUNitm5biqx7oIk/etZ6+Sro5tFND9vuELfkLYwAGvBOqKImLWzzQK329 yi5w/EFsNHIkDOmnt6J6ae4RQLfkbEXT9dZD/XJ8ia+HtE/F7r+qMSD4U+kOybsc6YDe 0Lx5ge8trK3hO7ij+zRFZBgtWijAxNHG/p9KPsPuJ534BMM3ZIXu/VbaBmjz93os0hb6 x3rCgi3YyIq3gnwlhIA1TRfNnSu/bnRok5W7zCURefNM7vQ2KQtzewEqi6ftrxifB7b7 eajA== 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; bh=TNXo+243M8qhsQGaQUuj1RBQ5Qe8r2XEVf+n5O0PFCU=; b=jZwl8CeBLq7NM4rg3PegHKq3Qf0WYEBEdZWjQHpPuGUm7AAwzquJCtKKVv2eqpRRTX ZQYzpOWV8QbVEub6y/ORmyBJAwW1dqgWd/fDp1CLxuLkNC+xYUI+GBoGuUJ7eenpZbLo 8+9sMRlv1r339ASM3i/bR2sVrzGTCm3+zcVsqA0t86lc4Dht/MM1nukWfvRrKHul6CZi zPWOEZJsi0f5igbn2ZzRp8OSLb1lCrLuOrRiL3frHwPrGorNb+MD5gmb33k2yeGVeHx5 2nQJE8W8rcq+MA+HKgvxTpQRq1HMhoWiSJTkxYG3lEVXHEI9uaGQ3zN9oJ2XdllVoXSj Ar1g== X-Gm-Message-State: AGi0Pua8Gd50ZxNKwYkLe0NhWCjoFPI6HtWXvKBDDCB4dCD1IO3vHhbF hv/758ZMHL01SlmXn6PgxhJpsoLCT0U= X-Google-Smtp-Source: APiQypIa71NRidemX4o5sSJD08J5Q+ApfVTYm/nnhkWdZrxe5E2JXalMiyrFt5luz6IjsXU6UUOcwA== X-Received: by 2002:a0c:bd17:: with SMTP id m23mr7525002qvg.37.1587248060293; Sat, 18 Apr 2020 15:14:20 -0700 (PDT) Received: from casantos.remote.csb.com (189.27.141.225.dynamic.adsl.gvt.net.br. [189.27.141.225]) by smtp.gmail.com with ESMTPSA id h3sm5335252qkf.15.2020.04.18.15.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2020 15:14:19 -0700 (PDT) From: unixmania@gmail.com To: buildroot@buildroot.org Date: Sat, 18 Apr 2020 19:14:07 -0300 Message-Id: <20200418221411.1549783-2-unixmania@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200418221411.1549783-1-unixmania@gmail.com> References: <20200418221411.1549783-1-unixmania@gmail.com> Subject: [Buildroot] [PATCH v2 1/5] package/kmod: add modules-load init script 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 , Lothar Felten , "Yann E. MORIN" , Adam Duskett MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Carlos Santos Use some scripting to mimic the systemd "modules-load" and the OpenRC "modules" services (load kernel modules based on static configuration). The configuration files should simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored. The configuration directory list and file format is the same as the one described in modules-load.d(5). Files are loaded in the following order: /etc/modules-load.d/*.conf /run/modules-load.d/*.conf /usr/lib/modules-load.d/*.conf This roughly mimics the logic used by systemd but the files are not sorted by their filename in lexicographic order as systemd does. Notice that OpenRC uses /etc/modules-load.d/*.conf, only, and does not ignore lines beginning with ';'. 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. Signed-off-by: Carlos Santos --- CC: "Yann E. MORIN" --- Changes v1->v2: - Redirect output to syslog only if /usr/bin/logger exists, as made in package/procps-ng/S02sysctl. - Use the MODULES_LOAD_ARGS variable, optionally set in /etc/default/modules-load. - Rename S02modules-load to S11modules-load to ensure that it runs after S10mdev and S10udev, which both are going to trigger cold-plug events that may in turn trigger module loading, as observed by Yann E. MORIN. - Prevent the installation of S11modules-load with openrc, which already provides the /etc/init.d/modules script. - Reorganize the comments in S11modules-load. --- package/kmod/S11modules-load | 115 +++++++++++++++++++++++++++++++++++ package/kmod/kmod.mk | 10 +++ 2 files changed, 125 insertions(+) create mode 100644 package/kmod/S11modules-load diff --git a/package/kmod/S11modules-load b/package/kmod/S11modules-load new file mode 100644 index 0000000000..9010230e23 --- /dev/null +++ b/package/kmod/S11modules-load @@ -0,0 +1,115 @@ +#!/bin/sh +# +# Use some scripting to mimic the systemd "modules-load" and the OpenRC +# "modules" services (load kernel modules based on static configuration). +# +# The configuration files should simply contain a list of kernel module +# names to load, separated by newlines. Empty lines and lines whose first +# non-whitespace character is # or ; are ignored. +# +# The configuration directory list and file format is the same as the one +# described in modules-load.d(5). Files are loaded in the following order: +# +# /etc/modules-load.d/*.conf +# /run/modules-load.d/*.conf +# /usr/lib/modules-load.d/*.conf +# +# This roughly mimics the logic used by systemd but the files are not sorted +# by their filename in lexicographic order as systemd does. +# +# Notice that OpenRC uses /etc/modules-load.d/*.conf, only, and does not +# ignore lines beginning with ';'. +# + +PROGRAM="modules-load" + +MODULES_LOAD_ARGS="" + +# Add "-q" to MODULES_LOAD_ARGS to disable error messages. +# shellcheck source=/dev/null +[ -r "/etc/default/$PROGRAM" ] && . "/etc/default/$PROGRAM" + +# Files are read from directories in the MODULES_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. +MODULES_SOURCES="/etc/modules-load.d/ /run/modules-load.d/ /usr/lib/modules-load.d/" + +# If the logger utility is available all messages are sent to syslog, except +# for the final status. 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_logger() { + # shellcheck disable=SC2086 # we need the word splitting + find $MODULES_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \ + xargs -0 -r -n 1 readlink -f | { + prog_status="OK" + while :; do + read -r file || { + echo "$prog_status" >&4 + break + } + echo "* Applying $file ..." + while :; do + read -r mod || break + case "$mod" in + ''|'#'*|';'*) ;; + *) /sbin/modprobe $MODULES_LOAD_ARGS "$mod" || prog_status="FAIL" + esac + done < "$file" + done 2>&1 >&3 | /usr/bin/logger -t "$PROGRAM" -p kern.err + } 3>&1 | /usr/bin/logger -t "$PROGRAM" -p kern.info +} + +# If logger is not available all messages are sent to stdout/stderr. +run_std() { + # shellcheck disable=SC2086 # we need the word splitting + find $MODULES_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \ + xargs -0 -r -n 1 readlink -f | { + prog_status="OK" + while :; do + read -r file || { + echo "$prog_status" >&4 + break + } + echo "* Applying $file ..." + while :; do + read -r mod || break + case "$mod" in + ''|'#'*|';'*) ;; + *) /sbin/modprobe $MODULES_LOAD_ARGS "$mod" || prog_status="FAIL" + esac + done < "$file" + done + } +} + +if [ -x /usr/bin/logger ]; then + run_program="run_logger" +else + run_program="run_std" +fi + +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/kmod/kmod.mk b/package/kmod/kmod.mk index e2dfea5c7b..9b6735e2d0 100644 --- a/package/kmod/kmod.mk +++ b/package/kmod/kmod.mk @@ -60,6 +60,16 @@ else KMOD_BIN_PATH = ../usr/bin/kmod endif +# Avoid installing S11modules-load, since openrc provides /etc/init.d/modules. +define KMOD_INSTALL_INIT_OPENRC + @: +endef + +define KMOD_INSTALL_INIT_SYSV + $(INSTALL) -m 0755 -D package/kmod/S11modules-load \ + $(TARGET_DIR)/etc/init.d/S11modules-load +endef + define KMOD_INSTALL_TOOLS for i in depmod insmod lsmod modinfo modprobe rmmod; do \ ln -sf $(KMOD_BIN_PATH) $(TARGET_DIR)/sbin/$$i; \