From patchwork Fri Jan 24 09:06:31 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: 23664 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f199.google.com (mail-gg0-f199.google.com [209.85.161.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CDB7520307 for ; Fri, 24 Jan 2014 09:06:49 +0000 (UTC) Received: by mail-gg0-f199.google.com with SMTP id n5sf3150272ggj.6 for ; Fri, 24 Jan 2014 01:06:48 -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=Vt+p6RbwxYYGJMdgGdz/Fh6wLdArl/Ef+m6QYdHR3gc=; b=QpdcjAcy0YheZFwZOvNSjVh/2G2GHLpAzQyrQ5x8WWhwZumAa324OXy+35bzgJ/DTi 2EsonFUqkNhgPLvM4M0UgcfunaeyD0QeP3NhrrwN0ER2DE2sy1n66vdMitaDm22+WTf+ e3Xb04yfXniM/sdMAzQo61SPIEFYa2/gfIzWL58z/g40ucpsujypTH6OcAeH82l+5XD6 bDM2EDKuc0OyM5QRlziUHEHNewcZ5aZoO4jW1Z7+be0wYUka5P4pVE08OtIFsZ7Yz5sP 6FjHpFXi67yC6mnsZA7dvIvIyw4y/nsogLPrILLFQTJD3QU7D+2jDK9xGfz4EbckCTce m0cw== X-Gm-Message-State: ALoCoQkzKPUSURMqVLsKeYOVT4b03DSExf6o+iOLxLoydnqQoEr7J01snpeOMkJ42f81xNjJ5k1/ X-Received: by 10.236.69.35 with SMTP id m23mr4276454yhd.6.1390554408325; Fri, 24 Jan 2014 01:06:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.73 with SMTP id i67ls515597qgd.97.gmail; Fri, 24 Jan 2014 01:06:48 -0800 (PST) X-Received: by 10.58.75.6 with SMTP id y6mr7077599vev.23.1390554408200; Fri, 24 Jan 2014 01:06:48 -0800 (PST) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id ja16si160449vec.50.2014.01.24.01.06.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 01:06:48 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id c14so1812934vea.3 for ; Fri, 24 Jan 2014 01:06:48 -0800 (PST) X-Received: by 10.220.159.4 with SMTP id h4mr7075690vcx.1.1390554408118; Fri, 24 Jan 2014 01:06:48 -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 u4csp87463vcz; Fri, 24 Jan 2014 01:06:47 -0800 (PST) X-Received: by 10.68.230.137 with SMTP id sy9mr13181440pbc.126.1390554407128; Fri, 24 Jan 2014 01:06:47 -0800 (PST) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) by mx.google.com with ESMTPS id ye6si314207pbc.320.2014.01.24.01.06.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 01:06:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.53 is neither permitted nor denied by best guess record for domain of sanjay.rawat@linaro.org) client-ip=209.85.160.53; Received: by mail-pb0-f53.google.com with SMTP id md12so3001589pbc.40 for ; Fri, 24 Jan 2014 01:06:46 -0800 (PST) X-Received: by 10.66.171.196 with SMTP id aw4mr13116058pac.51.1390554406535; Fri, 24 Jan 2014 01:06:46 -0800 (PST) Received: from srawat-Latitude-E6420.LGE.NET ([203.247.149.152]) by mx.google.com with ESMTPSA id qz9sm1063473pbc.3.2014.01.24.01.06.42 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Jan 2014 01:06:45 -0800 (PST) From: Sanjay Singh Rawat To: private-pmwg@linaro.org Cc: Sanjay Singh Rawat Subject: [PATCH] add method to check the userid for android Date: Fri, 24 Jan 2014 14:36:31 +0530 Message-Id: <1390554391-15330-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.128.172 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 --- cpufreq/cpufreq_03.sh | 5 +++-- 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 | 26 ++++++++++++++++++++++++++ 11 files changed, 61 insertions(+), 24 deletions(-) diff --git a/cpufreq/cpufreq_03.sh b/cpufreq/cpufreq_03.sh index 85118d7..7b08da0 100755 --- a/cpufreq/cpufreq_03.sh +++ b/cpufreq/cpufreq_03.sh @@ -49,8 +49,9 @@ check_governor() { set_governor $cpu $oldgov } -if [ $(id -u) -ne 0 ]; then - log_skip "run as non-root" +get_uid +if [ $? -ne 0 ]; then + log_skip "user is not root" exit 0 fi diff --git a/cpufreq/cpufreq_04.sh b/cpufreq/cpufreq_04.sh index 4a07315..9609f65 100755 --- a/cpufreq/cpufreq_04.sh +++ b/cpufreq/cpufreq_04.sh @@ -33,6 +33,12 @@ if [ $? -ne 0 ]; then exit 0 fi +get_uid +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..1702ab7 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" +get_uid +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..ac81288 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" +get_uid +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..f9dca2e 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" +get_uid +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..749b4bf 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" +get_uid +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..8baac8f 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" +get_uid +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..d5020c0 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" +get_uid +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..4ef5538 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" +get_uid +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 +get_uid +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..a489cb6 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" +get_uid +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..2307cde 100644 --- a/include/functions.sh +++ b/include/functions.sh @@ -348,3 +348,29 @@ 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) + return $ret + else + # for android + ret=$(id | sed -n 's/uid=//p' | sed -n 's/(root) [a-z]*=[0-9]*(log)//p') + return $ret + fi +}