1*2810ac1bSKiyoung Kim// +build go1.10 2*2810ac1bSKiyoung Kim 3*2810ac1bSKiyoung Kimpackage cap 4*2810ac1bSKiyoung Kim 5*2810ac1bSKiyoung Kimimport "syscall" 6*2810ac1bSKiyoung Kim 7*2810ac1bSKiyoung Kim// LaunchSupported indicates that is safe to return from a locked 8*2810ac1bSKiyoung Kim// OS Thread and have that OS Thread be terminated by the runtime. The 9*2810ac1bSKiyoung Kim// Launch functionality really needs to rely on the fact that an 10*2810ac1bSKiyoung Kim// excess of runtime.LockOSThread() vs. runtime.UnlockOSThread() calls 11*2810ac1bSKiyoung Kim// in a returning go routine will cause the underlying locked OSThread 12*2810ac1bSKiyoung Kim// to terminate. That feature was added to the Go runtime in version 13*2810ac1bSKiyoung Kim// 1.10. 14*2810ac1bSKiyoung Kim// 15*2810ac1bSKiyoung Kim// See these bugs for the discussion and feature assumed by the code 16*2810ac1bSKiyoung Kim// in this Launch() functionality: 17*2810ac1bSKiyoung Kim// 18*2810ac1bSKiyoung Kim// https://github.com/golang/go/issues/20395 19*2810ac1bSKiyoung Kim// https://github.com/golang/go/issues/20458 20*2810ac1bSKiyoung Kim// 21*2810ac1bSKiyoung Kim// A value of false for this constant causes the Launch functionality 22*2810ac1bSKiyoung Kim// to fail with an error: cap.ErrNoLaunch. If this value is false you 23*2810ac1bSKiyoung Kim// have two choices with respect to the Launch functionality: 24*2810ac1bSKiyoung Kim// 25*2810ac1bSKiyoung Kim// 1) don't use cap.(*Launcher).Launch() 26*2810ac1bSKiyoung Kim// 2) upgrade your Go toolchain to 1.10+ (ie., do this one). 27*2810ac1bSKiyoung Kimconst LaunchSupported = true 28*2810ac1bSKiyoung Kim 29*2810ac1bSKiyoung Kim// validatePA confirms that the pa.Sys entry is not incompatible with 30*2810ac1bSKiyoung Kim// Launch and loads up the chroot value. 31*2810ac1bSKiyoung Kimfunc validatePA(pa *syscall.ProcAttr, chroot string) (bool, error) { 32*2810ac1bSKiyoung Kim s := pa.Sys 33*2810ac1bSKiyoung Kim if s == nil { 34*2810ac1bSKiyoung Kim if chroot == "" { 35*2810ac1bSKiyoung Kim return false, nil 36*2810ac1bSKiyoung Kim } 37*2810ac1bSKiyoung Kim s = &syscall.SysProcAttr{ 38*2810ac1bSKiyoung Kim Chroot: chroot, 39*2810ac1bSKiyoung Kim } 40*2810ac1bSKiyoung Kim pa.Sys = s 41*2810ac1bSKiyoung Kim } else if s.Chroot != "" { 42*2810ac1bSKiyoung Kim return false, ErrAmbiguousChroot 43*2810ac1bSKiyoung Kim } 44*2810ac1bSKiyoung Kim if s.Credential != nil { 45*2810ac1bSKiyoung Kim return false, ErrAmbiguousIDs 46*2810ac1bSKiyoung Kim } 47*2810ac1bSKiyoung Kim if len(s.AmbientCaps) != 0 { 48*2810ac1bSKiyoung Kim return false, ErrAmbiguousAmbient 49*2810ac1bSKiyoung Kim } 50*2810ac1bSKiyoung Kim return s != nil && s.Chroot != "", nil 51*2810ac1bSKiyoung Kim} 52