I think the problem is that the '/proc/net/dev' command returns 'unsigned
long long' (see here:
https://github.com/raspberrypi/linux/blame/rpi-6.1.y/net/core/net-procfs.c#L82),
but the watchdog 'iface.c' code uses 'unsigned long', which causes the
'bytes' to always be 4294967295 (0xFFFF FFFF or ULONG_MAX). There is no
check that the 'strtoul' operation has been successful.
Recompiling the watchdog using 'unsigned long long' for 'bytes' and
changing 'strtoul' to 'stroull' apparently solved the problem for me after
doing a quick test. See changes below.
I would add the additional checks for "strtoull" to at least add a warning
in the logs if this is happening in the future. Maybe even better it would
be to use 'u64' instead of 'unsigned long long', as that's what is stored
anyway in "struct rtnl_hw_stats64" where "rx_bytes" that we read are
stored. However, they are printed as "%llu" so maybe better to keep as is?
diff --git a/iface.c.orig b/iface.c
index 5db4e55..7b5eba6 100644
--- a/iface.c.orig
+++ b/iface.c
@@ -41,11 +41,11 @@ int check_iface(struct list *dev)
for (; line[i] == ' ' || line[i] == '\t'; i++) ;
if (strncmp(line + i, dev->name, strlen(dev->name))
== 0) {
- unsigned long bytes = strtoul(line + i +
strlen(dev->name) + 1, NULL, 10);
+ unsigned long long bytes = strtoull(line +
i + strlen(dev->name) + 1, NULL, 10);
/* do verbose logging */
if (verbose && logtick && ticker == 1)
- log_message(LOG_DEBUG, "device %s
received %lu bytes", dev->name, bytes);
+ log_message(LOG_DEBUG, "device %s
received %llu bytes", dev->name, bytes);
if (dev->parameter.iface.bytes == bytes) {
fclose(file);
diff --git a/extern.h b/extern.h.orig
index 2eccf0b..81bc620 100644
--- a/extern.h
+++ b/extern.h.orig
@@ -30,7 +30,7 @@ struct filemode {
};
struct ifmode {
- unsigned long long bytes;
+ unsigned long bytes;
};
struct tempmode {