3

I am developing some code using the BlueZ Bluetooth stack and running it requires root privileges. As example running hcitool lescan as normal user returns Set scan parameters failed: Operation not permitted, which is also seen from my C++ code where hci_le_set_scan_parameters() functions returns -1.

The question Run a C++ program in Clion as root is about running C++ program as root in CLion on the local machine, which can be as simple as running the CLion as root.

I have configured Full Remote Mode with remote toolchain: enter image description here

and then I'm using this same configuration for automatic deployment: enter image description here

and then the Run/Debug Configurations are automatically run as this user on the remote machine.

I could replace Non-superuser user in Deployment configuration with root and probably solve the problem (by also giving root privileges to whole Remote Host Browser) - but is there any other way to achieve this any only run the built executable with sudo?

Bojan P.
  • 942
  • 1
  • 10
  • 21
  • Could you meanwhile find a solution? – Patrick Nov 25 '20 at 09:29
  • 1
    @Patrick unfortunately I did not, I went with "print debugging" and run executable manually. Interestingly, a while ago I noticed PyCharm option "_Execute code using this interpreter with root privileges via sudo_" when configuring remote Python interpreters. – Bojan P. Nov 26 '20 at 10:17
  • Thansk for your reply! I ended up writing a small shell script that is launched after the build task (can be configured in CLion's run configuration) and that changes the owner to root and also sets the setuid bit of the executable such that the program is executed as root. Also, I have added this executable into sudoers with the NOPASSWD flag so that I don't need to enter the password every time. Quite hacky but it works ;-) – Patrick Jan 02 '21 at 16:47

0 Answers0