Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strip path-info from -v (version) output, and implement -v flag for containerd-shim #6495

Merged
merged 3 commits into from
Mar 8, 2022

Conversation

thaJeztah
Copy link
Member

runtime/v2/shim: strip path information from version output

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.

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

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.

cmd/containerd-shim: add -v (version) flag

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

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.Println(" Version: ", version.Version)
fmt.Println(" Revision:", version.Revision)
fmt.Println(" Go version:", version.GoVersion)
fmt.Println("")
return nil
}
if namespaceFlag == "" {
return fmt.Errorf("shim namespace cannot be empty")
}
setRuntime()


"golang.org/x/sys/windows"
)

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]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I will dust off the rock I crawl under when I forget guidelines I should never forget. Thanks for taking care of this!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <github@gone.nl>
…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 <github@gone.nl>
func main() {
parseFlags()
if versionFlag {
fmt.Printf("%s:\n", filepath.Base(os.Args[0]))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <github@gone.nl>
@thaJeztah
Copy link
Member Author

Updated 👍 ptal

@thaJeztah
Copy link
Member Author

@dmcgowan @estesp ptal; relatively small change (consistently having a -v flag on all binaries makes it easy to do a quick check if the binaries are "functional")

@kzys
Copy link
Member

kzys commented Mar 8, 2022

@estesp Looks good to go?

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants