]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-util: introduce reset_cached_udev_availability()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 17 Jan 2024 05:09:05 +0000 (14:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 19 Jan 2024 06:06:08 +0000 (15:06 +0900)
src/shared/udev-util.c
src/shared/udev-util.h

index 7a86289d166df9ca0a33b2d24eb33e4d6564b42b..4f4b675a37b9fa3a41f818aa81d2256fc6f79fe2 100644 (file)
@@ -14,6 +14,7 @@
 #include "id128-util.h"
 #include "log.h"
 #include "macro.h"
+#include "missing_threads.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "signal-util.h"
@@ -363,18 +364,22 @@ int udev_queue_is_empty(void) {
                 (errno == ENOENT ? true : -errno) : false;
 }
 
-bool udev_available(void) {
-        static int cache = -1;
+static int cached_udev_availability = -1;
+
+void reset_cached_udev_availability(void) {
+        cached_udev_availability = -1;
+}
 
+bool udev_available(void) {
         /* The service systemd-udevd is started only when /sys is read write.
          * See systemd-udevd.service: ConditionPathIsReadWrite=/sys
          * Also, our container interface (http://systemd.io/CONTAINER_INTERFACE/) states that /sys must
          * be mounted in read-only mode in containers. */
 
-        if (cache >= 0)
-                return cache;
+        if (cached_udev_availability >= 0)
+                return cached_udev_availability;
 
-        return (cache = (path_is_read_only_fs("/sys/") <= 0));
+        return (cached_udev_availability = (path_is_read_only_fs("/sys/") <= 0));
 }
 
 int device_get_vendor_string(sd_device *device, const char **ret) {
index 5f49e87116179db7989374a1fec74491de4adc3f..4d27bed1d948f26ca0de104a6a2bb7546b6f027c 100644 (file)
@@ -23,6 +23,7 @@ size_t udev_replace_chars(char *str, const char *allow);
 
 int udev_queue_is_empty(void);
 
+void reset_cached_udev_availability(void);
 bool udev_available(void);
 
 int device_get_vendor_string(sd_device *device, const char **ret);