Commit 09227be2 by Michael H. Warfield Committed by Serge Hallyn

Check for symlinks before attempting create.

Check for symlinks before attempting create. When attempting to create the compulsory symlinks in /dev, check for the existence of the link using stat first before blindly attempting to create the link. This works around an apparent quirk in the kernel VFS on read-only file systems where the returned error code might be EEXIST or EROFS depending on previous access to the /dev directory and its entries. Reported-by: 's avatarWilliam Dauchy <william@gandi.net> Signed-off-by: 's avatarMichael H. Warfield <mhw@WittsEnd.com> Tested-by: 's avatarWilliam Dauchy <william@gandi.net>
parent 276a0862
...@@ -828,6 +828,7 @@ static int setup_dev_symlinks(const struct lxc_rootfs *rootfs) ...@@ -828,6 +828,7 @@ static int setup_dev_symlinks(const struct lxc_rootfs *rootfs)
{ {
char path[MAXPATHLEN]; char path[MAXPATHLEN];
int ret,i; int ret,i;
struct stat s;
for (i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) { for (i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) {
...@@ -835,12 +836,26 @@ static int setup_dev_symlinks(const struct lxc_rootfs *rootfs) ...@@ -835,12 +836,26 @@ static int setup_dev_symlinks(const struct lxc_rootfs *rootfs)
ret = snprintf(path, sizeof(path), "%s/dev/%s", rootfs->mount, d->name); ret = snprintf(path, sizeof(path), "%s/dev/%s", rootfs->mount, d->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= MAXPATHLEN)
return -1; return -1;
/*
* Stat the path first. If we don't get an error
* accept it as is and don't try to create it
*/
if (!stat(path, &s)) {
continue;
}
ret = symlink(d->oldpath, path); ret = symlink(d->oldpath, path);
if (ret && errno != EEXIST) { if (ret && errno != EEXIST) {
if ( errno == EROFS ) {
WARN("Warning: Read Only file system while creating %s", path);
} else {
SYSERROR("Error creating %s", path); SYSERROR("Error creating %s", path);
return -1; return -1;
} }
} }
}
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment