]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: add bool mount_new_api_supported() helper
authorLuca Boccassi <bluca@debian.org>
Thu, 28 Sep 2023 12:19:45 +0000 (13:19 +0100)
committerLuca Boccassi <bluca@debian.org>
Mon, 2 Oct 2023 13:02:32 +0000 (14:02 +0100)
src/basic/mountpoint-util.c
src/basic/mountpoint-util.h

index 5af0896ad69053a08eb5e7895757b46b60250d67..6a07f1da2cf6d3dc9a9bb1b954ee3817793b932a 100644 (file)
@@ -674,6 +674,21 @@ bool mount_propagation_flag_is_valid(unsigned long flag) {
         return IN_SET(flag, 0, MS_SHARED, MS_PRIVATE, MS_SLAVE);
 }
 
+bool mount_new_api_supported(void) {
+        static int cache = -1;
+        int r;
+
+        if (cache >= 0)
+                return cache;
+
+        /* This is the newer API among the ones we use, so use it as boundary */
+        r = RET_NERRNO(mount_setattr(-EBADF, NULL, 0, NULL, 0));
+        if (r == 0 || ERRNO_IS_NOT_SUPPORTED(r)) /* This should return an error if it is working properly */
+                return (cache = false);
+
+        return (cache = true);
+}
+
 unsigned long ms_nosymfollow_supported(void) {
         _cleanup_close_ int fsfd = -EBADF, mntfd = -EBADF;
         static int cache = -1;
@@ -683,6 +698,9 @@ unsigned long ms_nosymfollow_supported(void) {
         if (cache >= 0)
                 return cache ? MS_NOSYMFOLLOW : 0;
 
+        if (!mount_new_api_supported())
+                goto not_supported;
+
         /* Checks if MS_NOSYMFOLLOW is supported (which was added in 5.10). We use the new mount API's
          * mount_setattr() call for that, which was added in 5.12, which is close enough. */
 
index 846015c43c71a52c9d5d05cfda4089644068be2f..499403a4d89494530b4ef591d110d1553adb3c65 100644 (file)
@@ -65,6 +65,7 @@ const char *mount_propagation_flag_to_string(unsigned long flags);
 int mount_propagation_flag_from_string(const char *name, unsigned long *ret);
 bool mount_propagation_flag_is_valid(unsigned long flag);
 
+bool mount_new_api_supported(void);
 unsigned long ms_nosymfollow_supported(void);
 
 int mount_option_supported(const char *fstype, const char *key, const char *value);