diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-02-17 10:47:26 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-02-17 10:51:57 +0100 |
commit | f92c5bb18cee41d48b95d61a2a2dc613203844ca (patch) | |
tree | 48957e35ca3fb4b1653204d707cae55153538f50 /src/shared/udev-util.c | |
parent | Merge pull request #22535 from poettering/dbusctl-range-display (diff) | |
download | systemd-f92c5bb18cee41d48b95d61a2a2dc613203844ca.tar.xz systemd-f92c5bb18cee41d48b95d61a2a2dc613203844ca.zip |
udev-util: introduce udev_available() helper function
Diffstat (limited to 'src/shared/udev-util.c')
-rw-r--r-- | src/shared/udev-util.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index e2574b9af3..2f21ee6dbe 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); +} |