Skip to content
Snippets Groups Projects

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

Merge request pipeline #32262 passed

Merge request pipeline passed for fa5f8abb

Approved by

Merged by Gaël BonithonGaël Bonithon 5 months ago (Nov 8, 2024 8:25pm UTC)

Merge details

  • Changes merged into master with 92a2a85a (commits were squashed).
  • Deleted the source branch.

Pipeline #32287 passed

Pipeline passed for 92a2a85a on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading