#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);
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);
"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;
}
# 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)
# 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
[[ $(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)
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}")"
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}")"