diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-03-25 15:34:20 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-03-25 15:39:29 +0900 |
| commit | 50403e9d60a69640107d20525379d4714da2f739 (patch) | |
| tree | eb9a72082f5aaf04c886db68b07ad8ccb9c88e72 /container/dispatcher.go | |
| parent | b98c5f2e219c142ab89c09445b6c014120f0760f (diff) | |
internal/netlink: wrap netpoll via context
This removes netpoll boilerplate for the most common use case.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/dispatcher.go')
| -rw-r--r-- | container/dispatcher.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/container/dispatcher.go b/container/dispatcher.go index dce5f023..9f971fa5 100644 --- a/container/dispatcher.go +++ b/container/dispatcher.go @@ -1,6 +1,7 @@ package container import ( + "context" "io" "io/fs" "net" @@ -66,7 +67,7 @@ type syscallDispatcher interface { // ensureFile provides ensureFile. ensureFile(name string, perm, pperm os.FileMode) error // mustLoopback provides mustLoopback. - mustLoopback(msg message.Msg) + mustLoopback(ctx context.Context, msg message.Msg) // seccompLoad provides [seccomp.Load]. seccompLoad(rules []std.NativeRule, flags seccomp.ExportFlag) error @@ -170,7 +171,7 @@ func (k direct) mountTmpfs(fsname, target string, flags uintptr, size int, perm func (direct) ensureFile(name string, perm, pperm os.FileMode) error { return ensureFile(name, perm, pperm) } -func (direct) mustLoopback(msg message.Msg) { +func (direct) mustLoopback(ctx context.Context, msg message.Msg) { var lo int if ifi, err := net.InterfaceByName("lo"); err != nil { msg.GetLogger().Fatalln(err) @@ -199,11 +200,14 @@ func (direct) mustLoopback(msg message.Msg) { msg.GetLogger().Fatalf("RTNETLINK answers: %v", err) default: - msg.GetLogger().Fatalf("RTNETLINK answers with malformed message") + if err == context.DeadlineExceeded || err == context.Canceled { + msg.GetLogger().Fatalf("interrupted RTNETLINK operation") + } + msg.GetLogger().Fatal("RTNETLINK answers with malformed message") } } - must(c.SendNewaddrLo(uint32(lo))) - must(c.SendIfInfomsg(syscall.RTM_NEWLINK, 0, &syscall.IfInfomsg{ + must(c.SendNewaddrLo(ctx, uint32(lo))) + must(c.SendIfInfomsg(ctx, syscall.RTM_NEWLINK, 0, &syscall.IfInfomsg{ Family: syscall.AF_UNSPEC, Index: int32(lo), Flags: syscall.IFF_UP, |
