From c809c046be509226d0cad44a47ae78f6a428d500 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 17 Feb 2022 18:47:26 +0900 Subject: [PATCH] udev-util: introduce udev_available() helper function (cherry picked from commit f92c5bb18cee41d48b95d61a2a2dc613203844ca) --- src/shared/udev-util.c | 15 +++++++++++++++ src/shared/udev-util.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 56c28773ce..69c3255967 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -19,6 +19,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" @@ -718,3 +719,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); +} diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h index 8d21dc4364..a48beb95ea 100644 --- a/src/shared/udev-util.h +++ b/src/shared/udev-util.h @@ -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 -- 2.25.1