Don't require mount point for a non-directory to be a regular file
Previously, mounting a socket over the top of an existing socket would fail, because create_file() opens it with creat(): $ test -e /run/systemd/resolve/io.systemd.Resolve && echo exists exists $ bwrap \ --bind / / \ --bind /run/systemd/resolve/io.systemd.Resolve \ /run/systemd/resolve/io.systemd.Resolve \ /bin/true bwrap: Can't create file at /run/systemd/resolve/io.systemd.Resolve: No such device or address Tolerate the file existing as any type that we will be able to mount a non-directory onto. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
9
utils.c
9
utils.c
@@ -448,9 +448,14 @@ ensure_file (const char *path,
|
||||
|
||||
/* We check this ahead of time, otherwise
|
||||
the create file will fail in the read-only
|
||||
case with EROFS instead of EEXIST */
|
||||
case with EROFS instead of EEXIST.
|
||||
|
||||
We're trying to set up a mount point for a non-directory, so any
|
||||
non-directory, non-symlink is acceptable - it doesn't necessarily
|
||||
have to be a regular file. */
|
||||
if (stat (path, &buf) == 0 &&
|
||||
S_ISREG (buf.st_mode))
|
||||
!S_ISDIR (buf.st_mode) &&
|
||||
!S_ISLNK (buf.st_mode))
|
||||
return 0;
|
||||
|
||||
if (create_file (path, mode, NULL) != 0 && errno != EEXIST)
|
||||
|
Reference in New Issue
Block a user