peercred

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 6 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package peercred reads who is at the other end of a Unix socket, as the kernel recorded it when the peer connected: its credentials, and where the kernel gives one a pidfd, which keeps naming that process after its pid has been reused.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPIDFD = errors.New("the kernel has no SO_PEERPIDFD")

ErrNoPIDFD is what PIDFDOf wraps on a kernel without SO_PEERPIDFD (before Linux 6.5): the peer is known by its Credentials alone.

Functions

This section is empty.

Types

type Credentials

type Credentials struct {
	UID uint32
	GID uint32
	PID int32
}

Credentials are the ids of the process at a socket's other end, from SO_PEERCRED.

func Of

func Of(conn *net.UnixConn) (Credentials, error)

Of reads the credentials of the process at conn's other end.

type PIDFD

type PIDFD struct {
	// contains filtered or unexported fields
}

PIDFD is a pidfd of the process at a socket's other end, with that process's credentials. Unlike its pid it names that one process for as long as it is held, whatever the pid is reused for.

func PIDFDOf

func PIDFDOf(conn *net.UnixConn) (*PIDFD, error)

PIDFDOf opens a pidfd of the process at conn's other end, for the caller to Close. A kernel without SO_PEERPIDFD is ErrNoPIDFD: there Of still says who the peer is.

func (*PIDFD) Close

func (p *PIDFD) Close() error

Close releases the descriptor.

func (*PIDFD) Credentials

func (p *PIDFD) Credentials() Credentials

Credentials are the ids of the process the pidfd names, as Of reads them.

func (*PIDFD) Exited

func (p *PIDFD) Exited() (bool, error)

Exited reports whether the process has ended. While it has not, its pid is still its own: what was read by that pid before an Exited that reports false was read of this process.

func (*PIDFD) FD

func (p *PIDFD) FD() (int, error)

FD is the descriptor, for a call that takes a pidfd; it is valid until Close.

Directories

Path Synopsis
Package peercredtest gives a test a socket peer that is another process, with a pid and a lifetime of its own: what telling a peer from the test itself, or outliving it, needs.
Package peercredtest gives a test a socket peer that is another process, with a pid and a lifetime of its own: what telling a peer from the test itself, or outliving it, needs.

Jump to

Keyboard shortcuts

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