5 # Limit the maximum journal size
6 trap "journalctl --rotate --vacuum-size=16M" EXIT
8 # Rotation/flush test, see https://github.com/systemd/systemd/issues/19895
9 journalctl
--relinquish-var
11 dd if=/dev
/urandom bs
=1M count
=1 | base64 | systemd-cat
17 # Reset the ratelimit buckets for the subsequent tests below.
18 systemctl restart systemd-journald
23 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
25 printf $
'\n\n\n' | systemd-cat
-t "$ID" --level-prefix false
27 journalctl
-b -o cat -t "$ID" >/output
30 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
32 printf $
'<5>\n<6>\n<7>\n' | systemd-cat
-t "$ID" --level-prefix true
34 journalctl
-b -o cat -t "$ID" >/output
37 # Remove trailing spaces
38 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
39 printf "Trailing spaces\n">/expected
40 printf $
'<5>Trailing spaces \t \n' | systemd-cat
-t "$ID" --level-prefix true
42 journalctl
-b -o cat -t "$ID" >/output
45 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
46 printf "Trailing spaces\n">/expected
47 printf $
'Trailing spaces \t \n' | systemd-cat
-t "$ID" --level-prefix false
49 journalctl
-b -o cat -t "$ID" >/output
52 # Don't remove leading spaces
53 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
54 printf $
' \t Leading spaces\n'>/expected
55 printf $
'<5> \t Leading spaces\n' | systemd-cat
-t "$ID" --level-prefix true
57 journalctl
-b -o cat -t "$ID" >/output
60 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
61 printf $
' \t Leading spaces\n'>/expected
62 printf $
' \t Leading spaces\n' | systemd-cat
-t "$ID" --level-prefix false
64 journalctl
-b -o cat -t "$ID" >/output
67 # --output-fields restricts output
68 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
69 printf $
'foo' | systemd-cat
-t "$ID" --level-prefix false
71 journalctl
-b -o export --output-fields=MESSAGE
,FOO
--output-fields=PRIORITY
,MESSAGE
-t "$ID" >/output
72 [[ $
(grep -c .
/output
) -eq 6 ]]
73 grep -q '^__CURSOR=' /output
74 grep -q '^MESSAGE=foo$' /output
75 grep -q '^PRIORITY=6$' /output
76 grep '^FOO=' /output
&& { echo 'unexpected success'; exit 1; }
77 grep '^SYSLOG_FACILITY=' /output
&& { echo 'unexpected success'; exit 1; }
79 # `-b all` negates earlier use of -b (-b and -m are otherwise exclusive)
80 journalctl
-b -1 -b all
-m >/dev
/null
82 # -b always behaves like -b0
83 journalctl
-q -b-1 -b0 |
head -1 >/expected
84 journalctl
-q -b-1 -b |
head -1 >/output
86 # ... even when another option follows (both of these should fail due to -m)
87 { journalctl
-ball -b0 -m 2>&1 ||
:; } |
head -1 >/expected
88 { journalctl
-ball -b -m 2>&1 ||
:; } |
head -1 >/output
91 # https://github.com/systemd/systemd/issues/13708
92 ID
=$
(systemd-id128 new
)
93 systemd-cat
-t "$ID" bash
-c 'echo parent; (echo child) & wait' &
97 # We can drop this grep when https://github.com/systemd/systemd/issues/13937
99 journalctl
-b -o export -t "$ID" --output-fields=_PID |
grep '^_PID=' >/output
100 [[ $
(grep -c .
/output
) -eq 2 ]]
101 grep -q "^_PID=$PID" /output
102 grep -vq "^_PID=$PID" /output
104 # https://github.com/systemd/systemd/issues/15654
105 ID
=$
(journalctl
--new-id128 |
sed -n 2p
)
106 printf "This will\nusually fail\nand be truncated\n">/expected
107 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;'
109 journalctl
-b -o cat -t "$ID" >/output
110 cmp /expected
/output
111 [[ $
(journalctl
-b -o cat -t "$ID" --output-fields=_TRANSPORT |
grep -Pc "^stdout$") -eq 3 ]]
112 [[ $
(journalctl
-b -o cat -t "$ID" --output-fields=_LINE_BREAK |
grep -Pc "^pid-change$") -eq 3 ]]
113 [[ $
(journalctl
-b -o cat -t "$ID" --output-fields=_PID |
sort -u |
grep -c "^.*$") -eq 3 ]]
114 [[ $
(journalctl
-b -o cat -t "$ID" --output-fields=MESSAGE |
grep -Pc "^(This will|usually fail|and be truncated)$") -eq 3 ]]
116 # test that LogLevelMax can also suppress logging about services, not only by services
117 systemctl start silent-success
119 [[ -z "$(journalctl -b -q -u silent-success.service)" ]]
121 # Add new tests before here, the journald restarts below
122 # may make tests flappy.
124 # Don't lose streams on restart
125 systemctl start forever-print-hola
127 systemctl restart systemd-journald
129 systemctl stop forever-print-hola
130 [[ ! -f "/i-lose-my-logs" ]]
132 # https://github.com/systemd/systemd/issues/4408
133 rm -f /i-lose-my-logs
134 systemctl start forever-print-hola
136 systemctl
kill --signal=SIGKILL systemd-journald
138 [[ ! -f "/i-lose-my-logs" ]]
140 # https://github.com/systemd/systemd/issues/15528
141 journalctl
--follow --file=/var
/log
/journal
/*/* |
head -n1 ||
[[ $?
-eq 1 ]]