From patchwork Fri Mar 20 23:35:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1259263 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.137; helo=fraxinus.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=gVz0g2pH; dkim-atps=neutral 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 48kgC02fZZz9sPk for ; Sat, 21 Mar 2020 10:36:11 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2979D87612; Fri, 20 Mar 2020 23:36:09 +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 bVQ0s2XqkNho; Fri, 20 Mar 2020 23:36:07 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id EAFB987561; Fri, 20 Mar 2020 23:36:06 +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 5B43D1BF9BD for ; Fri, 20 Mar 2020 23:36:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 29A29254EB for ; Fri, 20 Mar 2020 23:36:04 +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 fmhp5MX2Ro7Z for ; Fri, 20 Mar 2020 23:36:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by silver.osuosl.org (Postfix) with ESMTPS id E4A9F26319 for ; Fri, 20 Mar 2020 23:36:00 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id g7so605716qtj.13 for ; Fri, 20 Mar 2020 16:36:00 -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=NkbW4C0UDXbxEVe26DzJ1So/vOF7c1wkeJb3LZ9SD1E=; b=gVz0g2pHFtq0tGc64u2peKly25ZWsdTjiR4mGP1Wk6jj/wYhesdczo88R1nBfkXwNi SHyLJNt93dLDBGvM+KXYN5KvvWK/deu/c0FZdQBukZoUWMAEYg7jfd4m3IauVDzl0yco hkC193QsoQr8kqsmCo5vI5ALZc3Bu0i70Qg/BlTdTPmLlT2qD5W+YRsbjn0167fwluHO lKoRAAY6rO7Qaq8g9D11PA3LhZyvNUwjpwKsE1qe3ayH3wz3OO7MuWj3KT1nCCoIEOX3 fBR34qkjZAPHieLfGz7X8eYGDiTT8YpXs+nZCwh8PLYM0g9USCaNHx71zrutLjpCgGUY HWmQ== 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=NkbW4C0UDXbxEVe26DzJ1So/vOF7c1wkeJb3LZ9SD1E=; b=gqM/EHVcDVU52HLfIUBU1SxgW8P04hH3FtW26nplaK8UkvlAMOsAMQfm0jeF0/StJX nxG4uGLz8s7y23IK5iPJPNKlS1d4K/79RGrydy4V+iOKAp4CFxlmXK8vdvoZisrd4xVT 0Qn4o2Drl+/oMP5YWJjNDJs8uJKifiX75Xb68fh8noQGzohKQrXblyFY5Q+LrtUTioe5 Ur2op8GixYDGtXMBuL1l9UJXtF0QVFlx7C89HPLzdDdc6JHB7qta+BPKfi96+JAnQksU 23K8sGBY45b8UFds18flLQ77Z0h0nOsIIP+UWbWTzYgabaoelRRzNTNpnXQY7im9r5/q 8VaA== X-Gm-Message-State: ANhLgQ2O/mr84RbJ82tkKLNyK0Pz2TdawWKP7UzSUWjqejPcDRgKoiWa aRklrPaPnkdmrklBSUKrCyOkjxreT+o= X-Google-Smtp-Source: ADFU+vsTW6f+0VamfxkAa83gaDMWGBUxRtwpA3kVNxDIrCEzG2Br/gqPpBHNRHqpxA/7pucjppeODQ== X-Received: by 2002:ac8:2c36:: with SMTP id d51mr6119942qta.61.1584747359502; Fri, 20 Mar 2020 16:35:59 -0700 (PDT) Received: from casantos.remote.com (177.204.229.175.dynamic.adsl.gvt.net.br. [177.204.229.175]) by smtp.gmail.com with ESMTPSA id p38sm6265257qtf.50.2020.03.20.16.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Mar 2020 16:35:58 -0700 (PDT) From: unixmania@gmail.com To: buildroot@buildroot.org Date: Fri, 20 Mar 2020 20:35:42 -0300 Message-Id: <20200320233547.28586-2-unixmania@gmail.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200320233547.28586-1-unixmania@gmail.com> References: <20200320233547.28586-1-unixmania@gmail.com> Subject: [Buildroot] [[PATCH RFC] 1/6] 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 , 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 foo --- package/kmod/S02modules-load | 85 ++++++++++++++++++++++++++++++++++++ package/kmod/kmod.mk | 5 +++ 2 files changed, 90 insertions(+) create mode 100644 package/kmod/S02modules-load diff --git a/package/kmod/S02modules-load b/package/kmod/S02modules-load new file mode 100644 index 0000000000..099cc63023 --- /dev/null +++ b/package/kmod/S02modules-load @@ -0,0 +1,85 @@ +#!/bin/sh + +PROGRAM="modules-load" + +MODULES_LOAD_ARGS="" + +# shellcheck source=/dev/null +[ -r "/etc/default/$PROGRAM" ] && . "/etc/default/$PROGRAM" + +# 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. + +MODULES_LOAD_D="/etc/modules-load.d/ /run/modules-load.d/ /usr/lib/modules-load.d/" + +# Use some scripting to mimic the systemd-modules-load utility provided by +# systemd, reporting results to syslog. Uers not interested on messages can +# put "-q" in MODULES_LOAD_ARGS. + +run_program() { + # shellcheck disable=SC2086 # we need the word splitting + find $MODULES_LOAD_D -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 ..." + while :; do + read -r mod || break + case "$mod" in + ''|'#'*|';'*) ;; + *) /sbin/modprobe -s "$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 +} + +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..31bdac6d81 100644 --- a/package/kmod/kmod.mk +++ b/package/kmod/kmod.mk @@ -60,6 +60,11 @@ else KMOD_BIN_PATH = ../usr/bin/kmod endif +define KMOD_INSTALL_INIT_SYSV + $(INSTALL) -m 0755 -D package/kmod/S02modules-load \ + $(TARGET_DIR)/etc/init.d/S02modules-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; \