I am writing a custom module kernel that boots at startup. I can write in the sysFS file using this :
echo -e "(0,0,255,750)\n" | sudo tee /sys/fs/led_sysfs/led_value
But I will have another software that will need to write to the sysFs
file. This software can only be launched in user mode and not using sudo.
By default the permission of the SysFs is -rwxrwx---
And it's in the rules of creating a SysFs file that it can't be 777. What I found would be the best solution is to create a new group where only my user and the SysFs will be.
So I found that I could write a udev rule to change the parameter. The command udevadm info -a -p /sys/fs/led_sysfs
give me this :
KERNEL=="led_sysfs"
SUBSYSTEM==""
DRIVER==""
ATTR{led_value}=="(not readable)"
looking at parent device '/fs':
KERNELS=="fs"
SUBSYSTEMS==""
DRIVERS==""
So I tried multiple different rules but none of them work... Here's what I tried :
KERNEL=="led_sysfs", ACTION=="add", RUN+="/bin/chmod 777 /sys/fs/led_sysfs/led_value ;/bin/chown root:led /sys/fs/led_sysfs/led_value ;"
KERNEL=="led_sysfs", ACTION=="change", RUN+="/bin/chmod 777 /sys/fs/led_sysfs/led_value ;/bin/chown root:led /sys/fs/led_sysfs/led_value ;"
KERNEL=="led_sysfs", RUN+="/bin/chmod 777 /sys/fs/led_sysfs/led_value ;/bin/chown root:led /sys/fs/led_sysfs/led_value ;" KERNEL=="led_sysfs", RUN+="/bin/chmod 777 /sys/fs/led_sysfs/led_value"
KERNEL=="led_sysfs", RUN+="/bin/chown root:led /sys/fs/led_sysfs/led_value" KERNEL=="led_sysfs", RUN+="/bin/chmod 777 /sys/fs/led_sysfs/led_value;"
KERNEL=="led_sysfs", RUN+="/bin/chown root:led /sys/fs/led_sysfs/led_value; KERNEL=="led_sysfs", RUN+="/usr/bin/find /sys/fs/led_sysfs/ -type f -name led_value -exec chown root:led {} ; -exec chmod 666 {} ;"
Does the problem come from how I create my module or my rules? Thanks in advance.
/sys/
anyway as files/directories under it are not real but rather a hierarchy of information reflected from the kernel space about subsystems, devices, drivers ... etc. and it might break if you change it ... Instead do something else like addingALL ALL = (ALL) NOPASSWD: /usr/bin/tee /sys/fs/led_sysfs/led_value
to the sudoers file withsudo visudo
so that... | sudo tee /sys/fs/led_sysfs/led_value
wouldn't ask for a password for example. – Raffa Dec 18 '23 at 14:08