mirror of
https://github.com/systemd/systemd.git
synced 2025-01-09 01:18:19 +03:00
journalctl: make --invocation and --list-invocations accept unit name without suffix
Fixes #35538.
This commit is contained in:
parent
d1ecd61176
commit
e8823b5e35
@ -10,6 +10,7 @@
|
||||
#include "rlimit-util.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "unit-name.h"
|
||||
|
||||
char* format_timestamp_maybe_utc(char *buf, size_t l, usec_t t) {
|
||||
assert(buf);
|
||||
@ -113,6 +114,7 @@ int journal_acquire_boot(sd_journal *j) {
|
||||
|
||||
int acquire_unit(const char *option_name, const char **ret_unit, LogIdType *ret_type) {
|
||||
size_t n;
|
||||
int r;
|
||||
|
||||
assert(option_name);
|
||||
assert(ret_unit);
|
||||
@ -128,15 +130,26 @@ int acquire_unit(const char *option_name, const char **ret_unit, LogIdType *ret_
|
||||
"Using %s with multiple units is not supported.",
|
||||
option_name);
|
||||
|
||||
LogIdType type;
|
||||
char **units;
|
||||
if (!strv_isempty(arg_system_units)) {
|
||||
*ret_type = LOG_SYSTEM_UNIT_INVOCATION_ID;
|
||||
*ret_unit = arg_system_units[0];
|
||||
type = LOG_SYSTEM_UNIT_INVOCATION_ID;
|
||||
units = arg_system_units;
|
||||
} else {
|
||||
assert(!strv_isempty(arg_user_units));
|
||||
*ret_type = LOG_USER_UNIT_INVOCATION_ID;
|
||||
*ret_unit = arg_user_units[0];
|
||||
type = LOG_USER_UNIT_INVOCATION_ID;
|
||||
units = arg_user_units;
|
||||
}
|
||||
|
||||
_cleanup_free_ char *u = NULL;
|
||||
r = unit_name_mangle(units[0], arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, &u);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to mangle unit name '%s': %m", units[0]);
|
||||
|
||||
free_and_replace(units[0], u);
|
||||
|
||||
*ret_type = type;
|
||||
*ret_unit = units[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,8 @@ set -o pipefail
|
||||
# shellcheck source=test/units/util.sh
|
||||
. "$(dirname "$0")"/util.sh
|
||||
|
||||
SERVICE_NAME=invocation-id-test-"$RANDOM".service
|
||||
SERVICE_NAME_SHORT=invocation-id-test-"$RANDOM"
|
||||
SERVICE_NAME="$SERVICE_NAME_SHORT".service
|
||||
|
||||
TMP_DIR=$(mktemp -d)
|
||||
|
||||
@ -26,6 +27,7 @@ done
|
||||
# systemd[1]: invocation-id-test-26448.service: Deactivated successfully.
|
||||
journalctl --sync
|
||||
|
||||
journalctl --list-invocation -u "$SERVICE_NAME_SHORT" | tee "$TMP_DIR"/short
|
||||
journalctl --list-invocation -u "$SERVICE_NAME" | tee "$TMP_DIR"/10
|
||||
journalctl --list-invocation -u "$SERVICE_NAME" --reverse | tee "$TMP_DIR"/10-r
|
||||
journalctl --list-invocation -u "$SERVICE_NAME" -n +10 | tee "$TMP_DIR"/p10
|
||||
@ -44,6 +46,7 @@ journalctl --list-invocation -u "$SERVICE_NAME" -n +5 --reverse | tee "$TMP_DIR"
|
||||
[[ $(cat "$TMP_DIR"/p5 | wc -l) == 6 ]]
|
||||
[[ $(cat "$TMP_DIR"/p5-r | wc -l) == 6 ]]
|
||||
|
||||
diff "$TMP_DIR"/10 "$TMP_DIR"/short
|
||||
diff <(tail -n 10 "$TMP_DIR"/10 | tac) <(tail -n 10 "$TMP_DIR"/10-r)
|
||||
diff <(tail -n 5 "$TMP_DIR"/10) <(tail -n 5 "$TMP_DIR"/5)
|
||||
diff <(tail -n 5 "$TMP_DIR"/10 | tac) <(tail -n 5 "$TMP_DIR"/5-r)
|
||||
@ -54,6 +57,8 @@ diff <(tail -n 10 "$TMP_DIR"/p10 | head -n 5 | tac) <(tail -n 5 "$TMP_DIR"/p5-r)
|
||||
tail -n 10 "$TMP_DIR"/10 |
|
||||
while read -r idx invocation _; do
|
||||
i="$(( idx + 10 ))"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${i}" -u "$SERVICE_NAME_SHORT")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${idx}" -u "$SERVICE_NAME_SHORT")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${i}" -u "$SERVICE_NAME")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${idx}" -u "$SERVICE_NAME")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${invocation}")"
|
||||
@ -62,6 +67,8 @@ tail -n 10 "$TMP_DIR"/10 |
|
||||
tail -n 10 "$TMP_DIR"/p10 |
|
||||
while read -r i invocation _; do
|
||||
idx="$(( i - 10 ))"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${i}" -u "$SERVICE_NAME_SHORT")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${idx}" -u "$SERVICE_NAME_SHORT")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${i}" -u "$SERVICE_NAME")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${idx}" -u "$SERVICE_NAME")"
|
||||
assert_in "invocation ${i} ${invocation}" "$(journalctl --no-hostname -n 1 -t bash --invocation="${invocation}")"
|
||||
|
Loading…
Reference in New Issue
Block a user