Thread (32 messages) flat view 32 messages, 6 authors, 2013-02-19

Re: SYSFS "errors"

From: Mauro Carvalho Chehab <hidden>
Date: 2013-02-19 13:43:32
Also in: linux-pm, linux-scsi, lkml

Possibly related (same subject, not in this thread)

Em Tue, 19 Feb 2013 14:06:26 +0100
Borislav Petkov [off-list ref] escreveu:
quoted
No, on both cases, open() will return an error (-ENOENT against -EPERM).
What if it is a shell script doing:

cat /sys/devices/system/edac/mc/mc0/sdram_scrub_rate

or similar?
Well, cat will return "1" if an error is found, no matter what error happened. 

With an existing file (-ENOSYS):

	$ cat /sys/devices/system/edac/mc/mc0/sdram_scrub_rate; echo $?

	cat: /sys/devices/system/edac/mc/mc0/sdram_scrub_rate: No such device
	1

When the file doesn't exist (-ENOENT):
	$ cat /sys/devices/system/edac/mc/mc0/sdram_scrub_rate_not_exist; echo $?
	cat: /sys/devices/system/edac/mc/mc0/sdram_scrub_rate_not_exist: No such file or directory
	1

When permission doesn't match (-EPERM):
	$ cat /sys/devices/system/cpu/probe; echo $?
	cat: /sys/devices/system/cpu/probe: Permission denied
	1

When everything is ok, it will return 0
	$ cat /sys/devices/system/edac/mc/mc0/ce_count; echo $? >/dev/null
	0

A script ready to handle -ENOSYS would be doing, instead:

	RATE=$(cat /sys/devices/system/edac/mc/mc0/ce_count 2>/dev/null)
	if [ "$?" == "0" ]; then echo "Scrub rate: $RATE"; fi

So, a bash script won't notice any difference.

The only difference will be noticed if the script is written on some other 
language and the script is dumb enough to assume success if the errno is
different than -ENOSYS.

-- 

Cheers,
Mauro
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help