I have a user-level C++ test application running on a linux mobile device. One of the test involves enabling/disabling printer paper sensor which requires root privileges writing on a device file. Is there a way to grant my application that kind of privilege? If none, is there a workaround for that?
Share
This will do,
as
rootexecute:or alternatively
or alternatively
This will not work with scripts. And yes, you should take seriously what jdizzle said about dropping unnecessary privileges.
Another way to solve this is to make the user who runs the application a member of the group that owns the device file. For example,
members of the
printergroup can read and write to the device, so you just need to addjoeto theprintergroup (and restart the session).If you need to adjust the devicefile permissions, you probably will need to edit udev rules to make it permanent. But
chmodshould work too.Other options worth investigating:
setcap(8)(nice guide here) andsudo(8).