GNOME Bugzilla – Bug 770165
Fix netload.c build on FreeBSD 11 by replacing kvm with getifaddrs and ioctl
Last modified: 2016-08-20 14:15:33 UTC
libgtop currently fails to build on FreeBSD 11 because it hides several kernel structs from userspace programs, causing compilation error: sysdeps/freebsd/netload.c:99:31: error: field has incomplete type 'struct ifaddr' sysdeps/freebsd/netload.c:100:34: error: field has incomplete type 'struct in_ifaddr' sysdeps/freebsd/netload.c:170:41: error: no member named 'if_ipackets' in 'struct ifnet' sysdeps/freebsd/netload.c:171:42: error: no member named 'if_opackets' in 'struct ifnet' sysdeps/freebsd/netload.c:175:40: error: no member named 'if_obytes' in 'struct ifnet' sysdeps/freebsd/netload.c:178:40: error: no member named 'if_ierrors' in 'struct ifnet' sysdeps/freebsd/netload.c:179:41: error: no member named 'if_oerrors' in 'struct ifnet' sysdeps/freebsd/netload.c:182:41: error: no member named 'if_collisions' in 'struct ifnet'
Created attachment 333725 [details] [review] Rename --with-libgtop-examples to --with-examples This makes what commit 598374b wanted to do really work. The 9-year-old commit was intented to rename the option, but it modified the help string without changing the first argument of AC_ARG_WITH. This patch is unrelated to the bug, but it is very trivial. I think it is not needed to create another bug report for submitting it.
Created attachment 333726 [details] [review] freebsd: Rewrite netload implementation with getifaddrs and ioctl Instead of using a documented and official API to get information related to a network interface, the old implementation uses kvm library to access kernel memory directly, which is not easy to understand and can be easily broken by changing kernel symbols or structs. Besides, FreeBSD 11 hides severai required kernel struct definitions from userspace programs, which causes compilation error because the definition of 'struct ifaddr' is not available unless _KERNEL is defined. This patch is primarily authored by Gleb Smirnoff <glebius@FreeBSD.org>, with other simple modification made by Antoine Brodin <antoine@FreeBSD.org>, Koop Mast <kwm@FreeBSD.org> and Ting-Wei Lan <lantw@src.gnome.org> applied. It was first submitted to FreeBSD ports and has been used by FreeBSD users for more than 18 months on all supported versions of FreeBSD. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194187 https://svnweb.freebsd.org/changeset/ports/371082 https://github.com/freebsd/freebsd-ports-gnome/commit/be884cd https://github.com/freebsd/freebsd-ports-gnome/commit/422a418 https://github.com/freebsd/freebsd-ports-gnome/commit/a4b1913
Created attachment 333727 [details] [review] freebsd: Support GLIBTOP_IF_FLAGS_WIRELESS in netload The ioctl call used in this patch doesn't seems to be documented. It is what ifconfig(8) command uses to display the media type, and its usage can be learned by reading the source code of ifconfig(8).
Thank you for your (and the others') contributions. I have pushed all three patches to the master, without testing, based on your evidence that FreeBSD users have already tested the patches from the ports collection. Indeed, the rename is a simple fix, but let's handle it with this. Attachment 333725 [details] pushed as b68b2ec - Rename --with-libgtop-examples to --with-examples Attachment 333726 [details] pushed as 305701c - freebsd: Rewrite netload implementation with getifaddrs and ioctl Attachment 333727 [details] pushed as 59d9780 - freebsd: Support GLIBTOP_IF_FLAGS_WIRELESS in netload
I have also pushed a new stable version with your fixes (fails to build on FreeBSD deserves it) and the other couple fixes we had piled up.