1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 10:25:37 +03:00
systemd/test/units/testsuite-07.pr-31351.sh
Mike Yuan 80b18d217a
core/exec-invoke: record correct exit status when failed to locate executable
Follow-up for 4d8b0f0f7a

After the mentioned commit, when the ExecCommand executable is missing,
and failure will be ignored by manager, we exit with EXIT_SUCCESS at executor
side too. The behavior however contradicts systemd.service(5), which states:

> If the executable path is prefixed with "-", an exit code of the command
> normally considered a failure (i.e. non-zero exit status or abnormal exit
> due to signal is _recorded_, but has no further effect and is considered
> equivalent to success.

and thus makes debugging unexpected failures harder. Therefore, let's still
exit with EXIT_EXEC, but just skip LOG_ERR level log.
2024-02-19 23:12:59 +08:00

23 lines
733 B
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
set -o pipefail
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
cat >/run/systemd/system/nonexistent-execstart-exit-status.service <<EOF
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=-/foo/bar/not-exist
EOF
systemctl start nonexistent-execstart-exit-status.service
systemctl is-active nonexistent-execstart-exit-status.service
assert_eq "$(systemctl show nonexistent-execstart-exit-status.service -P Result)" "success"
(( $(systemctl show nonexistent-execstart-exit-status.service -P ExecMainStatus) > 0 ))
systemctl stop nonexistent-execstart-exit-status.service
rm /run/systemd/system/nonexistent-execstart-exit-status.service