I'm writing a cross-platform app that I would like to run on Linux-based operating systems like Fedora and Ubuntu. I use QSerialPort
and it works fine. I can use QSerialPortInfo
to get a list of serial ports in the system and present them to the user who can select which one s/he wants to use.
However, on Linux systems, by default the user doesn't have permissions to the serial ports. I know that it is wrong to run my app with sudo
and I also know that it is not user friendly to ask the user to run chmod 666
on the serial port manually every time the app is used. So I looked around and it seems to me that polkit is the answer, however I haven't been able to find any example which would show me how to do it.
Can you please tell me how to use polkit (formerly known as policykit) to request permission for my app to use a specific serial port?
EDIT:
What I'm looking for is a way to:
- Check if the user has access to the serial port
- If not, pop up a dialog that asks for permission (like the Gnome settings app for example)
- If the user authenticated successfully, make the serial port available to the app.
Some more thoughts
- I do NOT want to set up an udev rule that gives perimission to every serial port
- I do NOT want to ask the user to run a script
- I do NOT want my app to run as the superuser
- I do NOT want any other actions performed as root, just the serial port access
Yes I've found the official polkit docs, but they are not very clear on how to do this.