Save failed processes

This commit is contained in:
Daniel 2020-05-15 22:43:15 +02:00
parent 53eb309e72
commit 652518e527

View file

@ -49,7 +49,8 @@ type Process struct {
FirstSeen int64 FirstSeen int64
LastSeen int64 LastSeen int64
Virtual bool // This process is either merged into another process or is not needed. Virtual bool // This process is either merged into another process or is not needed.
Error string // Cache errors
} }
// Profile returns the assigned layered profile. // Profile returns the assigned layered profile.
@ -94,6 +95,7 @@ func GetOrFindPrimaryProcess(ctx context.Context, pid int) (*Process, error) {
parentProcess, err := loadProcess(ctx, process.ParentPid) parentProcess, err := loadProcess(ctx, process.ParentPid)
if err != nil { if err != nil {
log.Tracer(ctx).Tracef("process: could not get parent of %d: %d: %s", process.Pid, process.ParentPid, err) log.Tracer(ctx).Tracef("process: could not get parent of %d: %d: %s", process.Pid, process.ParentPid, err)
saveFailedProcess(process.ParentPid, err.Error())
return process, nil return process, nil
} }
@ -226,13 +228,7 @@ func loadProcess(ctx context.Context, pid int) (*Process, error) {
pInfo, err := processInfo.NewProcess(int32(pid)) pInfo, err := processInfo.NewProcess(int32(pid))
if err != nil { if err != nil {
// TODO: remove this workaround as soon as NewProcess really returns an error on windows when the process does not exist return nil, err
// Issue: https://github.com/shirou/gopsutil/issues/729
_, err = pInfo.Name()
if err != nil {
// process does not exists
return nil, err
}
} }
// UID // UID
@ -375,3 +371,14 @@ func loadProcess(ctx context.Context, pid int) (*Process, error) {
new.Save() new.Save()
return new, nil return new, nil
} }
func saveFailedProcess(pid int, err string) {
failed := &Process{
Pid: pid,
FirstSeen: time.Now().Unix(),
Virtual: true, // not needed
Error: err,
}
failed.Save()
}