pigpio
pigpio copied to clipboard
Consider O_CLOEXEC when opening FIFOs?
Hi there! Thanks for your awesome project!
This is how I run into this problem: In main()
, I started notification on FIFO /dev/pigpio0
and forked another process which runs pig2vcd
to output the captured waveform. But I found that in the child process, I can't close /dev/pigpio0
even if I called gpioNotifyClose
.
After going through the source code I found that by default, the actual close is done in the alert thread, but fork()
only copies the main thread. I read the man page and found that this problem can be fixed by including O_CLOEXEC
when calling open()
. Will you consider adding this flag when opening FIFOs?
As an alternative approach, you could use pigpiod_if2
to open notifications via the socket then fork pig2vcd
from there.
I don't have any problem with the use of this flag. Mind you I have only had a quick skim through the man pages.
@fandahao17 , if you have a working proposal with test cases, please submit a pull request.