From b8cadf7539f2ed429f42582f45b38b4f563f2633 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 27 Jan 2022 14:09:09 +0100 Subject: [PATCH] runtime/v2/shim: strip path information from version output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I noticed that path information showed up in the version output: ./bin/containerd-shim-runc-v1 -v ./bin/containerd-shim-runc-v1: Version: v1.6.0-rc.1 Revision: ad771115b82a70cfd8018d72ae489c707e63de16.m Go version: go1.17.2 POSIX guidelines describes; https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion > The program’s name should be a constant string; don’t compute it from argv[0]. > The idea is to state the standard or canonical name for the program, not its > file name. Unfortunately, this code is used by multiple binaries, so we can't fully remove the use of os.Args[0], but let's make a start and just remove the path info. Signed-off-by: Sebastiaan van Stijn --- runtime/v2/shim/shim.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/v2/shim/shim.go b/runtime/v2/shim/shim.go index 59e522ced..cc5b68440 100644 --- a/runtime/v2/shim/shim.go +++ b/runtime/v2/shim/shim.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "os" + "path/filepath" "runtime" "runtime/debug" "strings" @@ -240,7 +241,7 @@ func RunManager(ctx context.Context, manager Manager, opts ...BinaryOpts) { func run(ctx context.Context, manager Manager, initFunc Init, name string, config Config) error { parseFlags() if versionFlag { - fmt.Printf("%s:\n", os.Args[0]) + fmt.Printf("%s:\n", filepath.Base(os.Args[0])) fmt.Println(" Version: ", version.Version) fmt.Println(" Revision:", version.Revision) fmt.Println(" Go version:", version.GoVersion)