| 1 |
//go:build zos && s390x |
| 2 |
|
| 3 |
package tcplisten |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
|
| 8 |
"golang.org/x/sys/unix" |
| 9 |
) |
| 10 |
|
| 11 |
func newSocketCloexec(domain, typ, proto int) (int, error) { |
| 12 |
fd, err := unix.Socket(domain, typ, proto) |
| 13 |
if err != nil { |
| 14 |
return -1, fmt.Errorf("cannot create listening socket: %w", err) |
| 15 |
} |
| 16 |
_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFD, unix.FD_CLOEXEC) |
| 17 |
if err != nil { |
| 18 |
unix.Close(fd) //nolint:errcheck |
| 19 |
return -1, fmt.Errorf("cannot mark listening socket close-on-exec: %w", err) |
| 20 |
} |
| 21 |
_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFL, unix.O_NONBLOCK) |
| 22 |
if err != nil { |
| 23 |
unix.Close(fd) //nolint:errcheck |
| 24 |
return -1, fmt.Errorf("cannot mark listening socket nonblocking: %w", err) |
| 25 |
} |
| 26 |
return fd, nil |
| 27 |
} |