From 792dcb59a837e7061f01edd5e8e97e132502f5bd Mon Sep 17 00:00:00 2001 From: Jana Radhakrishnan Date: Tue, 1 Sep 2015 12:17:15 -0700 Subject: [PATCH] Do not panic on setns failure Since panicking on setns failure affects daemon availability convert them to error log messages. Signed-off-by: Jana Radhakrishnan --- sandbox/namespace_linux.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sandbox/namespace_linux.go b/sandbox/namespace_linux.go index cadd487..d19acc9 100644 --- a/sandbox/namespace_linux.go +++ b/sandbox/namespace_linux.go @@ -244,11 +244,20 @@ func (n *networkNamespace) InvokeFunc(f func()) error { }) } +func getLink() string { + l, err := os.Readlink(fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid())) + if err != nil { + return fmt.Sprintf("(nil: %v)", err) + } + + return l +} + func nsInit() { var err error if initNs, err = netns.Get(); err != nil { - panic(fmt.Sprintf("could not get initial namespace: %v", err)) + log.Errorf("could not get initial namespace: %v", err) } } @@ -257,7 +266,8 @@ func InitOSContext() func() { runtime.LockOSThread() nsOnce.Do(nsInit) if err := netns.Set(initNs); err != nil { - panic(fmt.Sprintf("failed to set to initial namespace: %v", err)) + log.Errorf("failed to set to initial namespace, link %s, initns fd %d: %v", + getLink(), initNs, err) } return runtime.UnlockOSThread