This fixes a few unrelated issues:
- when ENABLE_MACHINED is false, machinectl is not installed, but _sd_machines
is still used in a few places that want to complete -M and such.
Also, bash completion calls machinectl in various places.
Make missing machinectl mean "no machines" in this case, so
that no error is generated in the callers.
- machinectl list --full would print multiple lines of output per machine,
breaking grep, issue introduced in
e2268fa43742ece4a5cdc2e93f731b2bb2fcc883.
Using --max-addresses=1 would fix the issue, but let's use
--max-addresses=0 because we now can.
- the lists used in various places were slightly different for no good reason.
- don't use a subshell if not necessary.
The code for bash still uses the same combined list of images and running
machines for various commands. The zsh code uses images for start/clone, and
running machines for the rest. Maybe something to fix in the future.
Replaces #25048.
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager 2>/dev/null |
- { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
__get_busnames() {
__get_machines() {
local a b
- (machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
- { while read a b; do echo " $a"; done; } | sort -u;
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
__syslog_priorities=(emerg alert crit err warning notice info debug)
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager 2>/dev/null |
- { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
_loginctl () {
__get_machines() {
local a b
- (machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; echo ".host") | \
- { while read a b; do echo " $a"; done; } | sort -u;
+ { machinectl list-images --full --no-legend --no-pager 2>/dev/null; machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
_machinectl() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager 2>/dev/null |
- { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
_portablectl() {
__get_machines() {
local a b
- { machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; } | \
- { while read a b; do echo " $a"; done; }
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
_systemctl () {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
__get_units_all() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
__get_units_have_cgroup() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
_systemd_cgtop() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
__get_env() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
_systemd_run() {
__get_machines() {
local a b
- machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo " $a"; done; } | \
+ sort -u
}
__get_interfaces(){
(( $+functions[__sd_machines_get_machines] )) ||
__sd_machines_get_machines () {
- machinectl --full --no-legend --no-pager list | {while read -r a b; do echo $a; done;};
+
+ { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
+ { while read a b; do echo "$a"; done; } | \
+ sort -u
}
local -a _machines