]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-util: introduce udev_available() helper function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 17 Feb 2022 09:47:26 +0000 (18:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 17 Feb 2022 09:51:57 +0000 (18:51 +0900)
src/shared/udev-util.c
src/shared/udev-util.h

index e2574b9af39f4c2d929b5b714ce263023cae36f6..2f21ee6dbee9d71e0be6b25f8c157231f6b8a623 100644 (file)
@@ -20,6 +20,7 @@
 #include "path-util.h"
 #include "signal-util.h"
 #include "socket-util.h"
+#include "stat-util.h"
 #include "string-table.h"
 #include "string-util.h"
 #include "strxcpyx.h"
@@ -723,3 +724,17 @@ int on_ac_power(void) {
 
         return found_online || !found_offline;
 }
+
+bool udev_available(void) {
+        static int cache = -1;
+
+        /* 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;
+
+        return (cache = path_is_read_only_fs("/sys/") <= 0);
+}
index 8d21dc43647b3fd80e60dc3e2f6c2249ed587395..a48beb95ea448217faade638fc8fa651c6c4743b 100644 (file)
@@ -55,6 +55,8 @@ int udev_queue_init(void);
 
 int on_ac_power(void);
 
+bool udev_available(void);
+
 #if HAVE_SYS_SDT_H
 
 /* Each trace point can have different number of additional arguments. Note that when the macro is used only