Introduce ERRNO_IS_FS_WRITE_REFUSED(), and use it in binfmt_mounted() (#38117)

- This introduces ERRNO_IS_FS_WRITE_REFUSED(), and apply it where
usable.
- This makes unexpected errors in access_fd() called by binfmt_mounted()
propagated to the caller.
- Renames binfmt_mounted() to binfmt_mounted_and_writable(), as it also
checks the fs is writable.
- Voidifies one disable_binfmt() call in shutdown.c.
This commit is contained in:
Lennart Poettering
2025-07-10 21:38:13 +02:00
committed by GitHub
16 changed files with 43 additions and 32 deletions
+9 -3
View File
@@ -11,7 +11,7 @@
#include "missing_magic.h"
#include "stat-util.h"
int binfmt_mounted(void) {
int binfmt_mounted_and_writable(void) {
_cleanup_close_ int fd = -EBADF;
int r;
@@ -25,7 +25,13 @@ int binfmt_mounted(void) {
if (r <= 0)
return r;
return access_fd(fd, W_OK) >= 0;
r = access_fd(fd, W_OK);
if (ERRNO_IS_NEG_FS_WRITE_REFUSED(r))
return false;
if (r < 0)
return r;
return true;
}
int disable_binfmt(void) {
@@ -37,7 +43,7 @@ int disable_binfmt(void) {
* We are a bit careful here, since binfmt_misc might still be an autofs which we don't want to
* trigger. */
r = binfmt_mounted();
r = binfmt_mounted_and_writable();
if (r < 0)
return log_warning_errno(r, "Failed to determine whether binfmt_misc is mounted: %m");
if (r == 0) {
+1 -1
View File
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
int binfmt_mounted(void);
int binfmt_mounted_and_writable(void);
int disable_binfmt(void);
+1 -1
View File
@@ -660,7 +660,7 @@ int loop_device_make_by_path_at(
r = fd;
/* Retry read-only? */
if (open_flags >= 0 || !(ERRNO_IS_PRIVILEGE(r) || r == -EROFS))
if (open_flags >= 0 || !ERRNO_IS_NEG_FS_WRITE_REFUSED(r))
return r;
fd = xopenat(dir_fd, path, basic_flags|direct_flags|O_RDONLY);