github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/utils.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/Sirupsen/logrus" 8 "github.com/opencontainers/runtime-spec/specs-go" 9 "github.com/urfave/cli" 10 ) 11 12 // fatal prints the error's details if it is a libcontainer specific error type 13 // then exits the program with an exit status of 1. 14 func fatal(err error) { 15 // make sure the error is written to the logger 16 logrus.Error(err) 17 fmt.Fprintln(os.Stderr, err) 18 os.Exit(1) 19 } 20 21 // setupSpec performs initial setup based on the cli.Context for the container 22 func setupSpec(context *cli.Context) (*specs.Spec, error) { 23 bundle := context.String("bundle") 24 if bundle != "" { 25 if err := os.Chdir(bundle); err != nil { 26 return nil, err 27 } 28 } 29 spec, err := loadSpec(specConfig) 30 if err != nil { 31 return nil, err 32 } 33 notifySocket := os.Getenv("NOTIFY_SOCKET") 34 if notifySocket != "" { 35 setupSdNotify(spec, notifySocket) 36 } 37 if os.Geteuid() != 0 { 38 return nil, fmt.Errorf("runc should be run as root") 39 } 40 return spec, nil 41 }