How to prevent udev from queueing up events?

I have a udev rule that starts an application via a shell script. When the udev rule is called twice in a row and as soon as I close the application, it is started again. How can I prevent this?

I want to run this script when I press a button on by stylus. I connects via bluetooth when the button is pressed. The script shall run the app, when the app is not running or maximize and focus it, when it is running. Problem is that I can only call the script once and the udev events are queueing up when I press a second time. As soon as I close the app, it restarts due to the queued up event. I also tried putting xournalpp &, but then the app is killed as soon as the udev rule terminates I assume. I have posted in multiple forums. No one seems to know a solution. I have tried nohup and flock -n. They all work when I call the script from bash, but not when it is called from the udev rule.

My best guess for now would be to use flock on the call of xournalpp in the script and then prevent udev somehow from queueing up events. Or maybe use a systemd unit that processes the udev rule, so the app doesn’t get terminated then using xournalpp &. I have no idea if that is possible, but I read that by using a unit, it doesn’t terminate.

ACTION=="add" \
, SUBSYSTEM=="bluetooth" \
, ATTRS{idProduct}=="0002"\
, ATTRS{idVendor}=="1d6b"\
, ENV{DISPLAY}=":0" \
, ENV{HOME}="/home/user/" \
, RUN+="/home/user/runXournalpp"

  if pgrep xournalpp
          echo Xournal++ is running
          wmctrl -x -a com.github.xournalpp.xournalpp
          wmctrl -x -r com.github.xournalpp.xournalpp -b "add,maximized_vert,maximized_horz"     
          echo Xournal++ is not running

You should be a lot more precise with what you are doing. Share the udev rule, share the script, share your intentions, etc.

I found a workaround here at last. You need a second script that calls the script with

echo /path/to/script | at now

This script has to be called from the udev rule. For it to work at has to be installed and you have to enable atd by calling sudo systemctl enable atd --now. It is a little hacky, but at least it works.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.