From 87f9362975341e5e12db5b484f662cbc525a1e41 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Tue, 28 Mar 2017 15:18:39 -0700 Subject: [PATCH] Update "tini --version" parsing to be more forgiving of Tini's output format (release build vs git build) Signed-off-by: Andrew "Tianon" Page --- daemon/info_unix.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/daemon/info_unix.go b/daemon/info_unix.go index 9c41c0e4cd..e60a06a006 100644 --- a/daemon/info_unix.go +++ b/daemon/info_unix.go @@ -56,20 +56,23 @@ func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) v.InitCommit.Expected = dockerversion.InitCommitID if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil { + // examples of how Tini outputs version info: + // "tini version 0.13.0 - git.949e6fa" + // "tini version 0.13.2" parts := strings.Split(strings.TrimSpace(string(rv)), " - ") - if len(parts) == 2 { - if dockerversion.InitCommitID[0] == 'v' { - vs := strings.TrimPrefix(parts[0], "tini version ") - v.InitCommit.ID = "v" + vs - } else { - // Get the sha1 - gitParts := strings.Split(parts[1], ".") - if len(gitParts) == 2 && gitParts[0] == "git" { - v.InitCommit.ID = gitParts[1] - v.InitCommit.Expected = dockerversion.InitCommitID[0:len(gitParts[1])] - } + + v.InitCommit.ID = "" + if v.InitCommit.ID == "" && len(parts) >= 2 { + gitParts := strings.Split(parts[1], ".") + if len(gitParts) == 2 && gitParts[0] == "git" { + v.InitCommit.ID = gitParts[1] + v.InitCommit.Expected = dockerversion.InitCommitID[0:len(v.InitCommit.ID)] } } + if v.InitCommit.ID == "" && len(parts) >= 1 { + vs := strings.TrimPrefix(parts[0], "tini version ") + v.InitCommit.ID = "v" + vs + } if v.InitCommit.ID == "" { logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultInitBinary, string(rv))