github.com/gidoBOSSftw5731/go/src@v0.0.0-20210226122457-d24b0edbf019/syscall/sock_cloexec_linux.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package syscall 6 7 // This is a stripped down version of sysSocket from net/sock_cloexec.go. 8 func cloexecSocket(family, sotype, proto int) (int, error) { 9 s, err := Socket(family, sotype|SOCK_CLOEXEC, proto) 10 switch err { 11 case nil: 12 return s, nil 13 default: 14 return -1, err 15 case EINVAL: 16 } 17 18 ForkLock.RLock() 19 s, err = Socket(family, sotype, proto) 20 if err == nil { 21 CloseOnExec(s) 22 } 23 ForkLock.RUnlock() 24 if err != nil { 25 Close(s) 26 return -1, err 27 } 28 return s, nil 29 }