udev triggered service not able to run sh script
0
votes
1
answer
64
views
I am working on a service to capture device-mapper dm-verity uevent. However, I am not able to figure out why the service is able to be triggered but fails to run my logger script.
I have the following rules (
/etc/udev/rules.d/dm-verity.rules
) based on [this discussion](https://github.com/systemd/systemd/issues/15855#issue-621269603) (newline added for readability):
KERNEL=="dm-[0-9]*", \
ACTION=="change", \
SUBSYSTEM=="block", \
ENV{DM_VERITY_ERR_BLOCK_NR}!="", \
TAG+="systemd", \
ENV{SYSTEMD_WANTS}+="dm-verity.service"
I have the following service (/etc/systemd/system/dm-verity.service
):
[Unit]
Description=dm-verity uevent logger
[Service]
Type=forking
ExecStart=/usr/bin/dm-verity_log_error.sh
I have the following script (/usr/bin/dm-verity_log_error.sh
):
#!/bin/bash
echo "dm-verity occurs" | my-logger-adaptor
exit 0
I can confirm from journal that the dm-verity.rules
and dm-verity.service
is triggered, however, it fails when it tries to execute dm-verity_log_error.sh
. Journal log snippet as follows.
systemd: dm-verity.service: About to execute: /bin/bash -c /usr/bin/dm-verity_log_error.sh
systemd: dm-verity.service: Forked /bin/bash as 19823
systemd: dm-verity.service: Kernel keyring not supported, ignoring.
systemd: dm-verity.service: Executing: /bin/bash -c /usr/bin/dm-verity_log_error.sh
systemd: dm-verity.service: Changed dead -> start
systemd: Starting dm-verity uevent logger
systemd: dm-verity.service: cgroup is empty
audit: ANOM_ABEND auid=4294967295 uid=0 gid=0 ses=4294967295 pid=19823 comm="bash" exe="/bin/bash.bash" sig=11 res=1
systemd: Received SIGCHLD from PID 19823 (bash).
systemd: Child 19823 (bash) died (code=killed, status=11/SEGV)
systemd: dm-verity.service: Child 19823 belongs to dm-verity.service.
systemd: dm-verity.service: Main process exited, code=killed, status=11/SEGV
systemd: dm-verity.service: Failed with result 'signal'.
systemd: dm-verity.service: Changed start -> failed
systemd: dm-verity.service: Job dm-verity.service/start finished, result=failed
systemd: Failed to start dm-verity uevent logger
From the logs, it seem like there is an error when executing the bash shell to run the script (code=killed, status=11/SEGV
) but I am not quite sure the cause of it. Any pointer to some documents or possible solutions on the problem?
My thoughts on what might be the cause:
1. Maybe it is because of systemd.exec
executing the command in sandbox environment so that the bash shell does not has all of the necessary environment ([reference 1](https://unix.stackexchange.com/a/642714/676447)
2. Maybe I invoke dm-verity_log_error.sh
incorrectly in ExecStart=
attribute field. Starting the service with systemctl start dm-verity.service
is successful. I did some other test with ExecStart=/bin/ls
and it can also run successfully when triggered by the rules.
3. Maybe dm-verity_log_error.sh
did run, but ends too quickly. However, I am not sure if the main process in the journal is referring to the dm-verity.service
that finished or referring to the `dm-verity_log_error.sh
script itself.
I have tried to search for similar problem online but have not find one quite that match my problem. Maybe I am using the wrong keyword to search. I have read the following reference so far:
- [udev rules to trigger systemd service](https://unix.stackexchange.com/questions/550279/udev-rule-to-trigger-systemd-service)
- [how udev works](https://unix.stackexchange.com/a/551047/676447)
- [how to start service with udev event](https://blog.fraggod.net/2012/06/16/proper-ish-way-to-start-long-running-systemd-service-on-udev-event-device-hotplug.html)
I am using a development board running Yocto 2.6, and systemd 239.
Asked by semicolon
(1 rep)
Nov 19, 2024, 03:13 PM
Last activity: Jan 7, 2025, 08:57 AM
Last activity: Jan 7, 2025, 08:57 AM