2020-03-04 09:35:06 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-11-17 11:21:23 +00:00
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
# Test stdout stream
|
|
|
|
|
|
|
|
# Skip empty lines
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
>/expected
|
|
|
|
printf $'\n\n\n' | systemd-cat -t "$ID" --level-prefix false
|
2015-11-27 13:55:23 +00:00
|
|
|
journalctl --sync
|
2015-11-17 11:21:23 +00:00
|
|
|
journalctl -b -o cat -t "$ID" >/output
|
|
|
|
cmp /expected /output
|
|
|
|
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
>/expected
|
|
|
|
printf $'<5>\n<6>\n<7>\n' | systemd-cat -t "$ID" --level-prefix true
|
2015-11-27 13:55:23 +00:00
|
|
|
journalctl --sync
|
2015-11-17 11:21:23 +00:00
|
|
|
journalctl -b -o cat -t "$ID" >/output
|
|
|
|
cmp /expected /output
|
|
|
|
|
2015-11-17 21:41:05 +00:00
|
|
|
# Remove trailing spaces
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
printf "Trailing spaces\n">/expected
|
|
|
|
printf $'<5>Trailing spaces \t \n' | systemd-cat -t "$ID" --level-prefix true
|
2015-11-27 13:55:23 +00:00
|
|
|
journalctl --sync
|
2015-11-17 21:41:05 +00:00
|
|
|
journalctl -b -o cat -t "$ID" >/output
|
|
|
|
cmp /expected /output
|
|
|
|
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
printf "Trailing spaces\n">/expected
|
|
|
|
printf $'Trailing spaces \t \n' | systemd-cat -t "$ID" --level-prefix false
|
2015-11-27 13:55:23 +00:00
|
|
|
journalctl --sync
|
2015-11-17 21:41:05 +00:00
|
|
|
journalctl -b -o cat -t "$ID" >/output
|
|
|
|
cmp /expected /output
|
|
|
|
|
|
|
|
# Don't remove leading spaces
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
printf $' \t Leading spaces\n'>/expected
|
|
|
|
printf $'<5> \t Leading spaces\n' | systemd-cat -t "$ID" --level-prefix true
|
2015-11-27 13:55:23 +00:00
|
|
|
journalctl --sync
|
2015-11-17 21:41:05 +00:00
|
|
|
journalctl -b -o cat -t "$ID" >/output
|
|
|
|
cmp /expected /output
|
|
|
|
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
printf $' \t Leading spaces\n'>/expected
|
|
|
|
printf $' \t Leading spaces\n' | systemd-cat -t "$ID" --level-prefix false
|
2015-11-27 13:55:23 +00:00
|
|
|
journalctl --sync
|
2015-11-17 21:41:05 +00:00
|
|
|
journalctl -b -o cat -t "$ID" >/output
|
|
|
|
cmp /expected /output
|
|
|
|
|
2017-10-27 03:10:47 +00:00
|
|
|
# --output-fields restricts output
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
printf $'foo' | systemd-cat -t "$ID" --level-prefix false
|
|
|
|
journalctl --sync
|
|
|
|
journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MESSAGE -t "$ID" >/output
|
|
|
|
[[ `grep -c . /output` -eq 6 ]]
|
|
|
|
grep -q '^__CURSOR=' /output
|
|
|
|
grep -q '^MESSAGE=foo$' /output
|
|
|
|
grep -q '^PRIORITY=6$' /output
|
2021-04-07 23:27:33 +00:00
|
|
|
grep '^FOO=' /output && { echo 'unexpected success'; exit 1; }
|
|
|
|
grep '^SYSLOG_FACILITY=' /output && { echo 'unexpected success'; exit 1; }
|
2017-10-27 03:10:47 +00:00
|
|
|
|
2019-03-07 01:20:06 +00:00
|
|
|
# `-b all` negates earlier use of -b (-b and -m are otherwise exclusive)
|
2021-04-07 22:09:55 +00:00
|
|
|
journalctl -b -1 -b all -m >/dev/null
|
2019-03-07 01:20:06 +00:00
|
|
|
|
|
|
|
# -b always behaves like -b0
|
2021-04-07 22:09:55 +00:00
|
|
|
journalctl -q -b-1 -b0 | head -1 >/expected
|
|
|
|
journalctl -q -b-1 -b | head -1 >/output
|
2019-03-07 01:20:06 +00:00
|
|
|
cmp /expected /output
|
|
|
|
# ... even when another option follows (both of these should fail due to -m)
|
2021-04-07 22:09:55 +00:00
|
|
|
{ journalctl -ball -b0 -m 2>&1 || :; } | head -1 >/expected
|
|
|
|
{ journalctl -ball -b -m 2>&1 || :; } | head -1 >/output
|
2019-03-07 01:20:06 +00:00
|
|
|
cmp /expected /output
|
|
|
|
|
2019-11-04 16:35:46 +00:00
|
|
|
# https://github.com/systemd/systemd/issues/13708
|
|
|
|
ID=$(systemd-id128 new)
|
|
|
|
systemd-cat -t "$ID" bash -c 'echo parent; (echo child) & wait' &
|
|
|
|
PID=$!
|
|
|
|
wait %%
|
|
|
|
journalctl --sync
|
|
|
|
# We can drop this grep when https://github.com/systemd/systemd/issues/13937
|
|
|
|
# has a fix.
|
|
|
|
journalctl -b -o export -t "$ID" --output-fields=_PID | grep '^_PID=' >/output
|
|
|
|
[[ `grep -c . /output` -eq 2 ]]
|
|
|
|
grep -q "^_PID=$PID" /output
|
|
|
|
grep -vq "^_PID=$PID" /output
|
|
|
|
|
2020-05-06 21:28:02 +00:00
|
|
|
# https://github.com/systemd/systemd/issues/15654
|
|
|
|
ID=$(journalctl --new-id128 | sed -n 2p)
|
|
|
|
printf "This will\nusually fail\nand be truncated\n">/expected
|
|
|
|
systemd-cat -t "$ID" /bin/sh -c 'env echo -n "This will";echo;env echo -n "usually fail";echo;env echo -n "and be truncated";echo;'
|
|
|
|
journalctl --sync
|
|
|
|
journalctl -b -o cat -t "$ID" >/output
|
|
|
|
cmp /expected /output
|
2020-05-09 10:01:07 +00:00
|
|
|
[[ $(journalctl -b -o cat -t "$ID" --output-fields=_TRANSPORT | grep -Pc "^stdout$") -eq 3 ]]
|
|
|
|
[[ $(journalctl -b -o cat -t "$ID" --output-fields=_LINE_BREAK | grep -Pc "^pid-change$") -eq 3 ]]
|
|
|
|
[[ $(journalctl -b -o cat -t "$ID" --output-fields=_PID | sort -u | grep -c "^.*$") -eq 3 ]]
|
|
|
|
[[ $(journalctl -b -o cat -t "$ID" --output-fields=MESSAGE | grep -Pc "^(This will|usually fail|and be truncated)$") -eq 3 ]]
|
2020-05-06 21:28:02 +00:00
|
|
|
|
2019-11-04 16:35:46 +00:00
|
|
|
# Add new tests before here, the journald restarts below
|
|
|
|
# may make tests flappy.
|
|
|
|
|
2015-12-30 03:33:43 +00:00
|
|
|
# Don't lose streams on restart
|
|
|
|
systemctl start forever-print-hola
|
|
|
|
sleep 3
|
|
|
|
systemctl restart systemd-journald
|
|
|
|
sleep 3
|
|
|
|
systemctl stop forever-print-hola
|
|
|
|
[[ ! -f "/i-lose-my-logs" ]]
|
|
|
|
|
2016-10-20 13:18:12 +00:00
|
|
|
# https://github.com/systemd/systemd/issues/4408
|
|
|
|
rm -f /i-lose-my-logs
|
|
|
|
systemctl start forever-print-hola
|
|
|
|
sleep 3
|
|
|
|
systemctl kill --signal=SIGKILL systemd-journald
|
|
|
|
sleep 3
|
|
|
|
[[ ! -f "/i-lose-my-logs" ]]
|
|
|
|
|
2020-04-22 17:22:40 +00:00
|
|
|
# https://github.com/systemd/systemd/issues/15528
|
|
|
|
journalctl --follow --file=/var/log/journal/*/* | head -n1 || [[ $? -eq 1 ]]
|
|
|
|
|
2015-11-17 11:21:23 +00:00
|
|
|
touch /testok
|