Extract as a function.
This commit is contained in:
parent
43a2af24ae
commit
743be9537c
1 changed files with 18 additions and 12 deletions
|
|
@ -178,21 +178,11 @@ fn verify_systemd_dir(ephemeral: bool) -> Result<()> {
|
|||
}
|
||||
|
||||
pub fn deactivate() -> Result<()> {
|
||||
restore_ephemeral_system_dir()?;
|
||||
|
||||
let old_services = read_saved_services()?;
|
||||
log::debug!("{:?}", old_services);
|
||||
|
||||
// If we turned the ephemeral systemd system dir under /run into a symlink,
|
||||
// then systemd crashes in a very difficult to understand way.
|
||||
// To avoid this, we always check if this directory exists and is correct,
|
||||
// and we recreate it if needed.
|
||||
let ephemeral_systemd_system_dir = systemd_system_dir(true);
|
||||
if !ephemeral_systemd_system_dir.exists() {
|
||||
if ephemeral_systemd_system_dir.is_symlink() {
|
||||
fs::remove_file(&ephemeral_systemd_system_dir)?;
|
||||
}
|
||||
fs::create_dir_all(&ephemeral_systemd_system_dir)?;
|
||||
}
|
||||
|
||||
let service_manager = systemd::ServiceManager::new_session()?;
|
||||
let job_monitor = service_manager.monitor_jobs_init()?;
|
||||
let timeout = Some(Duration::from_secs(30));
|
||||
|
|
@ -217,6 +207,22 @@ pub fn deactivate() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// If we turned the ephemeral systemd system dir under /run into a symlink,
|
||||
// then systemd crashes when that symlink goes broken.
|
||||
// To avoid this, we always check whether this directory exists and is correct,
|
||||
// and we recreate it if needed.
|
||||
// NOTE: We rely on the fact that the etc files get cleaned up first, before this runs!
|
||||
fn restore_ephemeral_system_dir() -> Result<()> {
|
||||
let ephemeral_systemd_system_dir = systemd_system_dir(true);
|
||||
if !ephemeral_systemd_system_dir.exists() {
|
||||
if ephemeral_systemd_system_dir.is_symlink() {
|
||||
fs::remove_file(&ephemeral_systemd_system_dir)?;
|
||||
}
|
||||
fs::create_dir_all(&ephemeral_systemd_system_dir)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// FIXME: we should probably lock this file to avoid concurrent writes
|
||||
fn serialise_saved_services(services: &Services) -> Result<()> {
|
||||
let state_file = Path::new(SYSTEM_MANAGER_STATE_DIR).join(SERVICES_STATE_FILE_NAME);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue