linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ryan Mallon <rmallon@gmail.com>
To: Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: /sys and access(2): Correctly implemented?
Date: Mon, 09 Jul 2012 09:24:38 +1000	[thread overview]
Message-ID: <4FFA16B6.9050009@gmail.com> (raw)
In-Reply-To: <4FF6A17B020000A10000A5E8@gwsmtp1.uni-regensburg.de>

On 06/07/12 16:27, Ulrich Windl wrote:
> Hi!
> 
> Recently I found a problem with the command (kernel 3.0.34-0.7-default from SLES 11 SP2, run as root):
> test -r "$file" && cat "$file"
> emitting "Permission denied"
> 
> Investigating, I found that "test" actually uses "access()" to check for permissions. Unfortunately there are some files in /sys that have "write-only" permission bits set (e.g. /sys/devices/system/cpu/probe).
> 
> ~ # ll /sys/devices/system/cpu/probe
> --w------- 1 root root 4096 Jun 29 12:43 /sys/devices/system/cpu/probe
> ~ # F=/sys/devices/system/cpu/probe
> ~ # test "$F" && cat "$F"
> cat: /sys/devices/system/cpu/probe: Permission denied

Looks like you have a typo here, I think you wanted "test -r $F", not
"test $F", the latter will just evaluate "$F" as an expression which
will be true, and so you get the permission denied error running cat.

Using "test -r $F" on a write-only sysfs file correctly returns false on
my machine (Ubuntu 10.04.4 LTS/2.6.32-41-generic).

~Ryan

  reply	other threads:[~2012-07-08 23:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06  6:27 /sys and access(2): Correctly implemented? Ulrich Windl
2012-07-08 23:24 ` Ryan Mallon [this message]
2012-07-09  6:23   ` Antw: " Ulrich Windl
2012-07-09  7:22     ` Ryan Mallon
2012-07-09  8:11       ` Ulrich Windl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FFA16B6.9050009@gmail.com \
    --to=rmallon@gmail.com \
    --cc=Ulrich.Windl@rz.uni-regensburg.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).