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.
This commit is contained in:
parent
884748cf55
commit
e492f03505
@ -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;
|
||||
const char *header[] = {
|
||||
"---Loader Environment---", "---Static Environment---" };
|
||||
const int headerlen = 128; /* conservative */
|
||||
struct sbuf *sb;
|
||||
int error, len;
|
||||
char *cp;
|
||||
|
||||
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);
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user