From: Luca Boccassi Date: Thu, 28 Sep 2023 12:19:45 +0000 (+0100) Subject: mountpoint-util: add bool mount_new_api_supported() helper X-Git-Tag: v255-rc1~360^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f273c09c5138d73697a5d8c6e6dc6974a43ae4a7;p=thirdparty%2Fsystemd.git mountpoint-util: add bool mount_new_api_supported() helper --- diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index 5af0896ad69..6a07f1da2cf 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -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. */ diff --git a/src/basic/mountpoint-util.h b/src/basic/mountpoint-util.h index 846015c43c7..499403a4d89 100644 --- a/src/basic/mountpoint-util.h +++ b/src/basic/mountpoint-util.h @@ -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);