From patchwork Wed Jun 28 08:49:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodolfo Giometti X-Patchwork-Id: 781505 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wyGgq3HGQz9rxm for ; Wed, 28 Jun 2017 18:49:43 +1000 (AEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 88BFEB90D75; Wed, 28 Jun 2017 10:49:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Wed, 28 Jun 2017 10:49:19 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8E01CB80CD2 for ; Wed, 28 Jun 2017 10:49:16 +0200 (CEST) X-policyd-weight: using cached result; rate: -4 Received: from mail1.hce-engineering.com (mail1.hce-engineering.com [104.233.86.154]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 28 Jun 2017 10:49:16 +0200 (CEST) Received: from net-93-146-66-165.cust.vodafonedsl.it ([93.146.66.165] helo=localhost.localdomain) by hce1.hce-engineering.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84) (envelope-from ) id 1dQ8TU-00028x-T6; Wed, 28 Jun 2017 10:37:26 +0200 From: Rodolfo Giometti To: Jo-Philipp Wich Date: Wed, 28 Jun 2017 10:49:01 +0200 Message-Id: <20170628084901.640-2-giometti@linux.it> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170628084901.640-1-giometti@linux.it> References: <20170628084901.640-1-giometti@linux.it> X-SA-Exim-Connect-IP: 93.146.66.165 X-SA-Exim-Mail-From: giometti@linux.it X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on hce1.hce-engineering.com) Subject: [OpenWrt-Devel] [PATCH 1/1] package sysfsutils: add support for sysfs settings at boot X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openwrt-devel@lists.openwrt.org MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" This patch is based on sysfsutils package's behaviour on Debian OS. Signed-off-by: Rodolfo Giometti --- package/libs/sysfsutils/Makefile | 12 ++++++++ package/libs/sysfsutils/files/local.conf | 1 + package/libs/sysfsutils/files/sysfs.conf | 22 +++++++++++++++ package/libs/sysfsutils/files/sysfsutils | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 package/libs/sysfsutils/files/local.conf create mode 100644 package/libs/sysfsutils/files/sysfs.conf create mode 100644 package/libs/sysfsutils/files/sysfsutils diff --git a/package/libs/sysfsutils/Makefile b/package/libs/sysfsutils/Makefile index 9ee76a0362..6d74d0bbfc 100644 --- a/package/libs/sysfsutils/Makefile +++ b/package/libs/sysfsutils/Makefile @@ -65,9 +65,21 @@ define Package/libsysfs/install endef define Package/sysfsutils/install + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/sysfsutils $(1)/etc/init.d/ + + $(INSTALL_DATA) ./files/sysfs.conf $(1)/etc/ + $(INSTALL_DIR) $(1)/etc/sysfs.d + $(INSTALL_DATA) ./files/local.conf $(1)/etc/sysfs.d/ + $(INSTALL_DIR) $(1)/usr/bin $(CP) $(PKG_INSTALL_DIR)/usr/bin/systool $(1)/usr/bin/ endef +define Package/sysfsutils/conffiles +/etc/sysfs.conf +/etc/sysfs.d/local.conf +endef + $(eval $(call BuildPackage,libsysfs)) $(eval $(call BuildPackage,sysfsutils)) diff --git a/package/libs/sysfsutils/files/local.conf b/package/libs/sysfsutils/files/local.conf new file mode 100644 index 0000000000..891da73df8 --- /dev/null +++ b/package/libs/sysfsutils/files/local.conf @@ -0,0 +1 @@ +# local sysctl settings can be stored in this directory diff --git a/package/libs/sysfsutils/files/sysfs.conf b/package/libs/sysfsutils/files/sysfs.conf new file mode 100644 index 0000000000..f03246284f --- /dev/null +++ b/package/libs/sysfsutils/files/sysfs.conf @@ -0,0 +1,22 @@ +# +# /etc/sysfs.conf - Configuration file for setting sysfs attributes. +# +# The sysfs mount directory is automatically prepended to the attribute paths. +# +# Syntax: +# attribute = value +# mode attribute = 0600 # (any valid argument for chmod) +# owner attribute = root:wheel # (any valid argument for chown) +# +# Examples: +# +# Always use the powersave CPU frequency governor +# devices/system/cpu/cpu0/cpufreq/scaling_governor = powersave +# +# Use userspace CPU frequency governor and set initial speed +# devices/system/cpu/cpu0/cpufreq/scaling_governor = userspace +# devices/system/cpu/cpu0/cpufreq/scaling_setspeed = 600000 +# +# Set permissions of suspend control file +# mode power/state = 0660 +# owner power/state = root:power diff --git a/package/libs/sysfsutils/files/sysfsutils b/package/libs/sysfsutils/files/sysfsutils new file mode 100644 index 0000000000..0305ca82a9 --- /dev/null +++ b/package/libs/sysfsutils/files/sysfsutils @@ -0,0 +1,48 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2017 Rodolfo Giometti +# +# Based on Debian's script /etc/init.d/sysfsutils by +# Martin Pitt + +load_conffile() { + FILE="$1" + sed 's/#.*$//; /^[[:space:]]*$/d; + s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' \ + $FILE | { + while read f1 f2 f3; do + if [ "$f1" = "mode" -a -n "$f2" -a -n "$f3" ]; then + if [ -f "/sys/$f2" ] || [ -d "/sys/$f2" ]; then + chmod "$f3" "/sys/$f2" + else + echo "unknown attribute $f2" + fi + elif [ "$f1" = "owner" -a -n "$f2" -a -n "$f3" ]; then + if [ -f "/sys/$f2" ]; then + chown "$f3" "/sys/$f2" + else + echo "unknown attribute $f2" + fi + elif [ "$f1" -a -n "$f2" -a -z "$f3" ]; then + if [ -f "/sys/$f1" ]; then + # Some fields need a terminating newline, others + # need the terminating newline to be absent :-( + echo -n "$f2" > "/sys/$f1" 2>/dev/null || + echo "$f2" > "/sys/$f1" + else + echo "unknown attribute $f1" + fi + else + echo "syntax error in $CONFFILE: '$f1' '$f2' '$f3'" + exit 1 + fi + done + } +} + +START=11 +start() { + for file in /etc/sysfs.conf /etc/sysfs.d/*.conf; do + [ -r "$file" ] || continue + load_conffile "$file" + done +}