udevadm: introduce new 'wait' command

Prompted by https://github.com/systemd/systemd/pull/22717#issuecomment-1067348496.

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
This commit is contained in:
Yu Watanabe
2022-04-01 15:13:18 +09:00
parent 209294ad24
commit aa2b0d8d29
7 changed files with 495 additions and 18 deletions
+22 -2
View File
@@ -32,7 +32,7 @@ __get_all_sysdevs() {
__get_all_devs() {
local i
for i in /dev/* /dev/*/*; do
for i in /dev/* /dev/*/* /dev/*/*/*; do
echo $i
done
}
@@ -64,9 +64,10 @@ _udevadm() {
[MONITOR_ARG]='-s --subsystem-match -t --tag-match'
[TEST]='-a --action -N --resolve-names'
[TEST_BUILTIN]='-a --action'
[WAIT]='-t --timeout --initialized=no --removed --settle'
)
local verbs=(info trigger settle control monitor test-builtin test)
local verbs=(info trigger settle control monitor test-builtin test wait)
local builtins=(blkid btrfs hwdb input_id keyboard kmod net_id net_setup_link path_id usb_id uaccess)
for ((i=0; i < COMP_CWORD; i++)); do
@@ -245,6 +246,25 @@ _udevadm() {
fi
;;
'wait')
if __contains_word "$prev" ${OPTS[WAIT]}; then
case $prev in
*)
comps=''
;;
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
fi
if [[ $cur = -* ]]; then
comps="${OPTS[COMMON]} ${OPTS[WAIT]}"
else
comps=$( __get_all_devs )
local IFS=$'\n'
fi
;;
*)
comps=${VERBS[*]}
;;
+11
View File
@@ -104,6 +104,17 @@ _udevadm_test-builtin(){
fi
}
(( $+functions[_udevadm_wait] )) ||
_udevadm_wait(){
_arguments \
'--timeout=[Maximum number of seconds to wait for the devices being created.]' \
'--initialized=[Wait for devices being initialized by systemd-udevd.]:boolean:(yes no)' \
'--removed[Wait for devices being removed.]' \
'--settle[Also wait for udev queue being empty.]' \
'--help[Print help text.]' \
'*::devpath:_files -P /dev/ -W /dev'
}
(( $+functions[_udevadm_mounts] )) ||
_udevadm_mounts(){
local dev_tmp dpath_tmp mp_tmp mline