vnstat on FreeBSD 9 broken (with quick fix)

Not sure if I'm the only one having this problem. On multiple machines running FBSD9-beta2 (amd64), vnstat 1.11 does not work properly. It seems to work fine on various FBSD 7 and 8 systems.

The symptom was the error "Not enough data available yet." no matter how many times the databases were updated with `vnstat -u`. Running it in live mode and as a daemon shows 0 bytes and 0 packets on the interface(s).

Using -D showed that interface statistics were not being retrieved correctly; consequently, they could not be calculated:

Code:
cc: 6510615555426900570 - 6510615555426900570 = 0
cc: 6510615555426900570 - 6510615555426900570 = 0
cc: 6510615555426900570 - 6510615555426900570 = 0
cc: 6510615555426900570 - 6510615555426900570 = 0

At first I thought the method to retrieve interface statistics changed between FBSD 8 and 9, but then after a few debug printf()s, I tracked the problem down to the readifaddrs() function in ifinfo.c

I found that moving the call to freeifaddrs(ifap) from before the last "if" block to after it (and right before the final return) would allow the statistics to be retrieved and calculated correctly.

I have no idea if this is the proper fix, and don't know why this would make a difference between the FBSD versions, except that maybe this is one of those compiler quirks.

Hope this helps someone.

Copy and pasted diff -u:
Code:
--- ifinfo.c.orig       2011-09-23 01:13:22.544097251 -0400
+++ ifinfo.c    2011-09-23 01:13:36.813101878 -0400
@@ -420,7 +420,6 @@
                        break;
                }
        }
-       freeifaddrs(ifap);

        if (check == 0) {
                if (debug)
@@ -435,6 +434,7 @@
                ifinfo.filled = 1;
        }

+       freeifaddrs(ifap);
        return 1;
 }
 #endif
 
The patch fixes the problem :) Sorry for the long time ;| I was a little busy in the past few months. Does the patch run without problems on 7/8/9?

-dhn
 
adox said:
The patch fixes the problem :) Sorry for the long time ;| I was a little busy in the past few months. Does the patch run without problems on 7/8/9?

-dhn

Sorry, I'm not in a position to test it on 7 or 8 right now. As far as I know, it is unnecessary on those versions. It was only necessary on 9, and I haven't tried recompiling it any time recently (between then and now, since RC1 has come out).
 
Back
Top