From 9c485361748bb98b94747b24768b5f8f12ce12a6 Mon Sep 17 00:00:00 2001 From: Ace-Tang Date: Wed, 12 Jun 2019 17:38:10 +0800 Subject: [PATCH] katautils: fix shim v2 fail to work with libnetwork detail how kata work with libnetwork 1. kata create a new netns 2. with EnterNS, kata change netns to the created one. 3. in pre-start hook, kata will re-exec libnetwork process libnetwork-setkey, and send self pid to it. libnetwork use /proc/pid/ns/net to find the netns kata use, and set veth into the netns. v1/v2 shim use the same way to create network, v1 can successful because EnterNS changed both current thread and main thread's netns. But use v2 shim, only changed current thread netns, main thread still use host netns, so it fails. Looks like v1 just lucky to be successful. In kata, `state.Pid` should be tid. Fixes: #1788 Signed-off-by: Ace-Tang --- pkg/katautils/hook.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/katautils/hook.go b/pkg/katautils/hook.go index cfb15522e0..c73ac2ab62 100644 --- a/pkg/katautils/hook.go +++ b/pkg/katautils/hook.go @@ -11,7 +11,6 @@ import ( "context" "encoding/json" "fmt" - "os" "os/exec" "strings" "syscall" @@ -39,7 +38,7 @@ func runHook(ctx context.Context, hook specs.Hook, cid, bundlePath string) error log.String("hook-args", strings.Join(hook.Args, " "))) state := specs.State{ - Pid: os.Getpid(), + Pid: syscall.Gettid(), Bundle: bundlePath, ID: cid, }