Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Software] udev Script Permission Issue with udevadm on Debian 12 (bookworm)

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Interna21
Posts: 3
Joined: 2024-05-14 05:45

[Software] udev Script Permission Issue with udevadm on Debian 12 (bookworm)

#1 Post by Interna21 »

Hello everyone,

I'm currently running Debian GNU/Linux 12 (bookworm) with the Kernel: Linux 6.1.0-20-amd64. I have a Perl script that is executed by udev when a USB device is plugged in. While the script is triggered correctly, I encounter an issue when it tries to execute a udevadm info command.

Here is the problematic part of the script (just for testing the bug):

Code: Select all

my $testOutput = "udevadm info --query=path /dev/sdc";
my $exitStatus = system($testOutput);
_PrintAndLog("This is the test exit status $exitStatus");
The script doesn't get past this part and gets stuck. I checked the exit status and it returns 13, which I read indicates a permission problem.
When I try the command in the shell it works just fine and returns what is expected.

This same script worked on a different Linux OS, so I suspect there's a specific permission or configuration issue on Debian.

Here's what I've tried so far:

Verified that the script is being called correctly by udev.
Added the following line to the sudoers file using sudo visudo

Code: Select all

root ALL=(ALL) NOPASSWD: /path/to/my/Script.pl
Checked my udev rule:

Code: Select all

KERNEL=="sd*", ENV{DEVTYPE}=="disk", RUN+="/path/to/my/Script.pl '$env{ACTION}' '$env{DEVNAME}' '$env{DEVTYPE}' '$env{ID_PATH}'"
Added both my users to the disk group:

Code: Select all

sudo usermod -a -G disk $USER
Despite these steps, the issue persists. I'm looking for advice on what might be causing this permission problem and how to resolve it.

Any help would be greatly appreciated!

Thank you.

lindi
Debian Developer
Debian Developer
Posts: 469
Joined: 2022-07-12 14:10
Has thanked: 1 time
Been thanked: 88 times

Re: [Software] udev Script Permission Issue with udevadm on Debian 12 (bookworm)

#2 Post by lindi »

Have you considered using strace to compare how those two cases differ? See for example viewtopic.php?p=769888#p769888

Also, are you sure it is ok to call udev API from an udev hook?

Interna21
Posts: 3
Joined: 2024-05-14 05:45

Re: [Software] udev Script Permission Issue with udevadm on Debian 12 (bookworm)

#3 Post by Interna21 »

It worked before on an ubuntu. That's why I hope that it is okay to call udevadm on debian as well.
Tomorrow I will try looking for differences with strace.

Thank you in advance.

Aki
Global Moderator
Global Moderator
Posts: 3110
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 78 times
Been thanked: 419 times

Re: [Software] udev Script Permission Issue with udevadm on Debian 12 (bookworm)

#4 Post by Aki »

Hello,
Interna21 wrote: 2024-05-14 05:55 [..]
Here is the problematic part of the script (just for testing the bug):

Code: Select all

my $testOutput = "udevadm info --query=path /dev/sdc";
my $exitStatus = system($testOutput);
_PrintAndLog("This is the test exit status $exitStatus");
Can you please post the whole script?
Interna21 wrote: 2024-05-14 05:55 The script doesn't get past this part and gets stuck. I checked the exit status and it returns 13, which I read indicates a permission problem. When I try the command in the shell it works just fine and returns what is expected.
Some suggestions/observations:
  • you may also report privileges and ownership assigned to the perl script, using the ls -la command.
  • your perl script snippet always uses /dev/sdc as a parameter for the udevadm command, but you have no guarantee that the sdc device name will always be assigned to the USB device when it is mounted by the operating system.
The discussion is moved from "General Questions" to "Programming" sub-forum.
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

Interna21
Posts: 3
Joined: 2024-05-14 05:45

Re: [Software] udev Script Permission Issue with udevadm on Debian 12 (bookworm)

#5 Post by Interna21 »

Hello all.
Sorry I needed a bit longer to answer.
Sadly I cannot post the whole script due to work restriction.

I fixed my problem .. kinda

I now made a commandServer that is executing my commands I need in root. This commanServer is a perl script with a endless loop that checks specific files if there are any changes. The commandServer is automatically started once the PC starts.

Then I changed it that the commands I usually would have executed in my other scripts, are now written in specific folders.
I made it something like this:
a sub that returns: File::Spec->catfile($directoryName , "parameters_" . int(rand(10000)) . ".args")
then I have a sub that writes all of this
opens the generated file
foreach $line in my commands
print..

I hope this helps for others that are having similar issues. It is definitely not a pleasent way to handle this but it works.

Post Reply