Source file src/net/unixsock_readmsg_cloexec.go

     1  // Copyright 2021 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  //go:build aix || darwin || freebsd || solaris
     6  
     7  package net
     8  
     9  import "syscall"
    10  
    11  const readMsgFlags = 0
    12  
    13  func setReadMsgCloseOnExec(oob []byte) {
    14  	scms, err := syscall.ParseSocketControlMessage(oob)
    15  	if err != nil {
    16  		return
    17  	}
    18  
    19  	for _, scm := range scms {
    20  		if scm.Header.Level == syscall.SOL_SOCKET && scm.Header.Type == syscall.SCM_RIGHTS {
    21  			fds, err := syscall.ParseUnixRights(&scm)
    22  			if err != nil {
    23  				continue
    24  			}
    25  			for _, fd := range fds {
    26  				syscall.CloseOnExec(fd)
    27  			}
    28  		}
    29  	}
    30  }
    31  

View as plain text