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 {


On Sun, 2 Apr 2023 at 16:18, Debian Bug Tracking System <
ow...@bugs.debian.org> wrote:

> Thank you for the additional information you have supplied regarding
> this Bug report.
>
> This is an automatically generated reply to let you know your message
> has been received.
>
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
>
> Your message has been sent to the package maintainer(s):
>  Michael Meskes <mes...@debian.org>
>
> If you wish to submit further information on this problem, please
> send it to 1033...@bugs.debian.org.
>
> Please do not send mail to ow...@bugs.debian.org unless you wish
> to report a problem with the Bug-tracking system.
>
> --
> 1033716: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1033716
> Debian Bug Tracking System
> Contact ow...@bugs.debian.org with problems
>

Reply via email to