mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-27 18:55:09 +03:00
journalctl: return a non-zero EC when --grep returns no matches
When journalctl is compiled with PCRE2 support, let's return a non-zero exit code when --grep is used and no match for given pattern is found. This should allow users to use journalctl --grep in scripts instead of piping journalctl into grep Fixes #8152
This commit is contained in:
parent
8688c29b5a
commit
6cda6774bd
@ -2678,8 +2678,16 @@ finish:
|
||||
free(arg_verify_key);
|
||||
|
||||
#if HAVE_PCRE2
|
||||
if (arg_compiled_pattern)
|
||||
if (arg_compiled_pattern) {
|
||||
pcre2_code_free(arg_compiled_pattern);
|
||||
|
||||
/* --grep was used, no error was thrown, but the pattern didn't
|
||||
* match anything. Let's mimic grep's behavior here and return
|
||||
* a non-zero exit code, so journalctl --grep can be used
|
||||
* in scripts and such */
|
||||
if (r == 0 && n_shown == 0)
|
||||
r = -ENOENT;
|
||||
}
|
||||
#endif
|
||||
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
Loading…
Reference in New Issue
Block a user