mirror of
https://github.com/systemd/systemd.git
synced 2025-02-21 05:57:34 +03: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]))
|
if (!isempty(c->data[PROP_CHASSIS]))
|
||||||
return strdup(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;
|
return dmi;
|
||||||
|
|
||||||
fallback = fallback_chassis();
|
fallback = fallback_chassis();
|
||||||
|
@ -44,9 +44,55 @@ test_hostname() {
|
|||||||
fi
|
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
|
: >/failed
|
||||||
|
|
||||||
test_hostname
|
test_hostname
|
||||||
|
test_chassis
|
||||||
|
|
||||||
touch /testok
|
touch /testok
|
||||||
rm /failed
|
rm /failed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user