]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Force dumplease to parse stdin
authorBrett Holman <bholman.devel@gmail.com>
Sat, 20 Jan 2024 01:43:26 +0000 (18:43 -0700)
committerRoy Marples <roy@marples.name>
Mon, 17 Jun 2024 08:48:16 +0000 (09:48 +0100)
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 #285

src/dhcpcd.c

index a94dbdacc9bae5290bffce7e2fb4455010b8be29..84b4d8f11b7ba1c347a80fd72eda0904567aebfa 100644 (file)
@@ -29,7 +29,6 @@
 static const char dhcpcd_copyright[] = "Copyright (c) 2006-2023 Roy Marples";
 
 #include <sys/file.h>
-#include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -2278,8 +2277,10 @@ printpidfile:
 
 #ifndef SMALL
        if (ctx.options & DHCPCD_DUMPLEASE &&
-           ioctl(fileno(stdin), FIONREAD, &i, sizeof(i)) == 0 &&
-           i > 0)
+           i > 0 &&
+           ctx.ifc == 1 &&
+           strlen(ctx.ifv[0]) == 1 &&
+           ctx.ifv[0][0] == '-')
        {
                ctx.options |= DHCPCD_FORKED; /* pretend child process */
 #ifdef PRIVSEP