Applications like the 'sway' Wayland compositor rely on getting the socket peer's pid for IPC security. It would be nice to get FreeBSD to report the pid, not just uid and gids, through the LOCAL_PEERCRED option.
From the commit that fixed bug #102956 (SO_PEERCRED in Linux emulation): "Temporarily use 0 for pid member as the FreeBSD does not cache remote UNIX domain socket peer pid"
So adding pid to LOCAL_PEERCRED would allow a simple improvement to Linux compatibility as well.

Created attachment 188271[details]
peercred.patch
Well, that was easy. Here's a tiny patch that fixes the problem.
Should XUCRED_VERSION be raised? Adding an extra field at the end of the struct doesn't break backwards compatibility…

The pid in LOCAL_PEERCRED is not a security feature but only a feature to enforce that a proper security feature can be added later. This is because there is nothing to enforce that the pid refers to the same process or that it has not executed some other binary; also, applications are not isolated in a way that makes different Wayland privileges useful for security.
Adding pid to struct ucred seems wrong since it is shared between processes that do not change their credentials. This would make more sense as a property of the socket. The pid would then be the pid of the process that called listen() or connect().

(In reply to Jilles Tjoelker from comment #2)
sway just uses the pid to read /proc/PID/file and check the file against a list of allowed files.
The pid is in ucred on Linux, I think it makes sense to match what they do.