MCPcopy Create free account
hub / github.com/containerd/nerdctl / appNeedsRootlessParentMain

Function appNeedsRootlessParentMain

cmd/nerdctl/main_linux.go:28–68  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

26)
27
28func appNeedsRootlessParentMain(cmd *cobra.Command, args []string) bool {
29 commands := []string{}
30 for tcmd := cmd; tcmd != nil; tcmd = tcmd.Parent() {
31 commands = append(commands, tcmd.Name())
32 }
33 commands = strutil.ReverseStrSlice(commands)
34
35 if !rootlessutil.IsRootlessParent() {
36 return false
37 }
38 if len(args) == 0 && cmd.HasSubCommands() {
39 return false
40 }
41 if len(commands) < 2 {
42 return true
43 }
44 switch commands[1] {
45 // completion, login, logout, version: false, because it shouldn't require the daemon to be running
46 // apparmor: false, because it requires the initial mount namespace to access /sys/kernel/security
47 // cp, compose cp: false, because it requires the initial mount namespace to inspect file owners
48 case "", "completion", "login", "logout", "apparmor", "cp", "version":
49 return false
50 case "container":
51 if len(commands) < 3 {
52 return true
53 }
54 switch commands[2] {
55 case "cp":
56 return false
57 }
58 case "compose":
59 if len(commands) < 3 {
60 return true
61 }
62 switch commands[2] {
63 case "cp":
64 return false
65 }
66 }
67 return true
68}
69
70func addApparmorCommand(rootCmd *cobra.Command) {
71 rootCmd.AddCommand(apparmor.Command())

Callers 2

newAppFunction · 0.70

Calls 3

ReverseStrSliceFunction · 0.92
IsRootlessParentFunction · 0.92
NameMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…