Merge "daemon: get peer pid, gid for socket connection on darwin" into main

This commit is contained in:
Lily Ballard
2025-02-04 04:50:49 +00:00
committed by Gerrit Code Review
3 changed files with 20 additions and 2 deletions
@@ -0,0 +1,12 @@
---
synopsis: "Fetch peer PID for daemon connections on macOS"
issues: [fj#640]
cls: [2453]
category: Fixes
credits: [lilyball]
---
`nix-daemon` will now fetch the peer PID for connections on macOS, to match behavior with Linux.
Besides showing up in the log output line, If `nix-daemon` is given an argument (such as `--daemon`)
that argument will be overwritten with the peer PID for the forked process that handles the connection,
which can be used for debugging purposes.
+7 -1
View File
@@ -188,7 +188,13 @@ static PeerInfo getPeerInfo(int remote)
socklen_t credLen = sizeof(cred);
if (getsockopt(remote, SOL_LOCAL, LOCAL_PEERCRED, &cred, &credLen) == -1)
throw SysError("getting peer credentials");
peer = { false, 0, true, cred.cr_uid, false, 0 };
peer = { false, 0, true, cred.cr_uid, true, cred.cr_gid };
#if defined(LOCAL_PEERPID)
socklen_t pidLen = sizeof(peer.pid);
if (!getsockopt(remote, SOL_LOCAL, LOCAL_PEERPID, &peer.pid, &pidLen))
peer.pidKnown = true;
#endif
#endif
+1 -1
View File
@@ -12,7 +12,7 @@
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>/bin/wait4path /nix/var/nix/profiles/default/bin/nix-daemon &amp;&amp; exec /nix/var/nix/profiles/default/bin/nix-daemon</string>
<string>/bin/wait4path /nix/var/nix/profiles/default/bin/nix-daemon &amp;&amp; exec /nix/var/nix/profiles/default/bin/nix-daemon --daemon</string>
</array>
<key>StandardErrorPath</key>
<string>/var/log/nix-daemon.log</string>