Making lchmod semantics work in OpenBSD (possibly Linux too). #1914

Closed
tonysidaway opened this Issue Sep 17, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@tonysidaway
Contributor

tonysidaway commented Sep 17, 2012

The spec spec/ruby/file/lchmod.rb requires the following behaviour from Rubinius in -X19 mode running on OpenBSD or Linux:

File.respond_to?(:lchmod).should be_false

lambda { File.lchmod }.should raise_error(NotImplementedError)

On OpenBSD at least FIle.respond_to?(:lchmod) returns true (because the method is defined in kernel/common/file.rb )
And File.lchmod returns an ArgumentError instead of NotImplementedError (ditto). The ArgumentError isn't an issue here because the :lchmod class method should never reach File on OpenBSD or Linux.

The solution here is that the method needs to be removed from class File (or not defined if possible) in the case of OpenBSD. As I'm still unfamiliar with the bootstrap process I don't know exactly where this should be done.

Should it be done in kernel/delta/file19.rb ?

Something like:

class <<File # The eigenclass of File.
remove_method :lchmod
end

but this should only happen for OpenBSD (and presumably Linux). Does the delta phase bootstrap have access to the constant Rubinius::OS ? If so that should do the trick.

@tonysidaway

This comment has been minimized.

Show comment Hide comment
@tonysidaway

tonysidaway Sep 18, 2012

Contributor

Fixed the above comment to change "remove_class" to "remove_method" in the example code.

Contributor

tonysidaway commented Sep 18, 2012

Fixed the above comment to change "remove_class" to "remove_method" in the example code.

@dbussink

This comment has been minimized.

Show comment Hide comment
@dbussink

dbussink Sep 22, 2012

Member

The problem here is that at least on Linux it doesn't expose lchmod through the headers, but it's actually available as a symbol in libc. Since we use FFI to attach these methods, it actually ends up working fine on Linux.

Also see #1827 and http://donttreadonme.co.uk/rubinius/2012/07/24.html

Is this also what happens on OpenBSD?

Member

dbussink commented Sep 22, 2012

The problem here is that at least on Linux it doesn't expose lchmod through the headers, but it's actually available as a symbol in libc. Since we use FFI to attach these methods, it actually ends up working fine on Linux.

Also see #1827 and http://donttreadonme.co.uk/rubinius/2012/07/24.html

Is this also what happens on OpenBSD?

@tonysidaway

This comment has been minimized.

Show comment Hide comment
@tonysidaway

tonysidaway Sep 22, 2012

Contributor

lchmod isn't there:

cc -O2 -pipe -o a a.c
/tmp//ccEkLL9i.o(.text+0x90): In function main': : undefined reference tolchmod'

As I understand it, Linux lchmod manipulates the protection bits of a symbolic link rather than following it and manipulating the target.

Instead, OpenBSD fchmodat is capable of doing this, but with different semantics and requiring a file descriptor to be opened prior to the call. So we could easily emulate lchmod in OpenBSD, or we could just disable it on that platform. If you'd like to see the emulation code, just ask.

Contributor

tonysidaway commented Sep 22, 2012

lchmod isn't there:

cc -O2 -pipe -o a a.c
/tmp//ccEkLL9i.o(.text+0x90): In function main': : undefined reference tolchmod'

As I understand it, Linux lchmod manipulates the protection bits of a symbolic link rather than following it and manipulating the target.

Instead, OpenBSD fchmodat is capable of doing this, but with different semantics and requiring a file descriptor to be opened prior to the call. So we could easily emulate lchmod in OpenBSD, or we could just disable it on that platform. If you'd like to see the emulation code, just ask.

@tonysidaway

This comment has been minimized.

Show comment Hide comment
@tonysidaway

tonysidaway Sep 24, 2012

Contributor

The problem here is with Ruby MRI. I've logged an enhancement request, Feature 7060, at the MRI website. fchmodat is in the Posix standard and should be supported by Ruby on any platform that implements it.

Contributor

tonysidaway commented Sep 24, 2012

The problem here is with Ruby MRI. I've logged an enhancement request, Feature 7060, at the MRI website. fchmodat is in the Posix standard and should be supported by Ruby on any platform that implements it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment