]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
binfmt: check if binfmt is mounted before applying rules
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 Dec 2022 02:42:50 +0000 (11:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 14 Dec 2022 18:36:27 +0000 (03:36 +0900)
src/binfmt/binfmt.c
src/shared/binfmt-util.c
src/shared/binfmt-util.h

index ba209a8d470a43e3903805edc99a375da73cae8a..624c63ec98b33f8db92b64138b0b6e1428f13de7 100644 (file)
@@ -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)
index 51fc245c0190a5b81c392c19b1ce33d207eec636..a26175474b369932675c796b16e842f24e973874 100644 (file)
@@ -12,7 +12,7 @@
 #include "missing_magic.h"
 #include "stat-util.h"
 
-static int binfmt_mounted(void) {
+int binfmt_mounted(void) {
         _cleanup_close_ int fd = -EBADF;
         int r;
 
index 2f008d12ffe3d1aa18592a4ddcb0a5a7ac8e5fe8..13f4548b7ce8c4283502e61fd52d18ca74675284 100644 (file)
@@ -1,4 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+int binfmt_mounted(void);
 int disable_binfmt(void);