]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libudev-monitor: rename udev_has_devtmpfs() and move it to mount-util.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 13 Aug 2018 08:59:44 +0000 (17:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 11 Sep 2018 03:45:21 +0000 (12:45 +0900)
As the function itself is quite generic.

src/basic/mount-util.c
src/basic/mount-util.h
src/libudev/libudev-monitor.c

index 1f9590ccb6a266f99140126c38336996cf1925b8..ae62d3090e7218bd0589366071abc238f92121bd 100644 (file)
@@ -951,3 +951,39 @@ int mount_option_mangle(
 
         return 0;
 }
+
+int dev_is_devtmpfs(void) {
+        _cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
+        char line[LINE_MAX], *e;
+        int mount_id, r;
+
+        r = path_get_mnt_id("/dev", &mount_id);
+        if (r < 0)
+                return r;
+
+        proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
+        if (!proc_self_mountinfo)
+                return -errno;
+
+        (void) __fsetlocking(proc_self_mountinfo, FSETLOCKING_BYCALLER);
+
+        FOREACH_LINE(line, proc_self_mountinfo, return -errno) {
+                int mid;
+
+                if (sscanf(line, "%i", &mid) != 1)
+                        continue;
+
+                if (mid != mount_id)
+                        continue;
+
+                e = strstr(line, " - ");
+                if (!e)
+                        continue;
+
+                /* accept any name that starts with the currently expected type */
+                if (startswith(e + 3, "devtmpfs"))
+                        return true;
+        }
+
+        return false;
+}
index 3cfea3bb20d1a0a9b786e7dfe65208f6be2322ac..ad8c47cb325f89b97ecbc3b08dbe31b557d2754b 100644 (file)
@@ -54,3 +54,5 @@ int mount_option_mangle(
                 unsigned long mount_flags,
                 unsigned long *ret_mount_flags,
                 char **ret_remaining_options);
+
+int dev_is_devtmpfs(void);
index f83115c95ce567e0d95456ac58c4c5a549ab130a..5ca035d43ccac64353f00fc69e51c2fc0bc604fe 100644 (file)
@@ -94,46 +94,6 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev) {
         return udev_monitor;
 }
 
-/* we consider udev running when /dev is on devtmpfs */
-static bool udev_has_devtmpfs(struct udev *udev) {
-
-        _cleanup_fclose_ FILE *f = NULL;
-        char line[LINE_MAX], *e;
-        int mount_id, r;
-
-        r = path_get_mnt_id("/dev", &mount_id);
-        if (r < 0) {
-                if (r != -EOPNOTSUPP)
-                        log_debug_errno(r, "name_to_handle_at on /dev: %m");
-
-                return false;
-        }
-
-        f = fopen("/proc/self/mountinfo", "re");
-        if (!f)
-                return false;
-
-        FOREACH_LINE(line, f, return false) {
-                int mid;
-
-                if (sscanf(line, "%i", &mid) != 1)
-                        continue;
-
-                if (mid != mount_id)
-                        continue;
-
-                e = strstr(line, " - ");
-                if (!e)
-                        continue;
-
-                /* accept any name that starts with the currently expected type */
-                if (startswith(e + 3, "devtmpfs"))
-                        return true;
-        }
-
-        return false;
-}
-
 static void monitor_set_nl_address(struct udev_monitor *udev_monitor) {
         union sockaddr_union snl;
         socklen_t addrlen;
@@ -169,7 +129,7 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c
                  * We do not set a netlink multicast group here, so the socket
                  * will not receive any messages.
                  */
-                if (access("/run/udev/control", F_OK) < 0 && !udev_has_devtmpfs(udev)) {
+                if (access("/run/udev/control", F_OK) < 0 && dev_is_devtmpfs() <= 0) {
                         log_debug("the udev service seems not to be active, disable the monitor");
                         group = UDEV_MONITOR_NONE;
                 } else