From: Yu Watanabe Date: Thu, 17 Feb 2022 09:47:26 +0000 (+0900) Subject: udev-util: introduce udev_available() helper function X-Git-Tag: v251-rc1~269^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f92c5bb18cee41d48b95d61a2a2dc613203844ca;p=thirdparty%2Fsystemd.git udev-util: introduce udev_available() helper function --- diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index e2574b9af39..2f21ee6dbee 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -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); +} diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h index 8d21dc43647..a48beb95ea4 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