Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

->spew() not usable for procfs/sysfs virtual filesystems / readonly directories #92

Closed
kentfredric opened this issue Apr 3, 2014 · 2 comments

Comments

@kentfredric
Copy link

This is because the directory cannot have nodes added to it, but the nodes are still writeable.

perl -MCarp::Always -MPath::Tiny=path -E 'path(q[/sys/devices/system/cpu/intel_pstate/max_perf_pct])->spew(100)'                                                                                                       
#Error sysopen on '/sys/devices/system/cpu/intel_pstate/max_perf_pct0831895': #Permission denied at /usr/lib64/perl5/vendor_perl/5.18.2/Path/Tiny.pm line 773.
#        Path::Tiny::Error::throw('Path::Tiny::Error', 'sysopen', '/sys/devices/system/cpu/intel_pstate/max_perf_pct0831895', 'Permission denied') called at /usr/lib64/perl5/vendor_perl/5.18.2/Path/Tiny.pm line 96
#        Path::Tiny::_throw('Path::Tiny=ARRAY(0x1602588)', 'sysopen') called at /usr/lib64/perl5/vendor_perl/5.18.2/Path/Tiny.pm line 376
#        Path::Tiny::filehandle('Path::Tiny=ARRAY(0x1602588)', 'HASH(0x15ef0e8)', '>', undef) called at /usr/lib64/perl5/vendor_perl/5.18.2/Path/Tiny.pm line 696
#        Path::Tiny::spew('Path::Tiny=ARRAY(0x1602498)', 100) called at -e line 1
echo 100 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
echo $?
#0

The same is the case with files that are writable in directories that are not:

ls -lah
# total 204K
# drwxr-xr-x  2 root root 4.0K Apr  4 03:15 .
# drwxrwxrwt 20 root root 196K Apr  4 03:15 ..
# -rw-r--r--  1 kent kent    0 Apr  4 03:15 bar
perl -MPath::Tiny -E'path(q[./bar])->spew(q[hello])' 
# Error sysopen on 'bar8321321244076350': Permission denied at -e line 1.
echo world > bar
echo $?
#0
cat bar
# world
@dagolden
Copy link
Collaborator

dagolden commented Apr 4, 2014

That's by design and documented. Without that, an atomic write can't be guaranteed. If you need to write to such a file, you have to do it the old fashioned way and open a handle.

@dagolden dagolden closed this as completed Apr 4, 2014
@kentfredric
Copy link
Author

IME this is a candidate for an option for being unsafe / fast.

Just where you'd put it in the command is the question..

spew( $opthash?, @data );
...
spew( { direct => 1 }, @data ); 

or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant