diff options
author | jlemon <jlemon@FreeBSD.org> | 2001-09-20 20:09:37 +0000 |
---|---|---|
committer | jlemon <jlemon@FreeBSD.org> | 2001-09-20 20:09:37 +0000 |
commit | 151b089e557038e96bc55875ed62c5ea7a30da37 (patch) | |
tree | c7c21fa6276ec0c4fe5232d61b9df54a23de34ea | |
parent | 7e6f69ce22a4606761ef35d9080eaa39a1e62cbd (diff) | |
download | FreeBSD-src-151b089e557038e96bc55875ed62c5ea7a30da37.zip FreeBSD-src-151b089e557038e96bc55875ed62c5ea7a30da37.tar.gz |
Add a sysctl MIB 'kern.env', that dumps the contents of the kernel
environment from the loader, as well as the kernel's compiled in static
hints.
-rw-r--r-- | sys/kern/kern_environment.c | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c index 6769c06..0ce8e63 100644 --- a/sys/kern/kern_environment.c +++ b/sys/kern/kern_environment.c @@ -41,6 +41,7 @@ #include <sys/systm.h> #include <sys/sysctl.h> #include <sys/libkern.h> +#include <sys/sbuf.h> char *kern_envp; @@ -104,35 +105,33 @@ getenv_quad(const char *name, quad_t *data) static int sysctl_kernenv(SYSCTL_HANDLER_ARGS) { - int *name = (int *)arg1; - u_int namelen = arg2; - char *cp; - int i, error; - - if (kern_envp == NULL) - return(ENOENT); - - name++; - namelen--; - - if (namelen != 1) - return(EINVAL); - - cp = kern_envp; - for (i = 0; i < name[0]; i++) { - cp = kernenv_next(cp); - if (cp == NULL) - break; - } - - if (cp == NULL) - return(ENOENT); - - error = SYSCTL_OUT(req, cp, strlen(cp) + 1); - return (error); + const char *header[] = { + "---Loader Environment---", "---Static Environment---" }; + const int headerlen = 128; /* conservative */ + struct sbuf *sb; + int error, len; + char *cp; + + len = 0; + for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) + len += strlen(cp) + 1; + for (cp = static_hints; cp != NULL; cp = kernenv_next(cp)) + len += strlen(cp) + 1; + sb = sbuf_new(NULL, NULL, len + headerlen, 0); + sbuf_printf(sb, "\n%s\n", header[0]); + for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) + sbuf_printf(sb, "%s\n", cp); + sbuf_printf(sb, "\n%s\n", header[1]); + for (cp = static_hints; cp != NULL; cp = kernenv_next(cp)) + sbuf_printf(sb, "%s\n", cp); + sbuf_finish(sb); + error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb)); + sbuf_delete(sb); + return (error); } -SYSCTL_NODE(_kern, OID_AUTO, environment, CTLFLAG_RD, sysctl_kernenv, "kernel environment space"); +SYSCTL_OID(_kern, OID_AUTO, env, CTLTYPE_STRING | CTLFLAG_RD, + NULL, 0, sysctl_kernenv, "A", "Kernel environment"); /* * Find the next entry after the one which (cp) falls within, return a |