From: Kent Gibson <warthog618@gmail.com>
To: Leszek Dubiel <leszek@dubiel.pl>
Cc: linux-gpio@vger.kernel.org
Subject: Re: Elegant way to kill previous gpioset?
Date: Wed, 16 Nov 2022 13:52:05 +0800 [thread overview]
Message-ID: <Y3R6hbBF5vKuwvFe@sol> (raw)
In-Reply-To: <57c25430-284b-36dc-7a68-70847bc1bdcb@dubiel.pl>
On Tue, Nov 15, 2022 at 09:36:59PM +0100, Leszek Dubiel wrote:
>
>
>
> Different bash scripts from different servers
> ssh to Raspberry and set GPIO line:
>
> /dev/gpiochip2, pin number 7.
>
> with such command:
>
> gpioset -b -msignal /dev/gpiochip2 7=1
>
>
>
> If another script tries:
>
> gpioset -b -msignal /dev/gpiochip2 7=0
>
> then it gets:
>
> gpioset: error setting the GPIO line values: Device or resource busy
>
>
>
> So every bash script kills previous instance
> before setting gpio line:
>
> pkill -ef "^gpioset .* /dev/gpiochip2 7=[01]$"
> gpioset -b -msignal /dev/gpiochip2 7=0
>
>
>
> Pkill is bad solution:
>
> 1. it is very slow, because it has to grep full command lines.
>
> 2. it doesn't work if one of bash scripts
> used little bit different command, for example:
>
> gpioset -b -msignal /dev/gpiochip2 7=0 5=2
> gpiomon /dev/gpiochip2 7
>
>
>
> Is there a better way to kill o replace
> previous instance of running gpioset?
>
The best way is not to have to kill it.
If you kill the gpioset then the state of the line becomes indeterminate
so you are open to glitches as well as some other process grabbing the
line.
To address this the gpioset for v2[1] has an interactive mode that allows
you to pipe commands to it. The tests for v2[2] (gpio-tools-tests.bats)
demonstrate that by launching the gpioset from bash using coproc and then
driving the gpioset via the pipe to the co-process.
For a more long lived solution you can setup a named pipe and then write
commands to that to update the line:
mkfifo setpipe
gpioset --interactive -c gpiochip2 7=0 < setpipe &
echo "set 7=1" > setpipe
or
echo "toggle" > setpipe
You can even kill it with:
echo "exit" > setpipe
Would that work for you?
Personally, for situations like this I don't use the tools, I use one of
the bindings to write a daemon that controls the line and receives its
commands from some other source.
There are plans for a generic daemon that would allow you to access lines
via dbus, but that hasn't got past the planning stages AFAIAA.
Wrt identifying and killing processes holding particular lines,
the ability to identify the GPIO lines held by processes via the /proc
filesystem has recently been added to the 6.1 kernel[3]. There are
plans for a tool that will use that to return the PID holding a line,
but again that is still in the planning stages.
Cheers,
Kent.
[1] https://lore.kernel.org/linux-gpio/20221114040102.66031-3-warthog618@gmail.com/
[2] https://lore.kernel.org/linux-gpio/20221114040102.66031-4-warthog618@gmail.com/
[3] https://lore.kernel.org/linux-gpio/Yyw5mivLAgWZIx0W@sol/T/
next prev parent reply other threads:[~2022-11-16 5:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fc3da423-1107-83a1-1c94-afb2ac5fa7c9@dubielvitrum.pl>
2022-11-15 20:01 ` User space tools Leszek Dubiel
2022-11-15 20:36 ` Elegant way to kill previous gpioset? Leszek Dubiel
2022-11-16 5:52 ` Kent Gibson [this message]
2022-11-16 8:54 ` Leszek Dubiel
2022-11-16 11:52 ` Kent Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y3R6hbBF5vKuwvFe@sol \
--to=warthog618@gmail.com \
--cc=leszek@dubiel.pl \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).