dhcpcd-discuss

Re: problem with "nobackground" mode on NetBSD current?

Rob Newberry

Sat Sep 12 18:17:31 2020

Yep. I've confirmed that fixes it.  

FYI -- I've also found the bug in my systems manager code.  It was an uninitialized file descriptor variable, defaulted to zero instead of -1 (invalid file descriptor value), which was closed at the exit of a function.

I backed out my fix (temporarily) and tested with your changes to confirm that it did indeed fix the problem (I even added a logerrx to make sure it detected an invalid stdin).  I can confirm that dhcpcd works with or without fixing my own code :-).

Thank you again!

Rob




> On Sep 12, 2020, at 7:43 AM, Roy Marples <roy@xxxxxxxxxxxx> wrote:
> 
> On 11/09/2020 20:28, Rob Newberry wrote:
>> OK, I've at least PARTIALLY figured this out.
>> There's a bug in my "embedded system/network manager" code that is somehow closing STDIN_FILENO before forking and running dhcpcd.
>> I haven't yet figured out exactly where that bug is, but I will :-).
>> It's a really cool bug, in that it's the kind of nastiness that few programs ever expect to deal with.  In this particular case, what was happening was that, because STDIN_FILENO was closed, the pidfile lock was getting back STDIN_FILENO for the lock file.
>> And then when dhcpcd called "freopen" on stdin, it actually closed the pidfile and re-opened it for read-only (appropriate for stdin), and the future pidfile_lock failed because the descriptor was no longer open for writing.  Very weird repercussion from such an unexpected situation (I kinda like bugs like this, as it makes me learn more about other parts of the system in more detail).
>> Anyway, very sorry to have bothered folks here, since it did indeed turn out to be a bug elsewhere (and completely my own), but really, really appreciate the help debugging.
> 
> WOW! That is a nice find!
> Well, there could be other situations like this - although file descriptors 0, 1 and 2 should always be open, no actual guarantee is made that this is the case.
> 
> Attached is a patch which should address this. Can you test it and let me know if it fixes it for you?
> 
> Roy
> <dhcpcd-fixstdio.diff>


Follow-Ups:
Re: problem with "nobackground" mode on NetBSD current?Roy Marples
References:
problem with "nobackground" mode on NetBSD current?Rob Newberry
Re: problem with "nobackground" mode on NetBSD current?Rob Newberry
Re: problem with "nobackground" mode on NetBSD current?Roy Marples
Re: problem with "nobackground" mode on NetBSD current?Rob Newberry
Re: problem with "nobackground" mode on NetBSD current?Rob Newberry
Re: problem with "nobackground" mode on NetBSD current?Roy Marples
Archive administrator: postmaster@marples.name