Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option 2: Fix stdin parsing #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

holmanb
Copy link

@holmanb holmanb commented Jan 20, 2024

This is my second fix #285. It checks if there was a single "interface" argument passed and if that argument value is -. If such an argument exists, then dhcpcd forcibly waits on stdin. This also removes the unreliable "check if the stdin buffer is full" semantics, which I don't think should break other use cases. Running dhcpcd -U <interface> will work just like it did before, by contacting the network manager[1]. I assume you prefer this fix over the first one I wrote, because that one breaks the "no interface means dump all interfaces" expectation, but I still offered both fixes for you to decide because that documented expectation also appears broken.

[1] this requirement also seems like a bug when the lease file has already been acquired with a --oneshot call, but as long as we have some stable way across releases to parse a lease without the daemon running I guess I don't care strongly if that one of these gets fixed

Checking if data exists in the stdin buffer via an ioctl is
unreliable. Allow a user to pass '-' to force stdin parsing.
This provides a fix that will allow "no interfaces" to still
mean "dump all interfaces".

Fixes NetworkConfiguration#285
@holmanb
Copy link
Author

holmanb commented Jan 20, 2024

Aside: Apologies for the flurry of similar issues filed and multiple PRs for the same issue. I'm currently trying to document what I see as unexpected / broken behavior, and (for now) fix the ones that I see as most important (#285 and also #282, which I see now has a PR waiting review: #284).

@@ -2243,8 +2242,10 @@ main(int argc, char **argv, char **envp)

#ifndef SMALL
if (ctx.options & DHCPCD_DUMPLEASE &&
ioctl(fileno(stdin), FIONREAD, &i, sizeof(i)) == 0 &&
i > 0)
i > 0 &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why checking i > 0? I used to contain the number of bytes in STDIN, now it is undefined as you removed the ioctl which set it.

@rsmarples
Copy link
Member

You'll need to change dhcpcd.8.in as well to document the new requirement for dumping leases needing the - part.
Luckily interface names cannot start with a - so this is a safe change.

@holmanb
Copy link
Author

holmanb commented Mar 11, 2024

Thanks for the review @rsmarples. I'm busy now, but will try to get back to this PR in the next few weeks if possible. Otherwise I plan circle back to this after the next Ubuntu release.

@perkelix
Copy link
Contributor

perkelix commented May 7, 2024

@holmanb Has this made any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dhcpcd -U intermittently fails if stdin is connected to a pipe
3 participants