You are not logged in.
hello,
running 5.11.16-arch1-1 with xorg-server 1.20.11-1 / i3-gaps 4.19.1-1
1. trying to set up a udev rule which launches a script upon DVD insertion.
/etc/udev/rules.d/dvd-insert.rules contains:
ACTION=="change", KERNEL=="sr[0-9]*", ENV{ID_CDROM_DVD}=="1", ENV{ID_CDROM_MEDIA_STATE}=="complete", ENV{ID_FS_TYPE}=="udf", RUN+="/home/user/DVD/insert.sh"
ACTION=="change", KERNEL=="sr[0-9]*", ENV{ID_CDROM_DVD}=="1", ENV{ID_CDROM_MEDIA_STATE}=="complete", ENV{ID_FS_TYPE}=="iso9660", RUN+="/home/user/DVD/insert.sh"after updating the rules file udevadm is reloaded:
udevadm control --reload2. insert.sh is a launcher script which works correctly when run in i3 or in a tty console:
#!/bin/bash
screen -dm urxvt -e /home/user/DVD/DVD.sh3. unfortunately nothing happens when a dvd is inserted. running the udevadm test shows that the dvd-insert.rules file is being processed:
udevadm test $(udevadm info --query=path --name=/dev/sr0) 2>&1 | grep dvd-insert.rulesreturns:
Reading rules file: /etc/udev/rules.d/dvd-insert.rulesany help is greatly appreciated. here is the udevadm monitor response when a DVD is inserted if it is of use:
sudo udevadm monitor --environment --udevreturns
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
UDEV [19436.115578] change /devices/pci0000:00/0000:00:01.2/0000:02:00.0/0000:03:09.0/0000:07:00.0/ata3/host2/target2:0:0/2:0:0:0/block/sr0 (block)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:01.2/0000:02:00.0/0000:03:09.0/0000:07:00.0/ata3/host2/target2:0:0/2:0:0:0/block/sr0
SUBSYSTEM=block
DISK_MEDIA_CHANGE=1
DEVNAME=/dev/sr0
DEVTYPE=disk
SEQNUM=4971
USEC_INITIALIZED=2120860
ID_CDROM=1
SYSTEMD_MOUNT_DEVICE_BOUND=1
ID_CDROM_CD_R=1
ID_CDROM_CD_RW=1
ID_CDROM_DVD=1
ID_CDROM_DVD_R=1
ID_CDROM_DVD_RAM=1
ID_CDROM_DVD_PLUS_R_DL=1
ID_CDROM_DVD_PLUS_R=1
ID_CDROM_DVD_PLUS_RW=1
ID_CDROM_DVD_R_DL_JR=1
ID_CDROM_DVD_R_DL_SEQ=1
ID_CDROM_DVD_RW_SEQ=1
ID_CDROM_DVD_RW_RO=1
ID_CDROM_CD=1
ID_CDROM_RW_REMOVABLE=1
ID_CDROM_DVD_RW=1
ID_CDROM_DVD_R_DL=1
ID_CDROM_MEDIA=1
ID_CDROM_MEDIA_DVD=1
ID_CDROM_MEDIA_STATE=complete
ID_CDROM_MEDIA_SESSION_COUNT=1
ID_CDROM_MEDIA_TRACK_COUNT=1
ID_CDROM_MEDIA_TRACK_COUNT_DATA=1
ID_ATA=1
ID_TYPE=cd
ID_BUS=ata
ID_MODEL=ASUS_DRW-24B1ST_j
ID_MODEL_ENC=ASUS\x20\x20\x20\x20DRW-24B1ST\x20\x20\x20j\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_REVISION=1.01
ID_SERIAL=ASUS_DRW-24B1ST_j_H3D0CL014403
ID_SERIAL_SHORT=H3D0CL014403
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_PATH=pci-0000:07:00.0-ata-3.0
ID_PATH_TAG=pci-0000_07_00_0-ata-3_0
ID_PATH_ATA_COMPAT=pci-0000:07:00.0-ata-3
ID_FS_VOLUME_ID=DVD_LABEL
ID_FS_UUID=2d26bd9a00000000
ID_FS_UUID_ENC=2d26bd9a00000000
ID_FS_VOLUME_SET_ID=2d26bd9a
ID_FS_LABEL=DVD_LABEL
ID_FS_LABEL_ENC=DVD_LABEL
ID_FS_LOGICAL_VOLUME_ID=DVD_LABEL
ID_FS_VERSION=1.02
ID_FS_TYPE=udf
ID_FS_USAGE=filesystem
.ID_FS_TYPE_NEW=udf
ID_FOR_SEAT=block-pci-0000_07_00_0-ata-3_0
MAJOR=11
MINOR=0
DEVLINKS=/dev/disk/by-id/ata-ASUS_DRW-24B1ST_j_H3D0CL014403 /dev/cdrom /dev/disk/by-path/pci-0000:07:00.0-ata-3.0 /dev/disk/by-uuid/2d26bd9a00000000 /dev/disk/by-path/pci-0000:07:00.0-ata-3 /dev/disk/by-label/DVD_LABEL
TAGS=:uaccess:systemd:seat:
CURRENT_TAGS=:uaccess:systemd:seat:Last edited by 0nobody0 (2021-04-28 19:56:05)
Offline
tested this some more by adding the below to the script and it looks like the udev rule is actually working fine, the log file was created succesfully.
#!/bin/bash
exec &> /home/user/DVD/insert.log
screen -dm urxvt -e sh -c /home/user/DVD/DVD.sh
echo "Success"
exec >/dev/null 2>&1it appears this is an issue with screens / the script being run as root by udev. made some progress by changing the command in insert.sh to:
sudo -u user /bin/sh -c "DISPLAY=:0 screen -dm urxvt -e /home/user/DVD/DVD.sh"after inserting the dvd the rule is processed, runes the script, the urxvt terminal shows up in the user session and begins running the child script. the child script does not completely successfully.
Last edited by 0nobody0 (2021-04-27 02:52:09)
Offline
Offline
many thanks, added the import environment code to insert.sh and the screen -dm urxvt window shows up in the user x session:
#!/bin/bash
pid=$(pgrep -t tty$(fgconsole) xinit)
pid=$(pgrep -P $pid -n)
import_environment() {
(( pid )) && for var; do
IFS='=' read key val < <(egrep -z "$var" /proc/$pid/environ)
printf -v "$key" %s "$val"
[[ ${!key} ]] && export "$key"
done
}
import_environment XAUTHORITY USER DISPLAY
screen -dm urxvt -e /home/user/DVD/DVD.shthere seems to be a further problem in the child script. it starts running in the uxrvt window and then the console closes. here is DVD.sh:
#!/bin/bash
blkid /dev/sr0 > /dev/null 2>&1
if [ $? == 0 ]; then
echo "Opening VLC to play DVD for 2 seconds..."
vlc dvd:// --stop-time=2 vlc://quit > /dev/null 2>&1
read -p "Press enter to exit"
else
echo "No DVD detected in disc drive."
read -p "Press enter to exit"
fithe console closes after a few seconds even if i add sleep 30 to the start of DVD.sh.
Offline
https://wiki.archlinux.org/index.php/Ud … _processes
You'll probably get away with
screen -dm urxvt -e /home/user/DVD/DVD.sh & disownOffline
hm, i tried updating insert.sh with that code and the urxvt window running DVD.sh still closes after a few seconds.
screen -dm urxvt -e /home/user/DVD/DVD.sh & disowni also tried the following with the same result:
screen -dm urxvt -e /home/user/DVD/DVD.sh & disown | at nowi don't know if it is helpful to note but VLC doesn't open either. when i was messing with:
sudo -u user /bin/sh -c "DISPLAY=:0 screen -dm urxvt -e /home/user/DVD/DVD.sh"VLC did open (it threw some errors but the DVD did play).
p.s. just noticed that while the urxvt process running DVD.sh runs under the user account, the screen process is still running under root
Last edited by 0nobody0 (2021-04-27 21:14:23)
Offline
screen -dm urxvt -e /home/user/DVD/DVD.sh | at nowCan you omit screen (for a test)?
Sanity check: Alad's script inherits the environment from the xinit process, do you use xinit to start X11?
Offline
yes, i believe i am using xinit (startx?). i ran alad's script with set -x and it returned what seemed like appropriate responses?
# ./insert.sh
+++ fgconsole
++ pgrep -t tty1 xinit
+ pid=542
++ pgrep -P 542 -n
+ pid=553
+ import_environment XAUTHORITY USER DISPLAY
+ (( pid ))
+ for var in "$@"
+ IFS==
+ read key val
++ egrep -z XAUTHORITY /proc/553/environ
+ printf -v XAUTHORITY %s /home/user/.Xauthority
+ [[ -n /home/user/.Xauthority ]]
+ export XAUTHORITY
+ for var in "$@"
+ IFS==
+ read key val
++ egrep -z USER /proc/553/environ
+ printf -v USER %s user
+ [[ -n user ]]
+ export USER
+ for var in "$@"
+ IFS==
+ read key val
++ egrep -z DISPLAY /proc/553/environ
+ printf -v DISPLAY %s :0
+ [[ -n :0 ]]
+ export DISPLAYomitting screen does solve the problem with the script terminating early. VLC does not launch which i imagine is a separate issue to troubleshoot?
p.s. many thanks for your assistance by the way
Offline
'key - why do you run "screen -dm" itfp?
About vlc: this one?
vlc dvd:// --stop-time=2 vlc://quit > /dev/null 2>&1I'd log the output somewhere other than /dev/null and see whether it tells you something (and whether vlc is invoked itfp)
Offline
regarding screen -dm: i have some experience working in a linux environment without xorg, and some experience making basic scripts that are run within an xorg session, but i didn't really know anything about having a root/system process run something in another users x session...screen -dm was just the first thing that turned up in some some sloppy research that seemed to be working. the environment import makes a lot more sense, thank you.
completely overlooked that i had put in the output redirect to /dev/null. removing that revealed "Opening VLC to play DVD for 2 seconds...VLC is not supposed to be run as root." adjusting insert.sh to the following seems to fix the issue:
su -c 'urxvt -e /home/graham/DVD/DVD.sh | at now' userVLC runs with some errors which i imagine are related to the way the script is being called. the errors don't occur if DVD.sh is run by user in the xsession. for the immediate goal of verifying the DVD on insertion i don't mind suppressing the errors with
vlc dvd:// --no-qt-error-dialogs --stop-time=2 vlc://quitthat being said, it would be interesting as a learning experience to figure out how to resolve the VLC errors. this whole puzzle has been a very good learning experience in a variety of ways...thank you again for your help it has been invaluable. the VLC errors:
VLC media player 3.0.12 Vetinari (revision 3.0.12-1-0-gd147bb5
[000055a06290eda0] vlcpulse audio output error: PulseAudio seron refused
[000055a0629f8780] dbus interface error: Failed to connect to X11 for dbus-daemon autolaunch was disabled at compile time, s instead
[000055a0629f8780] main interface error: no suitable interface
[000055a06285a460] main libvlc error: interface "dbus,none" in
[000055a06285a460] main libvlc: Running vlc with the default iwithout interface.
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/r
[00007f93b8001120] dvdnav demux: DVD Title: DVD_LABEL
[00007f93b8001120] dvdnav demux: DVD Serial Number: 2d1ca629
[00007f93b8001120] dvdnav demux: DVD Title (Alternative):
[00007f93b8001120] dvdnav demux: DVD disk reports itself with Region mask 0x00f00000. Regions: 01 02 03 04
[00007f93b8001120] dvdnav demux: Attempting to retrieve all CSS keys
[00007f93b8001120] dvdnav demux: This can take a _long_ time, please be patient
[000055a06290eda0] main audio output error: too low audio sample frequency (0)
[00007f93b81940e0] main decoder error: failed to create audio output
ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave
[000055a06290eda0] alsa audio output error: cannot open ALSA device "default": No such file or directory
[000055a06290eda0] main audio output error: module not functional
[00007f93b81940e0] main decoder error: failed to create audio outputOffline
Try "su -pc …", vlc doesn't get the environment variables because su/sudo drop them by default.
Offline
tried:
su -pc 'urxvt -e /home/graham/DVD/DVD.sh | at now' userbut the same problem seems to occur. thinking i might have to import the DBUS_SESSION_BUS_ADDRESS variable as well in insert.sh ?
edit: adding DBUS_SESSION_BUS_ADDRESS and XDG_RUNTIME_DIR to the import_environment line in insert.sh seemed to do to the trick. does that seem acceptable?
import_environment XAUTHORITY USER DISPLAY DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIRLast edited by 0nobody0 (2021-04-28 19:28:44)
Offline
Perfect (I didn't realize that the DBUS env wasn't in Alads script)
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Offline
wonderful, many many thanks, wishing you the best.
to summarize the working setup if it's of use to anyone in the future.
1. created file for udev rule to launch initial script upon DVD insertion - /etc/udev/rules.d/99-dvdinsert.rules with contents:
ACTION=="change", KERNEL=="sr[0-9]*", ENV{ID_CDROM_DVD}=="1", ENV{ID_CDROM_MEDIA_STATE}=="complete", RUN+="/home/USERNAME/DVD/insert.sh"sources:
https://wiki.archlinux.org/index.php/udev
https://askubuntu.com/a/747328
2. contents of initial script run by udev at /home/USERNAME/DVD/insert.sh:
#!/bin/bash
pid=$(pgrep -t tty$(fgconsole) xinit)
pid=$(pgrep -P $pid -n)
import_environment() {
(( pid )) && for var; do
IFS='=' read key val < <(egrep -z "$var" /proc/$pid/environ)
printf -v "$key" %s "$val"
[[ ${!key} ]] && export "$key"
done
}
import_environment XAUTHORITY USER DISPLAY DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR
su -c 'urxvt -e /home/USERNAME/DVD/DVD.sh' USERNAME | at now 2>/dev/nullsources:
seth, above
https://gist.github.com/AladW/de1c5676d93d05a5a0e1
https://wiki.archlinux.org/index.php/ud … _processes
3. contents of script /home/USERNAME/DVD/DVD.sh which specify long-running actions. in this case it opens VLC to test if DVD plays or returns a message if no DVD is inserted.
#!/bin/bash
function finish() {
printf '\n'
read -p "Script terminated by Ctrl+C. Press enter to exit"
exit
}
trap finish SIGINT
blkid /dev/sr0 > /dev/null 2>&1
if [ $? == 0 ]; then
echo "Opening VLC to play DVD for 2 seconds..."
vlc dvd:// --no-qt-error-dialogs --stop-time=2 vlc://quit > /dev/null 2>&1
read -p "Press enter to exit"
else
echo "No DVD detected in disc drive."
read -p "Press enter to exit"
fisources:
too many and too long ago to remember
Offline