Improve WSL systemd detection (#469)

* Improve WSL systemd detection

* Make systemd missing in wsl an expected error

* fmt

* Use && instead

* Make it more verbose
This commit is contained in:
Ana Hobden 2023-05-19 07:49:43 -07:00 committed by GitHub
parent eb41cc9205
commit 2673a9b299
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -93,8 +93,11 @@ impl ConfigureInitService {
InitSystem::Systemd => {
// If /run/systemd/system exists, we can be reasonably sure the machine is booted
// with systemd: https://www.freedesktop.org/software/systemd/man/sd_booted.html
if !(Path::new("/run/systemd/system").exists() || which::which("systemctl").is_ok())
{
if !Path::new("/run/systemd/system").exists() {
return Err(Self::error(ActionErrorKind::SystemdMissing));
}
if which::which("systemctl").is_err() {
return Err(Self::error(ActionErrorKind::SystemdMissing));
}

View file

@ -568,6 +568,7 @@ impl HasExpectedErrors for ActionErrorKind {
Self::PathUserMismatch(_, _, _)
| Self::PathGroupMismatch(_, _, _)
| Self::PathModeMismatch(_, _, _) => Some(Box::new(self)),
Self::SystemdMissing => Some(Box::new(self)),
_ => None,
}
}