From 5c6f79744a8bdf4cfb0e91517847281739c3e624 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 11 Aug 2025 05:12:08 -0400 Subject: usr: sysctl: Add parsing for 'proc.*' nodes Signed-off-by: Ian Moffett --- usr.bin/sysctl/sysctl.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/usr.bin/sysctl/sysctl.c b/usr.bin/sysctl/sysctl.c index 1e7f2c0..4a84484 100644 --- a/usr.bin/sysctl/sysctl.c +++ b/usr.bin/sysctl/sysctl.c @@ -46,13 +46,18 @@ #define NAME_NCPU "ncpu" #define NAME_MACHINE "machine" +/* Proc var string constants */ +#define NAME_COUNT "count" + /* Name start string constants */ #define NAME_KERN "kern" #define NAME_HW "hw" +#define NAME_PROC "proc" /* Name start int constants */ #define NAME_DEF_KERN 0 #define NAME_DEF_HW 1 +#define NAME_DEF_PROC 2 /* * Print the contents read from a sysctl @@ -104,6 +109,12 @@ name_to_def(const char *name) return NAME_DEF_HW; } + return -1; + case 'p': + if (strcmp(name, NAME_PROC) == 0) { + return NAME_DEF_PROC; + } + return -1; } @@ -177,6 +188,28 @@ hw_node(const char *node, bool *is_str) return -1; } +/* + * Handle parsing of 'proc.*' node names + * + * @node: Node name to parse + * @is_str: Set to true if string + */ +static int +proc_node(const char *node, bool *is_str) +{ + switch (*node) { + case 'c': + if (strcmp(node, NAME_COUNT) == 0) { + *is_str = false; + return PROC_COUNT; + } + + return -1; + } + + return -1; +} + /* * Convert string node to a sysctl name * definition. @@ -215,6 +248,8 @@ node_to_def(int name, const char *node, bool *is_str) return kern_node(node, is_str); case NAME_DEF_HW: return hw_node(node, is_str); + case NAME_DEF_PROC: + return proc_node(node, is_str); } return -1; -- cgit v1.2.3