mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 13:40:28 +03:00
nixos-container run: Execute command using ‘su’
This ensures that the environment is set up correctly.
This commit is contained in:
parent
6773babd5b
commit
21ab4e054c
1 changed files with 5 additions and 4 deletions
|
@ -197,8 +197,7 @@ sub getLeader {
|
|||
sub runInContainer {
|
||||
my @args = @_;
|
||||
my $leader = getLeader;
|
||||
# FIXME: initialise the environment properly.
|
||||
exec($nsenter, "-t", $leader, "-m", "-u", "-i", "-n", "-p", "--", "env", "-i", "--", @args);
|
||||
exec($nsenter, "-t", $leader, "-m", "-u", "-i", "-n", "-p", "--", @args);
|
||||
die "cannot run ‘nsenter’: $!\n";
|
||||
}
|
||||
|
||||
|
@ -251,12 +250,14 @@ elsif ($action eq "login") {
|
|||
}
|
||||
|
||||
elsif ($action eq "root-login") {
|
||||
runInContainer("bash", "--login");
|
||||
runInContainer("su", "root", "-l");
|
||||
}
|
||||
|
||||
elsif ($action eq "run") {
|
||||
shift @ARGV; shift @ARGV;
|
||||
runInContainer(@ARGV);
|
||||
# Escape command.
|
||||
my $s = join(' ', map { s/'/'\\''/g; "'$_'" } @ARGV);
|
||||
runInContainer("su", "root", "-l", "-c", "exec " . $s);
|
||||
}
|
||||
|
||||
elsif ($action eq "show-ip") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue