Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rakesh, I've just been trying to figure out exactly the same thing, and I think I've solved it.</p> <p>You don't need to understand much of the makefile at all. The important lines are the following, which are executed in bash when you run <code>sudo make install</code></p> <pre><code>install: install-files groupadd -f --system gpio chgrp gpio $(DESTDIR)/bin/gpio-admin chmod u=rwxs,g=rx,o= $(DESTDIR)/bin/gpio-admin </code></pre> <p><code>groupadd -f --system gpio</code> creates a system group called gpio. <code>chgrp gpio $(DESTDIR)/bin/gpio-admin</code> changes the group of the binary (which the C file gpio-admin.c was compiled to) to gpio. The owner of the binary is still root (since you're running make as root.) <code>chmod u=rwxs,g=rx,o= $(DESTDIR)/bin/gpio-admin</code> does two important things. Firstly, it lets a member of the gpio group run gpio-admin. Secondly, it sets the setuid bit on gpio-admin.</p> <p>When you add yourself to the gpio group, you can run gpio-admin, without using sudo, but gpio admin will act like it is being run under sudo. This allows it to write to the /sys/class/gpio/export file. It also allows it to change the owner of the files /sys/class/gpio/gpio[pin number]/direction etc. that get created.</p> <p>Even if you change the group of /sys/class/gpio/export to gpio, and set permissions to allow you to write to it</p> <pre><code>sudo chgrp gpio /sys/class/gpio/export /sys/class/gpio/unexport sudo chmod g+rwx /sys/class/gpio/export /sys/class/gpio/unexport </code></pre> <p>you can export a pin without superuser powers</p> <pre><code>echo 22 &gt; /sys/class/gpio/export </code></pre> <p>but the files /sys/class/gpio/gpio22/direction etc. will still be create with root as the owner and group, and you'll need to use sudo to change them. Also, ownership of the export and unexport files will revert to root after each reboot.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload