Tuesday, July 15, 2014

61: Philosophical thoughts about the gpio command

I think it's safe to say that the basic philosophy of UNIX (Linux) shell commands is that they do not maintain "state" information between one execution and another. (Info maintained by the shell while you are logged in doesn't break this rule -- your shell only exits when you log out). But gpio obviously ignores this convention. In my post #60 I gave these 2 examples:

$ gpio -g mode 7 in  # pin 7 is connected to an input
. . .
$ gpio -g read 7     # get a 0 or 1 from pin 7

Before I wrote my blog entry, I actually executed those 2 lines on my Pi. Then I quit SSH from my Mac (about 2 weeks ago). The Pi had not been rebooted since, so I logged in just now and repeated the gpio-read command. Surprise, surprise. It still worked (i.e., it remembered that pin 7 was "input").

A "sudo reboot" finally erased that rather dangerous information. I don't like this -- especially since gpio is a "setuid root" command. This is ugly and unnecessary. BTW: after the reboot the gpio-read command did not produce an error message -- it always  returned "1".

Advice? Better to operate relays in Python or C.


No comments:

Post a Comment