From patchwork Fri Jan 24 12:50:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanjay Singh Rawat X-Patchwork-Id: 23672 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C08B6203C5 for ; Fri, 24 Jan 2014 12:51:13 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id h16sf12010383oag.0 for ; Fri, 24 Jan 2014 04:51:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=BbvTERZCGCP4GTv7oKxzLwoyuM3qnVqi2NSkSg3isLI=; b=hEBr+wN80F20L/M9Lh/9MV35vHWt2+WGaZnUCEnDHKBCAn4JWZmGu+O3Ytu2jbr8Tk 8PBaWHnak+j6eLuuxLy+rt70thMVfnJgEnDWqSlWnJsIAD8CTKfX5B4JsKI1K+76QOJ/ aVTppXtvs73ZlAUokyuNihMHZC+BuePQfQm/eBqp7FJV4etJU2SQ47Q319N66g54U1+U SJfcPlcef8uy9yTgzlGuhuJYlWL9IXEpJfzCkoWcDU0kvBaMVhBRQrmWGBz5Nr4J+2GC Sh2t7VEcrVok/cpcBsmKlyQz5jSfdz1zjrBQelouRzkUHJ5gp24JFMa0vpEy02OHom1B hMJQ== X-Gm-Message-State: ALoCoQkN6tYPIg3JZ9rDFkejUSLT4xgKTQktc/ypYbBb8MLnQePCpsQ7G/wJfXt0lI5AOjCjfWPt X-Received: by 10.50.124.9 with SMTP id me9mr1838474igb.4.1390567872925; Fri, 24 Jan 2014 04:51:12 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.244 with SMTP id w107ls628843qge.26.gmail; Fri, 24 Jan 2014 04:51:12 -0800 (PST) X-Received: by 10.58.187.98 with SMTP id fr2mr34749vec.38.1390567872830; Fri, 24 Jan 2014 04:51:12 -0800 (PST) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id vi9si443970vec.132.2014.01.24.04.51.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 04:51:12 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id ld13so1855485vcb.32 for ; Fri, 24 Jan 2014 04:51:12 -0800 (PST) X-Received: by 10.59.0.193 with SMTP id ba1mr7574054ved.12.1390567872736; Fri, 24 Jan 2014 04:51:12 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp99956vcz; Fri, 24 Jan 2014 04:51:12 -0800 (PST) X-Received: by 10.68.184.194 with SMTP id ew2mr14345925pbc.100.1390567871764; Fri, 24 Jan 2014 04:51:11 -0800 (PST) Received: from mail-pb0-f47.google.com (mail-pb0-f47.google.com [209.85.160.47]) by mx.google.com with ESMTPS id bq5si1073694pbb.168.2014.01.24.04.51.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 04:51:11 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.47 is neither permitted nor denied by best guess record for domain of sanjay.rawat@linaro.org) client-ip=209.85.160.47; Received: by mail-pb0-f47.google.com with SMTP id rp16so3189430pbb.6 for ; Fri, 24 Jan 2014 04:51:11 -0800 (PST) X-Received: by 10.68.223.9 with SMTP id qq9mr14305647pbc.58.1390567871268; Fri, 24 Jan 2014 04:51:11 -0800 (PST) Received: from srawat-Latitude-E6420.LGE.NET ([203.247.149.152]) by mx.google.com with ESMTPSA id y9sm6847439pas.10.2014.01.24.04.51.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 04:51:10 -0800 (PST) From: Sanjay Singh Rawat To: private-pmwg@linaro.org Cc: Sanjay Singh Rawat Subject: [PATCH pmqa] add method to check the userid for android Date: Fri, 24 Jan 2014 18:20:55 +0530 Message-Id: <1390567855-20601-1-git-send-email-sanjay.rawat@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sanjay.rawat@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , id command option doesn't return same output, as it does for ubuntu. Add function with will check the system type and return the userid. Signed-off-by: Sanjay Singh Rawat --- On android the script shows error for "id" commadn return value. Added function to get the userid based on system type (ubuntu/android). - calling function in below manner doesn't return value to the _if_ case if [ $(is_root) -eq 0 ]; then so i am using is_root if [ $? -eq 0 ] - saving return value of function is not working on android. e.g local ret=$(is_root) Belows changes work find both. thanks, sanjay --- cpufreq/cpufreq_03.sh | 11 ++++++----- cpufreq/cpufreq_04.sh | 11 ++++++----- cpufreq/cpufreq_05.sh | 5 +++-- cpufreq/cpufreq_06.sh | 5 +++-- cpufreq/cpufreq_07.sh | 5 +++-- cpufreq/cpufreq_08.sh | 5 +++-- cpufreq/cpufreq_09.sh | 5 +++-- cpuidle/cpuidle_02.sh | 5 +++-- cpuidle/cpuidle_03.sh | 8 +++++--- cpuidle/cpuidle_04.sh | 5 +++-- include/functions.sh | 25 +++++++++++++++++++++++++ 11 files changed, 63 insertions(+), 27 deletions(-) diff --git a/cpufreq/cpufreq_03.sh b/cpufreq/cpufreq_03.sh index 85118d7..2bf2b3d 100755 --- a/cpufreq/cpufreq_03.sh +++ b/cpufreq/cpufreq_03.sh @@ -27,6 +27,12 @@ source ../include/functions.sh +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" + exit 0 +fi + cpufreq_enabled if [ $? -ne 0 ]; then log_skip "cpufreq not supported" @@ -49,10 +55,5 @@ check_governor() { set_governor $cpu $oldgov } -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" - exit 0 -fi - for_each_cpu for_each_governor check_governor || exit 1 test_status_show diff --git a/cpufreq/cpufreq_04.sh b/cpufreq/cpufreq_04.sh index 4a07315..3136b5c 100755 --- a/cpufreq/cpufreq_04.sh +++ b/cpufreq/cpufreq_04.sh @@ -33,6 +33,12 @@ if [ $? -ne 0 ]; then exit 0 fi +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" + exit 0 +fi + check_frequency() { local cpu=$1 @@ -52,11 +58,6 @@ check_frequency() { set_governor $cpu $oldgov } -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" - exit 0 -fi - supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace") if [ -z "$supported" ]; then log_skip "userspace not supported" diff --git a/cpufreq/cpufreq_05.sh b/cpufreq/cpufreq_05.sh index 3c76bc1..9a4e575 100755 --- a/cpufreq/cpufreq_05.sh +++ b/cpufreq/cpufreq_05.sh @@ -33,8 +33,9 @@ if [ $? -ne 0 ]; then exit 0 fi -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/cpufreq/cpufreq_06.sh b/cpufreq/cpufreq_06.sh index 157b1ef..ea2eb66 100755 --- a/cpufreq/cpufreq_06.sh +++ b/cpufreq/cpufreq_06.sh @@ -107,8 +107,9 @@ check_deviation() { for_each_frequency $cpu check_freq_deviation } -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/cpufreq/cpufreq_07.sh b/cpufreq/cpufreq_07.sh index 10fe909..12e1692 100755 --- a/cpufreq/cpufreq_07.sh +++ b/cpufreq/cpufreq_07.sh @@ -83,8 +83,9 @@ check_ondemand() { return 1 } -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/cpufreq/cpufreq_08.sh b/cpufreq/cpufreq_08.sh index 8ab33b7..636777c 100755 --- a/cpufreq/cpufreq_08.sh +++ b/cpufreq/cpufreq_08.sh @@ -72,8 +72,9 @@ check_userspace() { save_governors -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/cpufreq/cpufreq_09.sh b/cpufreq/cpufreq_09.sh index 832c303..8e89e10 100755 --- a/cpufreq/cpufreq_09.sh +++ b/cpufreq/cpufreq_09.sh @@ -68,8 +68,9 @@ check_powersave() { save_governors -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/cpuidle/cpuidle_02.sh b/cpuidle/cpuidle_02.sh index e604a8b..77261c4 100755 --- a/cpuidle/cpuidle_02.sh +++ b/cpuidle/cpuidle_02.sh @@ -29,8 +29,9 @@ source ../include/functions.sh CPUIDLE_KILLER=./cpuidle_killer -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/cpuidle/cpuidle_03.sh b/cpuidle/cpuidle_03.sh index b07bc89..645a94d 100755 --- a/cpuidle/cpuidle_03.sh +++ b/cpuidle/cpuidle_03.sh @@ -29,8 +29,9 @@ source ../include/functions.sh CPUIDLE_KILLER=./cpuidle_killer -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi @@ -49,7 +50,8 @@ check_cpuidle_kill() { check "cpuidle program runs successfully (120 secs)" "./$CPUIDLE_KILLER" } -if [ $(id -u) -ne 0 ]; then +is_root +if [ $? -ne 0 ]; then log_skip "run as non-root" exit 0 fi diff --git a/cpuidle/cpuidle_04.sh b/cpuidle/cpuidle_04.sh index 1688873..028b3ee 100644 --- a/cpuidle/cpuidle_04.sh +++ b/cpuidle/cpuidle_04.sh @@ -27,8 +27,9 @@ source ../include/functions.sh CPUIDLE_STATS=./cpuidle_stats -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +is_root +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/include/functions.sh b/include/functions.sh index 2124ceb..728f186 100644 --- a/include/functions.sh +++ b/include/functions.sh @@ -348,3 +348,28 @@ sigtrap() { cpufreq_enabled() { test -d /sys/devices/system/cpu/cpufreq } + +# currently we support ubuntu and android +get_os() { + lsb_release -a 2>&1 | grep -i ubuntu > /dev/null + if [ $? -eq 0 ]; then + # for ubuntu + return 1 + else + # for android (if needed can look for build.prop) + return 2 + fi +} + +get_uid() { + local ret + get_os + if [ $? -eq 1 ]; then + # for ubuntu + ret=$(id -u) + else + # for android + ret=$(id | sed -n 's/uid=//p' | sed -n 's/(root) [a-z]*=[0-9]*(log)//p') + fi + return $ret +}