After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 770165 - Fix netload.c build on FreeBSD 11 by replacing kvm with getifaddrs and ioctl
Fix netload.c build on FreeBSD 11 by replacing kvm with getifaddrs and ioctl
Status: RESOLVED FIXED
Product: libgtop
Classification: Core
Component: bsd
2.34.x
Other FreeBSD
: Normal normal
: ---
Assigned To: libgtop maintainers
libgtop maintainers
Depends on:
Blocks:
 
 
Reported: 2016-08-20 08:26 UTC by Ting-Wei Lan
Modified: 2016-08-20 14:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Rename --with-libgtop-examples to --with-examples (1005 bytes, patch)
2016-08-20 08:31 UTC, Ting-Wei Lan
committed Details | Review
freebsd: Rewrite netload implementation with getifaddrs and ioctl (16.59 KB, patch)
2016-08-20 08:31 UTC, Ting-Wei Lan
committed Details | Review
freebsd: Support GLIBTOP_IF_FLAGS_WIRELESS in netload (2.76 KB, patch)
2016-08-20 08:31 UTC, Ting-Wei Lan
committed Details | Review

Description Ting-Wei Lan 2016-08-20 08:26:10 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'
Comment 1 Ting-Wei Lan 2016-08-20 08:31:13 UTC
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.
Comment 2 Ting-Wei Lan 2016-08-20 08:31:30 UTC
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
Comment 3 Ting-Wei Lan 2016-08-20 08:31:39 UTC
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).
Comment 4 Robert Roth 2016-08-20 13:51:23 UTC
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
Comment 5 Robert Roth 2016-08-20 14:15:33 UTC
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.