unixlisten

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: Apache-2.0 Copyright Authors of Tetragon

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenWithRename

func ListenWithRename(path string, mode os.FileMode) (net.Listener, error)

ListenWithRename creates a "unix" listener for the given path and the given mode

Go's net.Listen() performs three system calls at once:

  • socket, where the file descriptor is created
  • bind, where the unix socket file is created
  • listen, where the socket can now accept connections

Hence, doing a chmod(2) after Listen is racy because a client can connect between the listen(2) and the chmod(2) calls. One solution would be to use umask(2), but this is tricky to do in a multi-threaded program because it affects other files being created from different threads. Also, other threads may change the umask.

This function, instead, creates the socket file in a private directory, performs the appropriate chmod and only then moves the file to its original location. Not sure about other systems, but at least on Linux renaming a unix socket file after the listen seems to work without issues.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL