summaryrefslogtreecommitdiff
path: root/src/binfmt
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-12-10 11:42:50 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-12-15 03:36:27 +0900
commit94ba5b15329d9d19277ca418bfd0266da98f7b2a (patch)
tree7519b1d3970afd0b0badfb8343435151630b0037 /src/binfmt
parent5aaa79ce96997825b4dcdcf5be10d8f955fb3339 (diff)
downloadsystemd-94ba5b15329d9d19277ca418bfd0266da98f7b2a.tar.gz
binfmt: check if binfmt is mounted before applying rules
Diffstat (limited to 'src/binfmt')
-rw-r--r--src/binfmt/binfmt.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index ba209a8d47..624c63ec98 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -190,6 +190,18 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
+static int binfmt_mounted_warn(void) {
+ int r;
+
+ r = binfmt_mounted();
+ if (r < 0)
+ return log_error_errno(r, "Failed to check if /proc/sys/fs/binfmt_misc is mounted: %m");
+ if (r == 0)
+ log_debug("/proc/sys/fs/binfmt_misc is not mounted in read-write mode, skipping.");
+
+ return r;
+}
+
static int run(int argc, char *argv[]) {
int r, k;
@@ -206,13 +218,17 @@ static int run(int argc, char *argv[]) {
if (arg_unregister)
return disable_binfmt();
- if (argc > optind)
+ if (argc > optind) {
+ r = binfmt_mounted_warn();
+ if (r <= 0)
+ return r;
+
for (int i = optind; i < argc; i++) {
k = apply_file(argv[i], false);
if (k < 0 && r >= 0)
r = k;
}
- else {
+ } else {
_cleanup_strv_free_ char **files = NULL;
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("binfmt.d"));
@@ -225,6 +241,10 @@ static int run(int argc, char *argv[]) {
return cat_files(NULL, files, 0);
}
+ r = binfmt_mounted_warn();
+ if (r <= 0)
+ return r;
+
/* Flush out all rules */
r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)