This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By default virtcontainer auto-detects if the current process is running rootless or not, but this behavior can change from commandline with the --rootless option fixes #2417 Signed-off-by: Julio Montes <[email protected]>
- Loading branch information
Julio Montes
committed
Feb 12, 2020
1 parent
11bd456
commit c36c667
Showing
4 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
// Copyright (c) 2019 Intel Corporation | ||
// Copyright (c) 2020 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package rootless | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/opencontainers/runc/libcontainer/system" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsRootless(t *testing.T) { | ||
assert := assert.New(t) | ||
isRootless = nil | ||
|
||
var rootless bool | ||
if os.Getuid() != 0 { | ||
rootless = true | ||
} else { | ||
rootless = system.RunningInUserNS() | ||
} | ||
|
||
assert.Equal(rootless, isRootlessFunc()) | ||
|
||
SetRootless(true) | ||
assert.True(isRootlessFunc()) | ||
|
||
SetRootless(false) | ||
assert.False(isRootlessFunc()) | ||
|
||
isRootless = nil | ||
} |