Merge pull request #258071 from helsinki-systems/feat/stc-lock

nixos/switch-to-configuration: Lock the switch

Changed files
+4
nixos
modules
system
+4
nixos/modules/system/activation/switch-to-configuration.pl
···
use IPC::Cmd;
use Sys::Syslog qw(:standard :macros);
use Cwd qw(abs_path);
## no critic(ControlStructures::ProhibitDeepNests)
## no critic(ErrorHandling::RequireCarping)
···
}
make_path("/run/nixos", { mode => oct(755) });
openlog("nixos", "", LOG_USER);
# Install or update the bootloader.
···
syslog(LOG_ERR, "switching to system configuration $toplevel failed (status $res)");
}
exit($res);
···
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)
···
}
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.
···
syslog(LOG_ERR, "switching to system configuration $toplevel failed (status $res)");
}
+
close($stc_lock) or die "Could not close lock - $!";
exit($res);