diff options
author | Janne Heß <janne@hess.ooo> | 2023-09-29 19:46:10 +0200 |
---|---|---|
committer | Janne Heß <janne@hess.ooo> | 2023-09-29 19:46:10 +0200 |
commit | 5d7723dd5ba1ee02595f03554acc139b627b3834 (patch) | |
tree | b5b7ede3c52a80e4e7f4eb39a07e2b25ac944618 | |
parent | 3397af26c4f2c70a51343ce622bfa3e26be5ed7e (diff) | |
download | nixpkgs-5d7723dd5ba1ee02595f03554acc139b627b3834.tar nixpkgs-5d7723dd5ba1ee02595f03554acc139b627b3834.tar.gz nixpkgs-5d7723dd5ba1ee02595f03554acc139b627b3834.tar.bz2 nixpkgs-5d7723dd5ba1ee02595f03554acc139b627b3834.tar.lz nixpkgs-5d7723dd5ba1ee02595f03554acc139b627b3834.tar.xz nixpkgs-5d7723dd5ba1ee02595f03554acc139b627b3834.tar.zst nixpkgs-5d7723dd5ba1ee02595f03554acc139b627b3834.zip |
nixos/switch-to-configuration: Lock the switch
This prevents any concurrent switches from happening which is not an issue I have seen people complaining about but it seems like a good measure.
-rwxr-xr-x | nixos/modules/system/activation/switch-to-configuration.pl | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index e05f89bb0fb..31b24f85528 100755 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -22,6 +22,7 @@ use JSON::PP; use IPC::Cmd; use Sys::Syslog qw(:standard :macros); use Cwd qw(abs_path); +use Fcntl ':flock'; ## no critic(ControlStructures::ProhibitDeepNests) ## no critic(ErrorHandling::RequireCarping) @@ -91,6 +92,8 @@ if (!-f "/etc/NIXOS" && (read_file("/etc/os-release", err_mode => "quiet") // "" } make_path("/run/nixos", { mode => oct(755) }); +open(my $stc_lock, '>>', '/run/nixos/switch-to-configuration.lock') or die "Could not open lock - $!"; +flock($stc_lock, LOCK_EX) or die "Could not acquire lock - $!"; openlog("nixos", "", LOG_USER); # Install or update the bootloader. @@ -983,4 +986,5 @@ if ($res == 0) { syslog(LOG_ERR, "switching to system configuration $toplevel failed (status $res)"); } +close($stc_lock) or die "Could not close lock - $!"; exit($res); |