Date: Sat, 20 Aug 2022 02:58:35 GMT From: Alan Somers <asomers@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 5c155bab48c0 - stable/12 - prometheus_sysctl_exporter: ignore ENOENT for mibs specified on the CLI Message-ID: <202208200258.27K2wZTC052153@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=5c155bab48c09e7a34bec8fb6a16164d26c1629c commit 5c155bab48c09e7a34bec8fb6a16164d26c1629c Author: Alan Somers <asomers@FreeBSD.org> AuthorDate: 2022-06-21 18:51:14 +0000 Commit: Alan Somers <asomers@FreeBSD.org> CommitDate: 2022-08-20 02:58:12 +0000 prometheus_sysctl_exporter: ignore ENOENT for mibs specified on the CLI They might belong to kernel modules not currently loaded, or to other kernel versions. Ignoring them allows the configuration to be shared between multiple hosts. Sponsored by: Axcient Reviewed by: rew Differential Revision: https://reviews.freebsd.org/D35540 (cherry picked from commit 982f980b86d6bab4d55452d17bf3f5eb04e5f01e) --- .../prometheus_sysctl_exporter.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c index e452e305d2bf..931d8e965d00 100644 --- a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c +++ b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c @@ -67,13 +67,12 @@ oid_get_root(struct oid *o) } /* Obtains the OID for a sysctl by name. */ -static void +static bool oid_get_by_name(struct oid *o, const char *name) { o->len = nitems(o->id); - if (sysctlnametomib(name, o->id, &o->len) != 0) - err(1, "sysctl(%s)", name); + return (sysctlnametomib(name, o->id, &o->len) == 0); } /* Returns whether an OID is placed below another OID. */ @@ -644,7 +643,15 @@ main(int argc, char *argv[]) for (i = 0; i < argc; ++i) { struct oid o, root; - oid_get_by_name(&root, argv[i]); + if (!oid_get_by_name(&root, argv[i])) { + /* + * Ignore trees provided as arguments that + * can't be found. They might belong, for + * example, to kernel modules not currently + * loaded. + */ + continue; + } o = root; do { oid_print(&o, &on, print_descriptions, exclude, include, fp);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202208200258.27K2wZTC052153>