mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 18:23:32 +08:00
Merge pull request #24385 from yuwata/hostname-chassis
hostname: fix fallback chassis type
This commit is contained in:
commit
d4001c518a
@ -415,7 +415,7 @@ static char* context_get_chassis(Context *c) {
|
||||
if (!isempty(c->data[PROP_CHASSIS]))
|
||||
return strdup(c->data[PROP_CHASSIS]);
|
||||
|
||||
if (get_dmi_data("ID_CHASSIS", NULL, &dmi) >= 0)
|
||||
if (get_dmi_data("ID_CHASSIS", NULL, &dmi) > 0)
|
||||
return dmi;
|
||||
|
||||
fallback = fallback_chassis();
|
||||
|
@ -44,9 +44,55 @@ test_hostname() {
|
||||
fi
|
||||
}
|
||||
|
||||
restore_machine_info() {
|
||||
if [[ -e /tmp/machine-info.bak ]]; then
|
||||
mv /tmp/machine-info.bak /etc/machine-info
|
||||
else
|
||||
rm -f /etc/machine-info
|
||||
fi
|
||||
}
|
||||
|
||||
get_chassis() (
|
||||
# shellcheck source=/dev/null
|
||||
. /etc/machine-info
|
||||
|
||||
echo "$CHASSIS"
|
||||
)
|
||||
|
||||
test_chassis() {
|
||||
local i
|
||||
|
||||
if [[ -f /etc/machine-info ]]; then
|
||||
cp /etc/machine-info /tmp/machine-info.bak
|
||||
fi
|
||||
|
||||
trap restore_machine_info RETURN
|
||||
|
||||
# Invalid chassis type is refused
|
||||
assert_rc 1 hostnamectl chassis hoge
|
||||
|
||||
# Valid chassis types
|
||||
for i in vm container desktop laptop convertible server tablet handset watch embedded; do
|
||||
hostnamectl chassis "$i"
|
||||
assert_eq "$(hostnamectl chassis)" "$i"
|
||||
assert_eq "$(get_chassis)" "$i"
|
||||
done
|
||||
|
||||
systemctl stop systemd-hostnamed.service
|
||||
rm -f /etc/machine-info
|
||||
|
||||
# fallback chassis type
|
||||
if systemd-detect-virt --quiet --container; then
|
||||
assert_eq "$(hostnamectl chassis)" container
|
||||
elif systemd-detect-virt --quiet --vm; then
|
||||
assert_eq "$(hostnamectl chassis)" vm
|
||||
fi
|
||||
}
|
||||
|
||||
: >/failed
|
||||
|
||||
test_hostname
|
||||
test_chassis
|
||||
|
||||
touch /testok
|
||||
rm /failed
|
||||
|
Loading…
Reference in New Issue
Block a user