You are not logged in.

#1 2014-04-11 08:39:39

blattlaus
Member
Registered: 2014-04-11
Posts: 9

Udev - rule executes script, but script sees everything read only

Hi,
After upgrading my arch system, I am having trouble getting my udev setup for auto monitor configuration running again:

/etc/udev/rules.d% cat 99-monitor-hotplug.rules 
# this line worked before upgrade
#ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/home/xx/.script/auto_monitor.sh" 
# now I have to use this, for the script to be executed, however file writing does not work:
ACTION=="change", SUBSYSTEM=="drm", RUN+="/home/xx/.script/auto_monitor.sh"

My problem is now, that everytime, auto_monitor.sh wants to write to a file it does not work. The following errors appear in the udev log:

Apr 11 10:02:51 e330 systemd-udevd[26263]: RUN '/home/xx/.script/auto_monitor.sh' /etc/udev/rules.d/99-monitor-hotplug.rules:4
Apr 11 10:02:51 e330 systemd-udevd[26263]: handling device node '/dev/dri/card0', devnum=c226:0, mode=0600, uid=0, gid=0
Apr 11 10:02:51 e330 systemd-udevd[26263]: preserve already existing symlink '/dev/char/226:0' to '../dri/card0'
Apr 11 10:02:51 e330 systemd-udevd[26263]: created db file '/run/udev/data/c226:0' for '/devices/pci0000:00/0000:00:02.0/drm/card0'
Apr 11 10:02:51 e330 systemd-udevd[26264]: starting '/home/xx/.script/auto_monitor.sh'
Apr 11 10:02:51 e330 systemd-udevd[26263]: '/home/xx/.script/auto_monitor.sh'(out) 'i am:'
Apr 11 10:02:51 e330 systemd-udevd[26263]: '/home/xx/.script/auto_monitor.sh'(out) 'root'
Apr 11 10:02:51 e330 systemd-udevd[26263]: '/home/xx/.script/auto_monitor.sh'(out) '-rw-r--r-- 1 root root 10446 Apr 11 09:47 /home/xx/.log/auto_monitor'
Apr 11 10:02:51 e330 systemd-udevd[26263]: '/home/xx/.script/auto_monitor.sh'(out) '/dev/sda1 on / type ext4 (ro,relatime,discard,data=ordered)'
Apr 11 10:02:51 e330 systemd-udevd[26263]: '/home/xx/.script/auto_monitor.sh'(err) 'touch: cannot touch '/home/xx/.log/auto_monitor_test''
Apr 11 10:02:51 e330 systemd-udevd[26263]: '/home/xx/.script/auto_monitor.sh'(err) ': Read-only file system'
Apr 11 10:02:51 e330 systemd-udevd[26263]: '/home/xx/.script/auto_monitor.sh'(err) '/home/xx/.script/auto_monitor.sh: line 14: /home/xx/.log/auto_monitor: Read-only file system'

For debugging, I thanged the beginning of the script to:

#!/bin/bash
echo "i am:"
echo `whoami`
echo `ls -l /home/xx/.log/auto_monitor`
echo `mount | grep sda1`
......
touch /home/xx/.log/auto_monitor_test
echo `date` >> /home/xx/.log/auto_monitor

Somehow udev changes the mount options of my file system to ro, while executing the scripts.

However during normal operation the file system is rw:

% mount |grep sda1              
/dev/sda1 on / type ext4 (rw,noatime,discard,data=ordered)

Maybe I missed something in the package upgrade notes.
I hope someone could give me a hint, what I might do wrong here.

Last edited by blattlaus (2014-04-11 16:28:38)

Offline

#2 2014-04-11 16:16:48

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Udev - rule executes script, but script sees everything read only

what user is udevd running as?

Offline

#3 2014-04-11 16:25:53

blattlaus
Member
Registered: 2014-04-11
Posts: 9

Re: Udev - rule executes script, but script sees everything read only

Thank you for replying.

I think it is running as root:

% ps aux | grep udev
root       161  0.0  0.0  32000  1824 ?        Ss   10:46   0:00 /usr/lib/systemd/systemd-udevd

Last edited by blattlaus (2014-04-11 16:26:17)

Offline

#4 2014-04-11 16:33:01

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Udev - rule executes script, but script sees everything read only

then it shouldn't matter the file permissions, unless it drops permissions when it runs, or it's a folder protected by some other mechanism. what's your file system structure like?

have you tried placing the log outside of /home/ ? maybe in /tmp/ or in /sys/log/ ?

edit: proper engrish wink
edit2: you can always symlink it later, so location isn't that important

Last edited by HiImTye (2014-04-11 16:34:41)

Offline

#5 2014-04-11 17:15:12

blattlaus
Member
Registered: 2014-04-11
Posts: 9

Re: Udev - rule executes script, but script sees everything read only

hmm I am confused right now.
It suddenly somehow works more or less.

What I did was the following:

I added the line

touch /tmp/auto_monitor_test_file

to my script

executed

sudo udevadm trigger -v -s drm -y card0

then I looked into journalctl -f, to see if errors were reported.
I could not see any output of udev there at all.

nevertheless I checked the /tmp folder and found the file.
The files in my homefolder however were untouched!!!

I restarted udevd (perhaps i also restarted it one step earlier. I can't remember).

Then I remembered that I had to enable verbode logging in udev to see the errors last time.
So I executed:

sudo udevadm control --log-priority=debug

and tested again.
This time I saw the following output in journalctl:

Apr 11 18:53:32 e330 systemd-udevd[26568]: device 0x22a14d0 has devpath '/devices/pci0000:00'
Apr 11 18:53:32 e330 systemd-udevd[26568]: device 0x229cc10 filled with db file data
Apr 11 18:53:32 e330 systemd-udevd[26568]: RUN 'uaccess' /usr/lib/udev/rules.d/73-seat-late.rules:15
Apr 11 18:53:32 e330 systemd-udevd[26568]: RUN '/home/xx/.script/auto_monitor.sh' /etc/udev/rules.d/99-monitor-hotplug.rules:3
Apr 11 18:53:32 e330 systemd-udevd[26568]: handling device node '/dev/dri/card0', devnum=c226:0, mode=0600, uid=0, gid=0
Apr 11 18:53:32 e330 systemd-udevd[26568]: preserve already existing symlink '/dev/char/226:0' to '../dri/card0'
Apr 11 18:53:32 e330 systemd-udevd[26568]: created db file '/run/udev/data/c226:0' for '/devices/pci0000:00/0000:00:02.0/drm/card0'
Apr 11 18:53:32 e330 systemd-udevd[26569]: starting '/home/xx/.script/auto_monitor.sh'
Apr 11 18:53:32 e330 systemd-udevd[26568]: '/home/xx/.script/auto_monitor.sh'(out) 'i am:'
Apr 11 18:53:32 e330 systemd-udevd[26568]: '/home/xx/.script/auto_monitor.sh'(out) 'root'
Apr 11 18:53:32 e330 systemd-udevd[26568]: '/home/xx/.script/auto_monitor.sh'(out) '-rw-r--r-- 1 root root 11003 Apr 11 18:53 /home/xx/.log/auto_monitor'
Apr 11 18:53:32 e330 systemd-udevd[26568]: '/home/xx/.script/auto_monitor.sh'(out) '/dev/sda1 on / type ext4 (rw,noatime,discard,data=ordered)'
Apr 11 18:53:32 e330 systemd-udevd[26568]: '/home/xx/.script/auto_monitor.sh' [26569] exit with return code 0
Apr 11 18:53:32 e330 systemd-udevd[26568]: passed -1 bytes to netlink monitor 0x229c5a0
Apr 11 18:53:32 e330 systemd-udevd[26568]: seq 2096 processed with 0
Apr 11 18:53:32 e330 systemd-udevd[25718]: seq 2096 done with 0

suddenly the filesystem is rw.

and now the files in my home folder also were touched.

I then removed the line, which created the file in /tmp from my script, to restore the original state of the script. => It is still touching the files in my home folder.

I still do not understand the exit code 0, but this might be an other bug in the script.

I do not mark this as solved, as I do not understand what happened, and still can not confirm that it is working correctly.
A friend of mine has the same problem. I will try to reproduce the problem on her system too and report back.

Offline

#6 2014-04-11 17:20:59

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: Udev - rule executes script, but script sees everything read only

0 typically means that it exited OK

Offline

#7 2014-04-11 20:28:33

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Udev - rule executes script, but script sees everything read only

blattlaus wrote:

/dev/sda1 on / type ext4 (ro,relatime,discard,data=ordered)

Systemd is (almost certainly) starting udev *before* remounting the disk as read/write.

I also do this in busybox (link in my sig), the order being:

1. Mount *temporary* filesystems, e.g. /tmp, /run
2. Start udevd
3. Remount disk read-only
4. fsck disk
5. Remount disk read/write

Offline

#8 2014-04-14 14:47:09

blattlaus
Member
Registered: 2014-04-11
Posts: 9

Re: Udev - rule executes script, but script sees everything read only

Thank you for your replies smile

brebs wrote:

Systemd is (almost certainly) starting udev *before* remounting the disk as read/write.

Yes this seems to be the problem somehow.
What I still do not understand is, why my script then does not see the remounted filesystem, as the udev event is triggered way after the system is initialized completely.

Currently I have to restart udev everytime, after I reboot my system.

Before I updated my system, I did not have this problem. Maybe the update changed the init order.

Offline

Board footer

Powered by FluxBB