From 04c5222abcb46fef9ba337f279396cd13d711faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Fri, 21 Aug 2015 16:33:19 +0200 Subject: [PATCH] functions: fixed sysfs save to work with options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit E.g.: $ cat /sys/block/sda/queue/scheduler noop [deadline] cfq The 'save_sys' function needs to save 'deadline', not 'noop [deadline] cfq'. Resolves: rhbz#1251507 Signed-off-by: Jaroslav Škarvada --- profiles/functions | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/profiles/functions b/profiles/functions index 957dfb6..510eb12 100644 --- a/profiles/functions +++ b/profiles/functions @@ -21,11 +21,22 @@ save_value() { [ "$2" -a -e "${STORAGE}" ] && echo "$2" > "${STORAGE}/${1}${STORAGE_SUFFIX}" } +# Parse sysfs value, i.e. for "val1 [val2] val3" return "val2" +# $0 SYSFS_NAME +parse_sys() { + local V1 V2 + [ -r "$1" ] || return + V1=`cat "$1"` + V2="${V1##*[}" + V2="${V2%%]*}" + echo "${V2:-$V1}" +} + # Save sysfs value # $0 STORAGE_NAME SYSFS_NAME save_sys() { [ "$#" -ne 2 ] && return - [ -r "$2" -a ! -e "${STORAGE}/${1}${STORAGE_SUFFIX}" ] && cat "$2" > "${STORAGE}/${1}${STORAGE_SUFFIX}" + [ -r "$2" -a ! -e "${STORAGE}/${1}${STORAGE_SUFFIX}" ] && parse_sys "$2" > "${STORAGE}/${1}${STORAGE_SUFFIX}" } # Set sysfs value @@ -105,7 +116,7 @@ set_elevator() { # $0 DEVICES [ELEVATOR] restore_elevator() { re_elevator="$2" - [ "$re_elevator" ] || re_elevator = cfq + [ "$re_elevator" ] || re_elevator=cfq _set_elevator_helper restore_sys "$1" "$re_elevator" }