pigpio icon indicating copy to clipboard operation
pigpio copied to clipboard

Consider O_CLOEXEC when opening FIFOs?

Open fandahao17 opened this issue 4 years ago • 3 comments

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?

fandahao17 avatar Apr 19 '20 13:04 fandahao17

As an alternative approach, you could use pigpiod_if2 to open notifications via the socket then fork pig2vcd from there.

guymcswain avatar Apr 19 '20 17:04 guymcswain

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.

joan2937 avatar Apr 20 '20 08:04 joan2937

@fandahao17 , if you have a working proposal with test cases, please submit a pull request.

guymcswain avatar May 01 '20 19:05 guymcswain