From b9dfa444c43343d227a19eb6e9fb36a4d17615a5 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Tue, 24 Jan 2017 22:53:59 +0000 Subject: [PATCH] Resolve InitArgs to ensure init works If a relative pathed exe is used for InitArgs init will fail to run if Cwd is not set the original path. Prevent failure of init to run by ensuring that exe in InitArgs is an absolute path. Signed-off-by: Steven Hartland --- libcontainer/factory_linux.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index fbaaf639..c41145d2 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -34,7 +34,15 @@ var ( // InitArgs returns an options func to configure a LinuxFactory with the // provided init binary path and arguments. func InitArgs(args ...string) func(*LinuxFactory) error { - return func(l *LinuxFactory) error { + return func(l *LinuxFactory) (err error) { + if len(args) > 0 { + // Resolve relative paths to ensure that its available + // after directory changes. + if args[0], err = filepath.Abs(args[0]); err != nil { + return newGenericError(err, ConfigInvalid) + } + } + l.InitArgs = args return nil }