Messages in this thread | | | Date | Mon, 09 Jul 2012 09:24:38 +1000 | From | Ryan Mallon <> | Subject | Re: /sys and access(2): Correctly implemented? |
| |
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
| |