0

From man udev

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.

I'm doing this:

KERNEL=="sd[a-z]", SUBSYSTEM=="block", ATTR{ro}=="0", ATTR{removable}=="1", SUBSYSTEMS=="usb", DRIVERS=="usb-storage", SYMLINK+="usb_%E{ID_VENDOR}_%E{ID_MODEL}_%E{ID_SERIAL_SHORT}"
ACTION=="add", KERNEL=="sd[a-z]", SUBSYSTEM=="block", ATTR{ro}=="0", ATTR{removable}=="1", SUBSYSTEMS=="usb", DRIVERS=="usb-storage", RUN+="/usr/bin/setsid /usr/bin/nautilus"

Setsid does run a program in a new session

I am running X as: root 937 1.4 1.3 179992 26328 tty2 S via xinit /root/.xinitrc

  • How is it failing? What were you expecting to see and what actually happened? – terdon Sep 21 '15 at 12:25
  • I am not really into udev, but how is the user determined? Doesn't this start nautilus as root and failes, because of no xsession defined? – Jodka Lemon Sep 21 '15 at 13:41
  • I tried with --display localhost:0.0 and it worked - thanks! –  Sep 21 '15 at 14:11
  • I modified the question to reflect "the user determined" bit.. I just run as root, but I was wondering if there's a way to have udev drop privileges on Nautilus by detecting the user of X. I just login at console and start X from .profile –  Sep 21 '15 at 14:15
  • or I could delete the question.. –  Sep 21 '15 at 14:15

1 Answers1

0

To run an X11 program, you need to tell it where to put its windows. This is done through the DISPLAY environment variable.

If there is a user logged in on the console, the corresponding display is usually :0 (but there can be more than one, and :0 can be used for non-console X servers). So you would need to run a script containing

#!/bin/sh
export DISPLAY=:0
setsid nautilus &

You might need to set XAUTHORITY in addition to DISPLAY.

But this is the wrong approach. What do you do if there's no user logged in on the console? What if there are multiple users on the console? What if the X cookie file is on a FUSE filesystem that root can't access directly?

There's a mechanism that allows udev to notify desktop applications: D-Bus. Many desktop environments use it to arrange for a file manager window to pop up when a removable device is inserted. I don't know exactly how it works, but this is what you need to research.