]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: add missing assertions, make mount_fd static
authorMike Yuan <me@yhndnzj.com>
Sat, 20 Apr 2024 19:02:38 +0000 (03:02 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 16:48:51 +0000 (00:48 +0800)
src/basic/mountpoint-util.c
src/basic/mountpoint-util.h

index 66fa35b63090cb6c074c5dca826951d0f3e8c233..03e56f6cabdbfad6e90796b4e1d076241b584e5c 100644 (file)
@@ -596,11 +596,14 @@ int dev_is_devtmpfs(void) {
         return false;
 }
 
-int mount_fd(const char *source,
-             int target_fd,
-             const char *filesystemtype,
-             unsigned long mountflags,
-             const void *data) {
+static int mount_fd(
+                const char *source,
+                int target_fd,
+                const char *filesystemtype,
+                unsigned long mountflags,
+                const void *data) {
+
+        assert(target_fd >= 0);
 
         if (mount(source, FORMAT_PROC_FD_PATH(target_fd), filesystemtype, mountflags, data) < 0) {
                 if (errno != ENOENT)
@@ -626,6 +629,8 @@ int mount_nofollow(
 
         _cleanup_close_ int fd = -EBADF;
 
+        assert(target);
+
         /* In almost all cases we want to manipulate the mount table without following symlinks, hence
          * mount_nofollow() is usually the way to go. The only exceptions are environments where /proc/ is
          * not available yet, since we need /proc/self/fd/ for this logic to work. i.e. during the early
index d7c6251aff78613e5156a28e50c4da7666751e61..e5f21780f8f07c60d2268cdad25dfb9bf0ecc577 100644 (file)
@@ -63,8 +63,12 @@ const char* fstype_norecovery_option(const char *fstype);
 
 int dev_is_devtmpfs(void);
 
-int mount_fd(const char *source, int target_fd, const char *filesystemtype, unsigned long mountflags, const void *data);
-int mount_nofollow(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data);
+int mount_nofollow(
+                const char *source,
+                const char *target,
+                const char *filesystemtype,
+                unsigned long mountflags,
+                const void *data);
 
 const char *mount_propagation_flag_to_string(unsigned long flags);
 int mount_propagation_flag_from_string(const char *name, unsigned long *ret);