strip path-info from -v (version) output, and implement -v flag for containerd-shim #6495
strip path-info from -v (version) output, and implement -v flag for containerd-shim #6495estesp merged 3 commits intocontainerd:mainfrom
-v (version) output, and implement -v flag for containerd-shim #6495Conversation
| func main() { | ||
| if len(os.Args) != 2 { | ||
| fmt.Printf("Usage: %s file_or_directory\n", os.Args[0]) | ||
| fmt.Printf("Usage: %s file_or_directory\n", filepath.Base(os.Args[0])) |
There was a problem hiding this comment.
I didn't know that POSIX has recommendations around such a detail...
This one seems only used by get_owner_windows.exe. Should we use the name instead?
There was a problem hiding this comment.
I didn't know that POSIX has recommendations around such a detail...
Yes, it's quite detailed, but also looks like nobody really follows the recommendations (including quite "posix-y" tools). That said; I thought it made sense to not make the output depend on "how" you call the binary (e.g. don't print ../../../../<binary> if you happen to use that as path 😂)
There were a couple more (somewhat interesting) recommendations in there, for example: https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
the version number proper starts after the last space
(could be useful for easily parse / get the version from the output, especially given that we also output "git commit" etc.
Some other recommendations about licensing, and "support" / "project" URLs in output of --help (perhaps URL to where to report security issues etc?) https://www.gnu.org/prep/standards/html_node/_002d_002dhelp.html#g_t_002d_002dhelp
Anyway; not very urgent, but more of a "nice to do at some point"
This one seems only used by get_owner_windows.exe. Should we use the name instead?
oh, good on; I guess for this one, we could hard code it; let me change that
There was a problem hiding this comment.
Well, I will dust off the rock I crawl under when I forget guidelines I should never forget. Thanks for taking care of this!
There was a problem hiding this comment.
You're welcome 😅. Yeah (as outlined above); even though there's POSIX, it looks like nobody really follows the rules, so I consider it a "best effort" (and something to keep in the back of my mind when working on these things)
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: ad77111.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 <[email protected]>
…e output 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. We don't have a const for this, but let's make a start and just remove the path info. Signed-off-by: Sebastiaan van Stijn <[email protected]>
cmd/containerd-shim/main_unix.go
Outdated
| func main() { | ||
| parseFlags() | ||
| if versionFlag { | ||
| fmt.Printf("%s:\n", filepath.Base(os.Args[0])) |
There was a problem hiding this comment.
Actually; this one is also only used for containerd-shim, so we can hard-code it here as well
Unlike the other shims, containerd-shim did not have a -v (version) flag:
./bin/containerd-shim-runc-v1 -v
./bin/containerd-shim-runc-v1:
Version: v1.6.0-rc.1
Revision: ad77111.m
Go version: go1.17.2
./bin/containerd-shim -v
flag provided but not defined: -v
Usage of ./bin/containerd-shim:
This patch adds a `-v` flag to be consistent with the other shims. The code was
slightly refactored to match the implementation in the other shims, taking the
same approach as https://github.com/containerd/containerd/blob/77d53d2d230c3bcd3f02e6f493019a72905c875b/runtime/v2/shim/shim.go#L240-L256
Signed-off-by: Sebastiaan van Stijn <[email protected]>
cbac8b8 to
fdbfde5
Compare
|
Updated 👍 ptal |
|
@estesp Looks good to go? |
runtime/v2/shim: strip path information from version output
I noticed that path information showed up in the version output:
POSIX guidelines describes; https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
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.
integration/images/volume-ownership: strip path information from usage output
POSIX guidelines describes; https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
We don't have a const for this, but let's make a start and just remove the path info.
cmd/containerd-shim: add -v (version) flag
Unlike the other shims, containerd-shim did not have a -v (version) flag:
This patch adds a
-vflag to be consistent with the other shims. The code wasslightly refactored to match the implementation in the other shims, taking the
same approach as
containerd/runtime/v2/shim/shim.go
Lines 240 to 256 in 77d53d2