Breaking Linux device file name changes

I have discovered that in some version of Linux prior to the one I am on the name of a device file created dynamically has changed. Rather than just deal with the latest version of Linux, I ought to support the old way of Linux. Is there a canonical way of handling this sort of change in Rust code.

So for example, the dynamically created file that used to be called:

/dev/input/by-path/pci-0000:00:14.0-usb-0:1:1.0-event

is now called:

/dev/input/by-path/pci-0000:00:14.0-usb-0:1:1.0-event-ir

Can you just write a function which checks the linux version (e.g. by invoking uname --kernel-release) and returns the correct path for that version?

Otherwise if you know the name change is consistent, you could check the new form and fall back to the older one if that doesn't exists.

1 Like

If you want a version check, I'd recommend calling uname() directly, rather than invoking a new process.

1 Like

I never knew uname was a syscall. I always thought the uname program used some sort of black magic to discover kernel information.

TIL.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.