Skip to content

Commit 9819e44

Browse files
committed
improve check-user-slice-on-shutdown
1 parent d20051e commit 9819e44

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

usr/libexec/usability-misc/check-user-slice-on-shutdown

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@ source /usr/libexec/helper-scripts/light_sleep.bsh
1616
counter=0
1717
while (( counter < 10 )); do
1818
light_sleep 1
19+
## TODO: Add a comment: Is '2>&1' a good idea here?
1920
systemd_cgls_output="$(systemd-cgls --no-pager --full --unit user.slice)"
20-
if [ "$(wc -l <<< "$systemd_cgls_output")" == '1' ]; then
21+
number_of_lines="$(wc -l <<< "$systemd_cgls_output")"
22+
if [ "$number_of_lines" == '0' ]; then
23+
printf '%s\n' "$0: ERROR: Number of lines: '$number_of_lines' - Existing." >&2
24+
exit 1
25+
fi
26+
if [ "$number_of_lines" == '1' ]; then
27+
## Example systemd_cgls_output:
28+
## > Unit user.slice (/user.slice):
29+
printf '%s\n' "$0: INFO: Number of lines: '$number_of_lines'"
2130
printf '%s\n' "$0: INFO: End. OK."
2231
exit 0
2332
fi
24-
printf '%s\n' "$0: WARNING: user.slice is not empty yet. Contents:" >&2
33+
printf '%s\n' "$0: WARNING: 'user.slice' is not empty yet. (number of lines: '$number_of_lines') Contents:" >&2
2534
printf '%s\n' "$systemd_cgls_output" >&2
35+
printf '%s\n' "$0: --------------------------------------------------" >&2
36+
printf '%s\n' "$0: WARNING: 'user.slice' was not empty yet. (number of lines: '$number_of_lines')" >&2
2637
done
2738

28-
printf '%s\n' "$0: ERROR: user.slice not empty after 10 seconds!" >&2
39+
printf '%s\n' "$0: ERROR: 'user.slice' not empty after 10 seconds!" >&2
2940
exit 1

0 commit comments

Comments
 (0)