Re: git: b9600db494a0 - main - prometheus_sysctl_exporter: Replace magic numbers with identifiers.

From: George Kontostanos <gkontos.mail_at_gmail.com>
Date: Wed, 26 Apr 2023 14:35:28 UTC
unsubscribe

On Wed, Apr 26, 2023 at 11:30 AM Peter Jeremy <peterj@freebsd.org> wrote:
>
> The branch main has been updated by peterj:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=b9600db494a04db6fbf1a16dbcf92f7c64d5e863
>
> commit b9600db494a04db6fbf1a16dbcf92f7c64d5e863
> Author:     Peter Jeremy <peterj@FreeBSD.org>
> AuthorDate: 2023-04-26 08:29:33 +0000
> Commit:     Peter Jeremy <peterj@FreeBSD.org>
> CommitDate: 2023-04-26 08:29:33 +0000
>
>     prometheus_sysctl_exporter: Replace magic numbers with identifiers.
>
>     Identifiers make it clearer what is going on and makes it easier to
>     find consumers of sysctl functionality.
>
>     No functional change.
>
>     MFC after:      3 days
>     Reviewed by:    asomers
>     Differential Revision:  https://reviews.freebsd.org/D39797
> ---
>  .../prometheus_sysctl_exporter.c                       | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c
> index 931d8e965d00..6c20d639a6d3 100644
> --- a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c
> +++ b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c
> @@ -62,7 +62,7 @@ static void
>  oid_get_root(struct oid *o)
>  {
>
> -       o->id[0] = 1;
> +       o->id[0] = CTL_KERN;
>         o->len = 1;
>  }
>
> @@ -91,8 +91,8 @@ oid_get_next(const struct oid *cur, struct oid *next)
>         int lookup[CTL_MAXNAME + 2];
>         size_t nextsize;
>
> -       lookup[0] = 0;
> -       lookup[1] = 2;
> +       lookup[0] = CTL_SYSCTL;
> +       lookup[1] = CTL_SYSCTL_NEXT;
>         memcpy(lookup + 2, cur->id, cur->len * sizeof(lookup[0]));
>         nextsize = sizeof(next->id);
>         if (sysctl(lookup, 2 + cur->len, &next->id, &nextsize, 0, 0) != 0) {
> @@ -135,8 +135,8 @@ oid_get_format(const struct oid *o, struct oidformat *of)
>         int lookup[CTL_MAXNAME + 2];
>         size_t oflen;
>
> -       lookup[0] = 0;
> -       lookup[1] = 4;
> +       lookup[0] = CTL_SYSCTL;
> +       lookup[1] = CTL_SYSCTL_OIDFMT;
>         memcpy(lookup + 2, o->id, o->len * sizeof(lookup[0]));
>         oflen = sizeof(*of);
>         if (sysctl(lookup, 2 + o->len, of, &oflen, 0, 0) != 0) {
> @@ -344,8 +344,8 @@ oid_get_name(const struct oid *o, struct oidname *on)
>         size_t i, len;
>
>         /* Fetch the name and split it up in separate components. */
> -       lookup[0] = 0;
> -       lookup[1] = 1;
> +       lookup[0] = CTL_SYSCTL;
> +       lookup[1] = CTL_SYSCTL_NAME;
>         memcpy(lookup + 2, o->id, o->len * sizeof(lookup[0]));
>         len = sizeof(on->names);
>         if (sysctl(lookup, 2 + o->len, on->names, &len, 0, 0) != 0)
> @@ -464,8 +464,8 @@ oid_get_description(const struct oid *o, struct oiddescription *od)
>         char *newline;
>         size_t odlen;
>
> -       lookup[0] = 0;
> -       lookup[1] = 5;
> +       lookup[0] = CTL_SYSCTL;
> +       lookup[1] = CTL_SYSCTL_OIDDESCR;
>         memcpy(lookup + 2, o->id, o->len * sizeof(lookup[0]));
>         odlen = sizeof(od->description);
>         if (sysctl(lookup, 2 + o->len, &od->description, &odlen, 0, 0) != 0) {
>


-- 
George Kontostanos
---