[systemd-devel] [PATCH] install: create_symlink() check unlink() return value

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Apr 16 20:15:04 PDT 2014


On Thu, Apr 17, 2014 at 01:47:11AM +0100, Djalal Harouni wrote:
> create_symlink() do not check the return value of unlink(), this may
> confuse the user.
> 
> Before the unlink() call we check the 'force' argument. If it is not set
> we fail with -EEXIST, otherwise we unlink() the file, therefore the next
> symlink() should not fail with -EEXIST (do not count races...).
> 
> However since callers may not have appropriate privileges to unlink()
> the file we lose the -EPERM or any other errno code of unlink(), and
> return the -EEXIST of the next symlink(). Fix this by checking unlink()
> results.
> 
> Before:
> $ systemctl --force --root=~/container-03 set-default multi-user.target
> Failed to set default target: File exists
> 
> After:
> $ systemctl --force --root=~/container-03 set-default multi-user.target
> Failed to set default target: Permission denied
Applied.

Zbyszek


More information about the systemd-devel mailing list