Black Lives Matter. Support the Equal Justice Initiative.

Source file src/net/unixsock_readmsg_cloexec.go

Documentation: net

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

View as plain text