You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// unset our pid from the audit subsystem and close the socket.
504
+
// This is a sort of isolated refactor, meant to deal with the deadlocks that can happen when we're not careful with blocking operations throughout a lot of this code.
505
+
func (c*AuditClient) closeAndUnsetPid() error {
506
+
msg:= syscall.NetlinkMessage{
507
+
Header: syscall.NlMsghdr{
508
+
Type: AuditSet,
509
+
Flags: syscall.NLM_F_REQUEST,
510
+
},
511
+
Data: AuditStatus{
512
+
Mask: AuditStatusPID,
513
+
PID: 0,
514
+
}.toWireFormat(),
515
+
}
516
+
517
+
// If our request to unset the PID would block, then try to drain events from
518
+
// the netlink socket, resend, try again.
519
+
// In netlink, EAGAIN usually indicates our read buffer is full.
520
+
// The auditd code (which I'm using as a reference implementation) doesn't wait for a response when unsetting the audit pid.
521
+
// The retry count here is largely arbitrary, and provides a buffer for either transient errors (EINTR) or retries.
522
+
retries:=5
523
+
outer:
524
+
fori:=0; i<retries; i++ {
525
+
_, err:=c.Netlink.SendNoWait(msg)
526
+
switch {
527
+
caseerr==nil:
528
+
returnnil
529
+
caseerrors.Is(err, syscall.EINTR):
530
+
// got a transient interrupt, try again
531
+
continue
532
+
caseerrors.Is(err, syscall.EAGAIN):
533
+
// send would block, try to drain the receive socket. The recv count here is just so we have enough of a buffer to attempt a send again/
534
+
// The number is just here so we ideally have enough of a buffer to attempt the send again.
0 commit comments