mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-29 03:50:18 +00:00
Fix macOS build for sensor-proxy and improve hot-dev script
This commit is contained in:
parent
212484885f
commit
d8e2b40086
4 changed files with 243 additions and 171 deletions
44
cmd/pulse-sensor-proxy/peer_creds_linux.go
Normal file
44
cmd/pulse-sensor-proxy/peer_creds_linux.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// extractPeerCredentials extracts peer credentials via SO_PEERCRED
|
||||
func extractPeerCredentials(conn net.Conn) (*peerCredentials, error) {
|
||||
unixConn, ok := conn.(*net.UnixConn)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("not a unix connection")
|
||||
}
|
||||
|
||||
file, err := unixConn.File()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get file descriptor: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
fd := int(file.Fd())
|
||||
|
||||
cred, err := syscall.GetsockoptUcred(fd, syscall.SOL_SOCKET, syscall.SO_PEERCRED)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get peer credentials: %w", err)
|
||||
}
|
||||
|
||||
log.Debug().
|
||||
Int32("pid", cred.Pid).
|
||||
Uint32("uid", cred.Uid).
|
||||
Uint32("gid", cred.Gid).
|
||||
Msg("Peer credentials")
|
||||
|
||||
return &peerCredentials{
|
||||
uid: cred.Uid,
|
||||
pid: uint32(cred.Pid),
|
||||
gid: cred.Gid,
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue