Fix BSD `glibtop_get_netload: Function not implemented` error
This fixes #22 (closed) by adding glibtop_init()
when plugin inits.
It is Ok when only use one command from libgtop, whether glibtop_get_netlist()
or glibtop_get_netload()
works fine when they are the only command used by one program. but combinations could trigger Function not implemented
error.
This bug seems not triggered on Linux, but all BSDs might be affected (OpenBSD/NetBSD/FreeBSD/Darwin).
Reproduce:
// cc -DCASE_1 reproduce.c -o test_netlist
// cc -DCASE_2 reproduce.c -o test_netload
// cc -DUSE_BOTH reproduce.c -o test_combine
// cc -DINIT -DUSE_BOTH reproduce.c -o test_combine_with_init
// test_combine is expected to trigger error:
// [ERROR] glibtop_get_netload: Function not implemented
#include <stdio.h>
#include <glibtop/netlist.h>
#include <glibtop/netload.h>
int main()
{
glibtop_netload netload;
glibtop_netlist netlist;
#ifdef INIT
glibtop_init();
#endif
#if defined(CASE_1)
char **interfaces = glibtop_get_netlist (&netlist);
for (int i = 0; i < netlist.number; ++i) {
printf("interfaces[%d]: %s\n", i, interfaces[i]);
}
#elif defined(CASE_2)
glibtop_get_netload (&netload, "en0");
printf("netload.bytes_total: %llu\n", netload.bytes_total);
#elif defined(USE_BOTH)
char **interfaces = glibtop_get_netlist (&netlist);
for (int i = 0; i < netlist.number; ++i) {
glibtop_get_netload (&netload, interfaces[i]);
printf("%s: netload.bytes_total: %llu\n", interfaces[i], netload.bytes_total);
}
#endif
glibtop_close();
return 0;
}
Merge request reports
Activity
mentioned in merge request !41 (merged)
changed milestone to %v1.3.3
/cc @landry
i can confirm that this fixes the crash at plugin startup i was seeing in #22 (closed). I'll push another MR on top to fix the build failure about
guint64
vsgulong
ah, the
guint64
vsgulong
thing was fixed in 13a2e3ec for #25 (closed) / #28 (closed), good. So merging this MR will close #22 (closed)