4

I am working on setting up an automated deployment of an executable using the PIGPIO C bindings to a Pi Zero. I copy the executable to the pi (into a directory on pi user's desktop) as expected, but when I try to run it, I get a permissions error:

initCheckPermitted:
+---------------------------------------------------------+
|Sorry, you don't have permission to run this program.    |
|Try running as root, e.g. precede the command with sudo. |
+---------------------------------------------------------+

It seems this problem can be solved by setting the executable to be owned by root and using a permission setting like 4775. This seems to allow me to run the executable while logged in as pi.

Unfortunately though, when I then copy a new version of the executable in, the ownership permissions stay the same, but the sticky bit is removed and I can no longer run the executable. It seems like the right answer would be "figure out how to run the executable when it's owned by pi". Is this possible? Can I change something so PIGPIO can access the needed hardware without having to do weird things with the permissions?

This question seems to be a similar issue, but with PWM specifically. I see a gpio group but pi is already in that group. Is this question related or completely misleading me?

RedBassett
  • 141
  • 1
  • 3

1 Answers1

-1

I am assuming you have the source code of your C program. If so, add these lines:

At the top:

#include <sys/types.h>
#include <unistd.h>

Near the start of main():

if (setuid(getuid()) < 0)
{
        printf("Privilege change failed\n");
        exit(EXIT_FAILURE);
}

You can use any other error notification, instead of the printf.

See man -s 2 setuid for details.

Peter Bill
  • 339
  • 2
  • 8