[systemd-devel] a service depending on a sound card

me at beroal.in.ua me at beroal.in.ua
Wed Jun 15 13:12:10 UTC 2016


Hello. I want to create a service that starts after a specific sound 
card is active. I have 2 sound cards, you can see them in the output 
below. The service file contains
{{{
[Unit]
After=sound.target
After=sys-devices-pci0000:00-0000:00:05.0-sound-card0.device
}}}
But when the service starts, the device files of Card 0 are absent in 
"/dev/snd". To debug, I added the following shell script to the service.
{{{
function print_status {
     echo "/dev:"
     ls -l /dev/snd
     systemctl status sys-devices-pci0000:00-0000:00:05.0-sound-card0.device
     echo "/sys 0:"
     ls -l /sys/devices/pci0000:00/0000:00:05.0/sound/card0
}
print_status
systemctl status sound.target
print_status
}}}
And this is its output:
{{{
/dev:
total 0
drwxr-xr-x 2 root root       60 Jun 15 13:21 by-path
crw-rw---- 1 root audio 116,  2 Jun 15 13:21 controlC1
crw-rw---- 1 root audio 116,  4 Jun 15 13:21 hwC1D0
crw-rw---- 1 root audio 116,  3 Jun 15 13:21 pcmC1D3p
crw-rw---- 1 root audio 116,  1 Jun 15 13:21 seq
crw-rw---- 1 root audio 116, 33 Jun 15 13:21 timer
* sys-devices-pci0000:00-0000:00:05.0-sound-card0.device
    Loaded: loaded
    Active: inactive (dead)
/sys 0:
ls: cannot access '/sys/devices/pci0000:00/0000:00:05.0/sound/card0': No 
such file or directory
* sound.target - Sound Card
    Loaded: loaded (/usr/lib/systemd/system/sound.target; static; vendor 
preset: disabled)
    Active: active since Wed 2016-06-15 13:21:01 EEST; 912ms ago
      Docs: man:systemd.special(7)

Jun 15 13:21:01 beroal systemd[1]: Reached target Sound Card.
/dev:
total 0
drwxr-xr-x 2 root root       80 Jun 15 13:21 by-path
crw-rw---- 1 root audio 116,  5 Jun 15 13:21 controlC0
crw-rw---- 1 root audio 116,  2 Jun 15 13:21 controlC1
crw-rw---- 1 root audio 116, 10 Jun 15 13:21 hwC0D0
crw-rw---- 1 root audio 116,  4 Jun 15 13:21 hwC1D0
crw-rw---- 1 root audio 116,  7 Jun 15 13:21 pcmC0D0c
crw-rw---- 1 root audio 116,  6 Jun 15 13:21 pcmC0D0p
crw-rw---- 1 root audio 116,  8 Jun 15 13:21 pcmC0D1p
crw-rw---- 1 root audio 116,  9 Jun 15 13:21 pcmC0D2c
crw-rw---- 1 root audio 116,  3 Jun 15 13:21 pcmC1D3p
lrwxrwxrwx 1 root root        9 Jun 15 13:21 perm-mb -> controlC0
crw-rw---- 1 root audio 116,  1 Jun 15 13:21 seq
crw-rw---- 1 root audio 116, 33 Jun 15 13:21 timer
* sys-devices-pci0000:00-0000:00:05.0-sound-card0.device - MCP61 High 
Definition Audio
    Loaded: loaded
    Active: active (plugged) since Wed 2016-06-15 13:21:02 EEST; 711ms ago
    Device: /sys/devices/pci0000:00/0000:00:05.0/sound/card0
/sys 0:
total 0
drwxr-xr-x 3 root root    0 Jun 15 13:21 controlC0
lrwxrwxrwx 1 root root    0 Jun 15 13:21 device -> ../../../0000:00:05.0
drwxr-xr-x 3 root root    0 Jun 15 13:21 hwC0D0
-rw-r--r-- 1 root root 4096 Jun 15 13:21 id
drwxr-xr-x 6 root root    0 Jun 15 13:21 input12
drwxr-xr-x 6 root root    0 Jun 15 13:21 input13
drwxr-xr-x 6 root root    0 Jun 15 13:21 input14
-r--r--r-- 1 root root 4096 Jun 15 13:21 number
drwxr-xr-x 3 root root    0 Jun 15 13:21 pcmC0D0c
drwxr-xr-x 3 root root    0 Jun 15 13:21 pcmC0D0p
drwxr-xr-x 3 root root    0 Jun 15 13:21 pcmC0D1p
drwxr-xr-x 3 root root    0 Jun 15 13:21 pcmC0D2c
drwxr-xr-x 2 root root    0 Jun 15 13:21 power
lrwxrwxrwx 1 root root    0 Jun 15 13:21 subsystem -> 
../../../../../class/sound
-rw-r--r-- 1 root root 4096 Jun 15 13:21 uevent
}}}

Questions.
0. When "sound.target" is supposed to be active, when any sound card is 
active or when all sound cards are active?
1. Why the service starts when Card 0 is inactive?
2. Why "systemctl status sound.target" waits until Card 0 is active? It 
does not make sense.



More information about the systemd-devel mailing list