From f694ecdc179cf43429135188934eed687ae28645 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 7 May 2024 17:04:18 +0200 Subject: pkg/ipc: split out EmptyProgInfo() --- pkg/ipc/ipc.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'pkg/ipc') diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index c83fabe84..826d3068d 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -105,6 +105,17 @@ type ProgInfo struct { Freshness int // number of programs executed in the same process before this one } +func EmptyProgInfo(calls int) *ProgInfo { + info := &ProgInfo{Calls: make([]CallInfo, calls)} + for i := range info.Calls { + // Store some unsuccessful errno in the case we won't get any result. + // It also won't have CallExecuted flag, but it's handy to make it + // look failed based on errno as well. + info.Calls[i].Errno = int(syscall.ENOSYS) + } + return info +} + type Env struct { in []byte out []byte @@ -401,13 +412,7 @@ func (env *Env) parseOutput(opts *ExecOpts, ncalls int) (*ProgInfo, error) { if !ok { return nil, fmt.Errorf("failed to read number of calls") } - info := &ProgInfo{Calls: make([]CallInfo, ncalls)} - for i := range info.Calls { - // Store some unsuccessful errno in the case we won't get any result. - // It also won't have CallExecuted flag, but it's handy to make it - // look failed based on errno as well. - info.Calls[i].Errno = int(syscall.ENOSYS) - } + info := EmptyProgInfo(ncalls) extraParts := make([]CallInfo, 0) for i := uint32(0); i < ncmd; i++ { if len(out) < int(unsafe.Sizeof(callReply{})) { -- cgit mrf-deployment