From 23fd96806d2ac9946e38df5eb2a2e7d6c2cd44da Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 26 Nov 2016 17:04:23 +0100 Subject: ipc: append pid to binary name E.g. if binary is 'syz-executor' and pid=15, we create a link from 'syz-executor15' to 'syz-executor' and use 'syz-executor15' as binary. This allows to easily identify program that lead to a crash in the log. Log contains pid in "executing program 15" and crashes usually contain "Comm: syz-executor15". --- ipc/ipc.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ipc') diff --git a/ipc/ipc.go b/ipc/ipc.go index 144bf9828..36cee04c5 100644 --- a/ipc/ipc.go +++ b/ipc/ipc.go @@ -131,6 +131,21 @@ func MakeEnv(bin string, timeout time.Duration, flags uint64, pid int) (*Env, er if err != nil { return nil, fmt.Errorf("filepath.Abs failed: %v", err) } + // Append pid to binary name. + // E.g. if binary is 'syz-executor' and pid=15, + // we create a link from 'syz-executor15' to 'syz-executor' and use 'syz-executor15' as binary. + // This allows to easily identify program that lead to a crash in the log. + // Log contains pid in "executing program 15" and crashes usually contain "Comm: syz-executor15". + base := filepath.Base(env.bin[0]) + pidStr := fmt.Sprint(pid) + if len(base)+len(pidStr) >= 16 { + // TASK_COMM_LEN is currently set to 16 + base = base[:15-len(pidStr)] + } + binCopy := filepath.Join(filepath.Dir(env.bin[0]), base+pidStr) + if err := os.Link(env.bin[0], binCopy); err == nil { + env.bin[0] = binCopy + } inf = nil outf = nil return env, nil -- cgit mrf-deployment