On Fri, Mar 2, 2012 at 20:20:11 +0100, vladz wrote:
> On Fri, Mar 02, 2012 at 02:29:33PM +0100, Julien Cristau wrote:
> > I'm not convinced the chown can be removed. And 'mkdir -m 1777 foo' is
> > not any more atomic than 'mkdir foo && chmod 1777 foo'.
>
> The command "mkdir -m" calls the mkdir() syscall, and its second
> argument seems to be the mode.
>
> $ man 2 mkdir
> [...]
> int mkdir(const char *pathname, mode_t mode);
>
> Maybe I'm wrong, but this is what I call an atomic way to create and set
> permissions (ie. two operations in a unique syscall). For example:
>
> $ strace mkdir -m 222 /tmp/foo
> [...]
> mkdir("/tmp/foo", 0222) = 0
>
the second argument to mkdir obeys umask, so you end up doing
mkdir()
open()
fstat()
fchmod()
as far as I can tell.
> > hmm, how about this:
> >
> >mkdir -p /tmp/.X11-unix
> >chown -h root:root /tmp/.X11-unix
> >stat=$(LC_ALL=C stat -c '%u %g %F' /tmp/.X11-unix)
> >if [ "$stat" != '0 0 directory' ]; then
> > exit 1
> >fi
> >chmod 1777 /tmp/.X11-unix
>
> This would work (even if it uses chmod), but wasn't the Bash approach (test
> with "-O", "-G" and "-d") simpler than using "stat"?
>
test -d follows symlinks...
the problem with stat(1) is it's on /usr so I'd have to make this script
depend on $remote_fs. Which shouldn't be a problem, but is still a bit
annoying.
Cheers,
Julien
Attachment:
signature.asc
Description: Digital signature