Skip to content

x/sys/unix: Enable pid lookup of unix socket peer for darwin #27613

@APTy

Description

@APTy

Package syscall on linux currently has behavior to look up a Ucred object, which contains the PID of the remote end of a Unix socket using getsockopt + SO_PEERCRED.

This feature request seeks to add similar behavior for darwin (and perhaps BSD). This can be done using getsockopt + LOCAL_PEERPID. Note that we can't use LOCAL_PEERCRED, as the behavior isn't identical to linux: we get a xucred struct, which doesn't contain a pid.

Open question: linux's type syscall.Ucred exposes UID, GID, and PID. These are all useful, however an exact darwin analog doesn't exist. Options:

  1. Conform to the linux golang API
  • Add a custom golang type syscall.Ucred type for darwin that contains UID, GID, and PID.
  • Add func syscall.GetsockoptUcred(...) (syscall.Ucred, error) for darwin that abstracts two getsockopt system calls: (1) LOCAL_PEERPID for the pid, and (2) LOCAL_PEERCRED for the user and group

or

  1. Conform to the darwin C API
  • Expose darwin's xucred struct that contains UID and GID (type syscall.Xucred)
  • Add func syscall.GetsockoptXucred(...) (syscall.Xucred, error) to look up UID and GID
  • Add func syscall.GetsockoptPID(...) (int, error) to look up PID

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions