0

I am trying to launch a GUI app upon plugging in a certain USB device. The udev rule gets triggered, but the app does appear on my screen. Running the script from another TTY makes the app open in my graphical environment. I can also confirm that the rule is getting triggered by appending a date to a file from the rule.

/etc/udev/rules.d/99-betaflight.rules:

SUBSYSTEMS=="usb", ATTR{serial}=="314839673237", RUN+="/usr/bin/su daniel -c '/home/daniel/bin/betaflight-configurator'"

/home/daniel/bin/betaflight-configurator:

#!/bin/bash

export DISPLAY=:1
/opt/betaflight/betaflight-configurator/betaflight-configurator

The way I understand it is that the GUI app has difficulties starting, since it's not starting in the context of the X server. Still, running the code from another tty opens the app perfectly fine.

What can I improve to make the app run upon plugging in my USB device?

1
  • (i) Did you check that your rule is actually executed ? You can do so by replacing your RUN+="..." block with RUN+="echo $(date) > /home/daniel/udev_exec.log" for instance. (ii) I would actually look at ADDITIONAL filtering on action with ACTION=="add" placed before your RUN+="..." block. That would restrict the trigger condition to you plugging-in your serial device. (iii) Also report if "/home/daniel/.Xauthority" exists in your home directory... --- There are other issues but you can start with that. Please report by editing your OP.
    – Cbhihe
    Aug 11, 2021 at 16:27

1 Answer 1

0

You should not start any long running programs from udev rules -- udevd will kill them after a short while, EVEN if you try to run them in background (with & from a script). It will also put other roadblocks in their way.

A non recommended hack could be to install the atd daemon and start them with echo some_command | at now. You will find plenty of examples of that online.

What you should actually do depends on what kind of system you have -- with a "modern" you will have no way but learn how to use systemd (shudder).

3
  • Thanks, I am quite familiar with systemd. So, would it make sense to launch my gui app as a systemd service?
    – Daniel D.
    Aug 11, 2021 at 15:49
  • Probably yes. If it's an input device, it would make more sense to start the app via the X11 input extension, which doesn't need any root privileges (search for inputplug)
    – user486445
    Aug 11, 2021 at 15:55
  • @DanielD. I beg to differ if only on principle. systemd places each service in its own session to ensure a clean execution environment for the service (see man 7 daemon). In addition it doesnot restrict execution privileges in any way. So starting a gui app as a "service would be the equivalent of daemonizing its execution, something you probably don't need/want to do, not to mention the execution privileges tacked on that "service".
    – Cbhihe
    Aug 11, 2021 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .