From 5d8a2199b6c8dc5f75b529a39d196c6cb14c98c2 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 21 Aug 2025 00:18:50 +0900 Subject: container/init: op interface valid method Check ops early and eliminate duplicate checks. Signed-off-by: Ophestra --- container/initremount.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'container/initremount.go') diff --git a/container/initremount.go b/container/initremount.go index 77efc21d..74bea097 100644 --- a/container/initremount.go +++ b/container/initremount.go @@ -3,7 +3,6 @@ package container import ( "encoding/gob" "fmt" - "syscall" ) func init() { gob.Register(new(RemountOp)) } @@ -20,20 +19,18 @@ type RemountOp struct { Flags uintptr } +func (r *RemountOp) Valid() bool { return r != nil && r.Target != nil } func (*RemountOp) early(*setupState) error { return nil } func (r *RemountOp) apply(*setupState) error { - if r.Target == nil { - return syscall.EBADE - } return wrapErrSuffix(hostProc.remount(toSysroot(r.Target.String()), r.Flags), fmt.Sprintf("cannot remount %q:", r.Target)) } func (r *RemountOp) Is(op Op) bool { vr, ok := op.(*RemountOp) - return ok && ((r == nil && vr == nil) || - (r.Target != nil && vr.Target != nil && r.Target.Is(vr.Target)) && - r.Flags == vr.Flags) + return ok && r.Valid() && vr.Valid() && + r.Target.Is(vr.Target) && + r.Flags == vr.Flags } func (*RemountOp) prefix() string { return "remounting" } func (r *RemountOp) String() string { return fmt.Sprintf("%q flags %#x", r.Target, r.Flags) } -- cgit v1.3.1