I guess I should be more careful when posting off-the-cuff comments. :-) You need to be careful using the setuid bit because you can create a program that is exploitable. If you're just hacking around on your own BBB then it's fine for getting things to work. But if you want to distribute it to anyone then you probably need to think more about managing privileged access.
I don't think you'll need the setuid() call in the code providing you are okay with having your process always run as root. If you are looking to access the gpio pins at the beginning of your program and then drop the root privileges then you can use setuid to become a non-privileged user. The parameter for setuid is the uid of the user you want to become. However, if you use setuid to drop root privileges then you cannot setuid back to root later. If you want to periodically use admin privileges to access the gpio pins while reverting to a non-privileged user during normal runtime then look into the seteuid or setreuid calls. TJF's idea about using libpruio is a good one also. On Tuesday, February 3, 2015 at 7:00:25 AM UTC-5, Julian Gold wrote: > > Thanks Walker. I have looked at setuid and it appears to be the best way > to go. I don't quite get it though. My code is built by netbeans, so I have > to chmod +s the exe, then call setuid( x ) in the code? What is x? > > On Monday, 2 February 2015 18:57:27 UTC, Walker Archer wrote: >> >> Or you can google the setuid bit. This would allow your application to >> run as root without having to be logged in as root. >> >> On Monday, February 2, 2015 at 12:10:31 PM UTC-5, Nic Cyn wrote: >>> >>> You are not really asking the right question (its ok you are new to >>> this). However the problem you have really has nothing to do with the >>> Beaglebone Black - it is really a Linux issue and any solution to it would >>> be common to any Linux system. >>> >>> Try googling something like "*linux auto run program on boot as root*" >>> and you will find a lot of help. >>> >>> On Monday, 2 February 2015 14:20:41 UTC, Julian Gold wrote: >>>> >>>> We have a Revision C board running debian, and wish to use a couple of >>>> the GPIO channels from within the (C++) software we are developing. This >>>> requires writing to the "file" /sys/class/gpio/export, but this requires >>>> root permission. In bash I can just "sudo su", but this is surely not >>>> going >>>> to work from C++? >>>> >>>> Presumably if I logged in as root and ran my code, the permissions >>>> would be correct. However the board boots to the desktop with "debian" as >>>> the default user. Can this be changed to root and how? >>>> >>> -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
