github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/configs/namespaces_syscall.go (about)

     1  // +build linux
     2  
     3  package configs
     4  
     5  import "syscall"
     6  
     7  func (n *Namespace) Syscall() int {
     8  	return namespaceInfo[n.Type]
     9  }
    10  
    11  var namespaceInfo = map[NamespaceType]int{
    12  	NEWNET:  syscall.CLONE_NEWNET,
    13  	NEWNS:   syscall.CLONE_NEWNS,
    14  	NEWUSER: syscall.CLONE_NEWUSER,
    15  	NEWIPC:  syscall.CLONE_NEWIPC,
    16  	NEWUTS:  syscall.CLONE_NEWUTS,
    17  	NEWPID:  syscall.CLONE_NEWPID,
    18  }
    19  
    20  // CloneFlags parses the container's Namespaces options to set the correct
    21  // flags on clone, unshare. This function returns flags only for new namespaces.
    22  func (n *Namespaces) CloneFlags() uintptr {
    23  	var flag int
    24  	for _, v := range *n {
    25  		if v.Path != "" {
    26  			continue
    27  		}
    28  		flag |= namespaceInfo[v.Type]
    29  	}
    30  	return uintptr(flag)
    31  }