You are not logged in.

#1 2018-03-18 11:46:59

JohnDVD
Member
Registered: 2011-11-29
Posts: 39

udev rules - load program

I wrote a driver program in C that has to run endlessly to read sensors and invoke calls.
The driver should start via udev-rule, but it does not. The script should end with exitcode 0 after a few milliseconds, so the udev rule should execute properly.
However, I need a delay to get the symlink done correctly, so the driver runs properly.

KERNEL=="hidraw*", ATTRS{idVendor}=="1d34", MODE="0666", SYMLINK+="bigredbutton", OWNER="user1", GROUP="users", RUN+="/usr/script/bigredbutton_start.sh"

the script

#!/bin/bash
chown -h user1:users /dev/bigredbutton
nohup bash -c "sleep 5 ; su -l user1 -c /usr/script/bigredbutton" </dev/null &>/dev/null &

The problem: the driver program "bigredbutton" is not loaded as it should, or does not remain in the memory.
Please give me any hints. Thanks.

Greetz
JD

Offline

#2 2018-03-19 09:11:06

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: udev rules - load program

Using a udev rule to start a background process doesn't work; see 'man udev':

RUN{type}
...
           This can only be used for very short-running foreground tasks. Running an event process for a long period of time may block all further events for this or a dependent device.

           Starting daemons or other long-running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished.
...

Maybe you can keep the udev rule to create the simlink, but it seems you need an 'ACTION==add' in it, not sure.
For starting the script, you can use a systemd service if the script needs to be run at boot, adding conditions to test the existence of what is required.

Offline

Board footer

Powered by FluxBB