Is this behaviour deliberate, or a bug? The chown binary from gnu coreutils
does not do this.
Example:
rubyx@atlas bb $ echo “test” > test
rubyx@atlas bb $ chmod +sx test
rubyx@atlas bb $ ls -l
total 4
-rwsr-sr-x 1 rubyx users 5 Aug 29 19:56 test
rubyx@atlas bb $ sudo irb
irb(main):001:0> File.chown(0,0,‘test’)
=> 1
irb(main):002:0> exit
rubyx@atlas bb $ ls -l
total 4
-rwxr-xr-x 1 root root 5 Aug 29 19:56 test
rubyx@atlas bb $
Is this behaviour deliberate, or a bug? The chown binary
from gnu coreutils does not do this.
You don’t say what platform you are running on, but “man 2 chown” on
my RH8 box says (in part):
When the owner or group of an executable file are changed by a non-
super-user, the S_ISUID and S_ISGID mode bits are cleared. POSIX does
not specify whether this also should happen when root does the chown;
the Linux behaviour depends on the kernel version. In case of a non-
group-executable file (with clear S_IXGRP bit) the S_ISGID bit indi-
cates mandatory locking, and is not cleared by a chown.
so Ruby is just doing what the system call does.
d.k.
···
–
Daniel Kelley - San Jose, CA
For email, replace the first dot in the domain with an at.
> Is this behaviour deliberate, or a bug? The chown binary
> from gnu coreutils does not do this.
You don’t say what platform you are running on, but “man 2 chown” on
my RH8 box says (in part):
When the owner or group of an executable file are changed by a
non-
super-user, the S_ISUID and S_ISGID mode bits are cleared. POSIX
does
not specify whether this also should happen when root does the
chown;
the Linux behaviour depends on the kernel version. In case of a
non-
group-executable file (with clear S_IXGRP bit) the S_ISGID bit
indi-
cates mandatory locking, and is not cleared by a chown.
so Ruby is just doing what the system call does.
Thanks Daniel. This not only answers my question, but brings to my notice
the mysterious lack of man2 manual pages on my system 
I guess /bin/chown must explicitly save the permissions then reset them
after the call to chown()
Thanks
Andrew Walrond