dhcpcd-discuss

Re: dhcpcd-gtk HEAD loops endlessly on start

Roy Marples

Tue Dec 01 13:07:37 2020

On 28/11/2020 16:34, Hanno Zysik wrote:
Am Sat, 28 Nov 2020 14:56:30 +0000
schrieb Roy Marples <roy@xxxxxxxxxxxx>:

Well, I just released dhcpcd-9.3.4 but I doubt it will fix your issue.
Do dhcpcd-online or dhcpcd-qt also loop as such? As they also use the
same library.

With dhcpcd running can you get `dhcpcd -U` to work? As that also
uses the same logic.

Well, the bad code is not in dhcpcd but in dhcpcd-ui. So, that will not
help anyway. But `dhcpcd -U` works, dhcpcd-online not, dhcpcd-qt
not available.

With that behaviour, it is clear, that the code used by `dhcpcd -U` is
not the same as in dhcpcd-ui.

OK, lets try and debug!
The attached patch spits out some debug using dhcpcd-online at least.
On my dev box I see this:

$ ./dhcpcd-online
dhcpcd-online: opened
libdhcpcd: read interface re0:CARRIER
libdhcpcd: read interface re0:BOUND
dhcpcd-online: connected

If you appy the patch to dhcpcd-ui, what do you see?
At every attempt to read an interface it will say something.

Roy
diff --git a/src/libdhcpcd/dhcpcd.c b/src/libdhcpcd/dhcpcd.c
index f1d663f..9f64001 100644
--- a/src/libdhcpcd/dhcpcd.c
+++ b/src/libdhcpcd/dhcpcd.c
@@ -900,21 +900,26 @@ dhcpcd_read_if(DHCPCD_CONNECTION *con, int fd)
 
 	bytes = read(fd, &len, sizeof(len));
 	if (bytes == 0 || bytes == -1) {
+		fprintf(stderr, "libdhcpcd: read1 bytes=%zd\n", bytes);
 		dhcpcd_close(con);
 		return NULL;
 	}
 	if (len >= SSIZE_MAX) {
+		fprintf(stderr, "libdhcpcd: read1 bytes=%zd>SSIZE_MAX\n", bytes);
 		/* Even this is probably too big! */
 		errno = ENOBUFS;
 		return NULL;
 	}
 	rbuf = malloc(len + 1);
-	if (rbuf == NULL)
+	if (rbuf == NULL) {
+		fprintf(stderr, "libdhcpcd: rbuf malloc: %s", strerror(errno));
 		return NULL;
+	}
 	rbufp = rbuf;
 again:
 	bytes = read(fd, rbufp, len);
 	if (bytes == 0 || bytes == -1) {
+		fprintf(stderr, "libdhcpcd: read2 bytes=%zd\n", bytes);
 		free(rbuf);
 		dhcpcd_close(con);
 		return NULL;
@@ -925,6 +930,8 @@ again:
 		goto again;
 	}
 	if ((size_t)bytes != len) {
+		fprintf(stderr, "libdhcpcd: read2 bytes=%zd != len=%zu\n",
+		    bytes, len);
 		free(rbuf);
 		errno = EINVAL;
 		return NULL;
@@ -932,8 +939,14 @@ again:
 	rbufp[bytes] = '\0';
 
 	i = dhcpcd_new_if(con, rbuf, (size_t)((rbufp - rbuf) + bytes));
-	if (i == NULL)
+	if (i == NULL) {
+		fprintf(stderr, "libdhcpcd: error reading if: %s",
+		    strerror(errno));
 		free(rbuf);
+	}
+
+	fprintf(stderr, "libdhcpcd: read interface %s:%s\n",
+	    i->ifname, i->reason);
 	return i;
 }
 
@@ -1070,10 +1083,8 @@ dhcpcd_open(DHCPCD_CONNECTION *con, bool privileged)
 	memcpy(&nifs, cmd, sizeof(nifs));
 	/* We don't dispatch each interface here as that
 	 * causes too much notification spam when the GUI starts */
-	for (n = 0; n < nifs; n++) {
-		if (dhcpcd_read_if(con, con->command_fd) == NULL)
-			goto err_exit;
-	}
+	for (n = 0; n < nifs; n++)
+		dhcpcd_read_if(con, con->command_fd);
 
 	update_status(con, DHC_UNKNOWN);
 

Follow-Ups:
Re: dhcpcd-gtk HEAD loops endlessly on startHanno Zysik
Re: dhcpcd-gtk HEAD loops endlessly on startRoy Marples
References:
dhcpcd-gtk HEAD loops endlessly on startHanno Zysik
Re: dhcpcd-gtk HEAD loops endlessly on startRoy Marples
Re: dhcpcd-gtk HEAD loops endlessly on startHanno Zysik
Re: dhcpcd-gtk HEAD loops endlessly on startRoy Marples
Re: dhcpcd-gtk HEAD loops endlessly on startHanno Zysik
Archive administrator: postmaster@marples.name