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

modif: Improve --version/--help & print version on startup #5829

Merged
merged 9 commits into from
May 19, 2023

Conversation

kmk3
Copy link
Collaborator

@kmk3 kmk3 commented May 14, 2023

It is not too uncommon for the firejail version to be missing when issues are
reported; this PR makes it more likely that any posted logs will contain the
program version.

Do so just for firejail and firecfg for now because they are the most common
user-facing programs.

Kind of relates to #5275.

kmk3 added 9 commits May 12, 2023 12:11
Added on commit 42e2db1 ("jaitest - simple sandbox testing utility
program", 2021-02-20).
Currently, --version doesn't print a dash while --help does.  Example:

    $ firejail --version | grep 'version 0'
    firejail version 0.9.73
    $ firejail --help | grep 'version 0'
    firejail - version 0.9.73

For consistency, always print the version without a dash.

Commands used to search and replace:

    $ git grep -IFlz ' - version' -- src | xargs -0 -I '{}' sh -c
      "printf '%s\n' \"\$(sed 's/ - version/ version/' '{}')\" >'{}'"
Split print_version into two functions:

* print_version: only prints the version line
* print_version_full: also prints compile-time support
Build the entire string at once and print it only once.
Changes:

* Only print the version line in the print_version function
* Add a print_version function where missing (put it in usage.c if the
  file exists)
* Always a blank line after the version
Changes:

* Name them all "usage_str"
* Make them const

For the latter item, see commit eb20f52 ("Make list of paths const to
fix a false positive of gcc analyzer", 2022-07-27) / PR netblue30#5275.
For consistency and readability.

Note: This also makes exactly one extra blank line be printed at the end
of every usage text, which is currently only done in the following
files:

* src/fcopy/main.c
* src/fnettrace-dns/main.c
* src/fnettrace-icmp/main.c
* src/fnettrace-sni/main.c
* src/fnettrace/main.c
* src/profstats/main.c
It is not too uncommon for the firejail version to be missing when
issues are reported; this commit makes it more likely that any posted
logs will contain the program version.

Do so just for firejail and firecfg for now because they are the most
common user-facing programs.

Print the version after argument parsing, in order to avoid printing the
program version more than once and to avoid interfering with commands
that generate machine-readable output (like `firejail --list` and
`firecfg --list`).  Also, only print it after all profiles have been
loaded, because a profile may contain `quiet`.

Note: This does not cover the case where the program exits before the
end of argument/profile parsing (such as when an error occurs).
Copy link
Collaborator

@glitsj16 glitsj16 left a comment

Choose a reason for hiding this comment

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

LGTM. Nice work!

@netblue30 netblue30 merged commit 6a94b36 into netblue30:master May 19, 2023
@netblue30
Copy link
Owner

all in, thanks!

@kmk3 kmk3 deleted the improve-print-version branch May 19, 2023 17:26
kmk3 added a commit that referenced this pull request May 19, 2023
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 28, 2024
Unlike the rest of the normal startup output (which goes to stderr), the
version number is being printed to stdout, which makes it harder to
ignore all of firejail's output.  Example:

    $ firejail --noprofile /usr/bin/true --version 2>/dev/null
    firejail version 0.9.73

    true (GNU coreutils) 9.4
    Copyright (C) 2023 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Jim Meyering.

So make the normal startup version output go to stderr and keep the
other occurrences (such as in `firejail --version`) going to stdout, to
make it easier to grep things in the output.

Added on commit f019f0e ("Print version on startup for
firejail/firecfg", 2023-05-11) / PR netblue30#5829.

Reported by @rusty-snake[1].

[1] netblue30#6171 (comment)
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 31, 2024
Unlike the rest of the normal startup output (which goes to stderr), the
version number is being printed to stdout, which makes it harder to
ignore all of firejail's output.  Example:

    $ firejail --noprofile /usr/bin/true --version 2>/dev/null
    firejail version 0.9.73

    true (GNU coreutils) 9.4
    Copyright (C) 2023 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Jim Meyering.

So make the normal startup version output go to stderr and keep the
other occurrences (such as in `firejail --version`) going to stdout, to
make it easier to grep things in the output.

Added on commit f019f0e ("Print version on startup for
firejail/firecfg", 2023-05-11) / PR netblue30#5829.

Reported by @rusty-snake[1].

[1] netblue30#6171 (comment)
kmk3 added a commit that referenced this pull request Jan 31, 2024
Unlike the rest of the normal startup output (which goes to stderr), the
version number is being printed to stdout, which makes it harder to
ignore all of firejail's output.  Example:

    $ firejail --noprofile /usr/bin/true --version 2>/dev/null
    firejail version 0.9.73

    true (GNU coreutils) 9.4
    Copyright (C) 2023 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Jim Meyering.

So make the normal startup version output go to stderr and keep the
other occurrences (such as in `firejail --version`) going to stdout, to
make it easier to grep things in the output.

Added on commit f019f0e ("Print version on startup for
firejail/firecfg", 2023-05-11) / PR #5829.

Reported by @rusty-snake[1].

[1] #6171 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done (on RELNOTES)
Development

Successfully merging this pull request may close these issues.

3 participants