Skip to content

Commit

Permalink
shell-wrapper: wait for activation script to mitigate race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
nzbr committed Dec 10, 2024
1 parent 3602ce1 commit ff6efd3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions utils/src/shell_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use log::{error, info, warn, LevelFilter};
use nix::libc::{sigaction, PT_NULL, SIGCHLD, SIG_IGN};
use std::mem::MaybeUninit;
use std::os::unix::process::CommandExt;
use std::path::Path;
use std::process::Command;
use std::thread;
use std::time::Duration;
use std::{env, fs::read_link};
use systemd_journal_logger::JournalLog;

Expand All @@ -17,6 +20,13 @@ fn real_main() -> anyhow::Result<()> {
// Therefore we dereference our symlink to get whatever it was originally.
let shell = read_link(exe_dir.join("shell")).context("when locating the wrapped shell")?;

if shell.starts_with("/run/current-system/sw/bin/") {
while !Path::new("/run/current-system/sw/bin").exists() {
warn!("Activation script has not finished! Waiting for /run/current-system/sw/bin to exist");
thread::sleep(Duration::from_secs(3));
}
}

// Set the SHELL environment variable to the wrapped shell instead of the wrapper
let shell_env = env::var_os("SHELL");
if shell_env == Some(exe.into()) {
Expand Down

0 comments on commit ff6efd3

Please sign in to comment.