Skip to content

Commit

Permalink
bugfix: print version to stderr on startup
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
kmk3 committed Jan 31, 2024
1 parent 0c2be35 commit ebc9662
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/firejail/firejail.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ void tree(void);
void top(void);

// usage.c
void print_version(void);
void print_version(FILE *stream);
void print_version_full(void);
void usage(void);

Expand Down
6 changes: 3 additions & 3 deletions src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2957,10 +2957,10 @@ int main(int argc, char **argv, char **envp) {
}
EUID_ASSERT();

// Note: Only attempt to print non-debug information to stdout after
// all profiles have been loaded (because a profile may set arg_quiet)
// Note: Only attempt to print non-debug information after all profiles
// have been loaded (because a profile may set arg_quiet)
if (!arg_quiet)
print_version();
print_version(stderr);

// block X11 sockets
if (arg_x11_block)
Expand Down
8 changes: 4 additions & 4 deletions src/firejail/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,16 @@ static const char *const usage_str =
"License GPL version 2 or later\n"
"Homepage: https://firejail.wordpress.com\n";

void print_version(void) {
printf("firejail version %s\n\n", VERSION);
void print_version(FILE *stream) {
fprintf(stream, "firejail version %s\n\n", VERSION);
}

void print_version_full(void) {
print_version();
print_version(stdout);
print_compiletime_support();
}

void usage(void) {
print_version();
print_version(stdout);
puts(usage_str);
}

0 comments on commit ebc9662

Please sign in to comment.