mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-10 18:36:45 +08:00
* fix(agent): join Pi cancellation cleanup and guard continuation Co-authored-by: multica-agent <[email protected]> * fix(agent): preserve Pi completion and negotiate cleanup Co-authored-by: multica-agent <[email protected]> * perf(agent): avoid Pi exit delay and index cleanup guards Co-authored-by: multica-agent <[email protected]> --------- Co-authored-by: Multica Eve <[email protected]> Co-authored-by: multica-agent <[email protected]>
40 lines
962 B
Go
40 lines
962 B
Go
//go:build linux
|
|
|
|
package agent
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
type piLinuxProcessIdentity struct{ fd int }
|
|
|
|
func piProcessMissing(_ int, err error) bool {
|
|
return errors.Is(err, syscall.ESRCH) || errors.Is(err, os.ErrNotExist)
|
|
}
|
|
|
|
func capturePiProcessIdentity(info cursorUnixProcessInfo) (piProcessIdentity, error) {
|
|
fd, err := unix.PidfdOpen(info.pid, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
current, err := readCursorUnixProcessInfo(info.pid)
|
|
if err != nil || current.start != info.start {
|
|
_ = unix.Close(fd)
|
|
if piProcessMissing(info.pid, err) {
|
|
return nil, syscall.ESRCH
|
|
}
|
|
return nil, fmt.Errorf("process identity changed during capture: %d", info.pid)
|
|
}
|
|
return &piLinuxProcessIdentity{fd: fd}, nil
|
|
}
|
|
|
|
func (p *piLinuxProcessIdentity) signal(sig syscall.Signal) error {
|
|
return unix.PidfdSendSignal(p.fd, unix.Signal(sig), nil, 0)
|
|
}
|
|
func (p *piLinuxProcessIdentity) close() { _ = unix.Close(p.fd) }
|