Score:3

How to 'strace' a systemd service on startup?

sa flag

I'm working on an embedded system running a stripped down version of Ubuntu 22.04. We've recently updated some hardware in the embedded system and I'm working on getting our Ubuntu image working on the new hardware.

On the old hardware the pulseaudio service always ran without any issues, but on the new hardware I'm having an issue with pulseaudio not detecting Alsa card 0 when the service starts during boot. If I restart the service via systemctl --user restart pulseaudio.service then it does detect Alsa card 0 and everything works.

My suspicion is that pulseaudio is checking for the existence of a character device in /dev/snd/ or maybe the presence of a file/folder in /proc/asound/, but the device or file it's looking for does not exist yet and is created later by a kernel module being loaded.

To try to verify my suspicions, I'm trying to run strace on the service during boot. I've updated /usr/lib/systemd/user/pulseaudio.service and changed the the ExecStart line as follows:

ExecStart=strace -e trace=file -o /home/user/trace_erronly_fail.log -Z -f -tt /usr/bin/pulseaudio --daemonize=no --log-target=journal --log-level=debug

After running systemctl --user daemon-reload, I try starting the service to test that the strace will work, but the service fails to start. The service status reports the following:

x pulseaudio.service - Sound Service
     Loaded: loaded (/usr/lib/systemd/user/pulseaudio.service; enabled; vendor preset: enabled)
     Active: failed (Result: core-dump) since Wed 2023-04-19 12:33:21 UTC; 2s ago
TriggeredBy: x pulseaudio.socket
    Process: 1673 ExecStart=strace -e trace=file -o /home/user/trace_erronly_fail.log -Z -f -tt /usr/bin/pulseaudio --daemonize=no --log-target=journal --log-level=debug (code=dumped, signal=SYS)
   Main PID: 1673 (code=dumped, signal=SYS)
        CPU: 49ms

Apr 19 12:33:21 Ubuntu-V8 systemd[780]: pulseaudio.service: Scheduled restart job, restart counter is at 5.
Apr 19 12:33:21 Ubuntu-V8 systemd[780]: Stopped Sound Service.
Apr 19 12:33:21 Ubuntu-V8 systemd[780]: pulseaudio.service: Start request repeated too quickly.
Apr 19 12:33:21 Ubuntu-V8 systemd[780]: pulseaudio.service: Failed with result 'core-dump'.
Apr 19 12:33:21 Ubuntu-V8 systemd[780]: Failed to start Sound Service.

Seems like it's raising a SIGSYS signal, which according to man 7 signal is raised when there's a bad system call.

I'm not really sure why it's having this issue. I am able to run the ExecStart command manually without it raising the SIGSYS signal, so it only does it when it's run as a systemd service.

So, how can I get strace to work when run as a systemd service?

Score:1
sa flag

It turns out that systemd services have a list of permitted system calls. If a service attempts a system call that isn't permitted, the process is terminated with a SIGSYS signal.

To tell systemd to allow the process to execute any system call, you need to update the .service file and add the following under the [Service] section:

SystemCallFilter=@known

Then, just do a systemctl --user daemon-reload followed by systemctl --user start pulseaudio.service (omit --user for system services) and it should start right up.

For more information on the SystemCallFilter parameter, refer to man 5 systemd.exec.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.