
The new MIB service implements the sysctl(2) system call which, as we adopt more NetBSD code, is an increasingly important part of the operating system API. The system call is implemented in the new service rather than as part of an existing service, because it will eventually call into many other services in order to gather data, similar to ProcFS. Since the sysctl(2) functionality is used even by init(8), the MIB service is added to the boot image. MIB stands for Management Information Base, and the MIB service should be seen as a knowledge base of management information. The MIB service implementation of the sysctl(2) interface is fairly complete; it incorporates support for both static and dynamic nodes and imitates many NetBSD-specific quirks expected by userland. The patch also adds trace(1) support for the new system call, and adds a new test, test87, which tests the fundamental operation of the MIB service rather thoroughly. Change-Id: I4766b410b25e94e9cd4affb72244112c2910ff67
41 lines
1.1 KiB
C
41 lines
1.1 KiB
C
#include <sys/cdefs.h>
|
|
#include <lib.h>
|
|
#include "namespace.h"
|
|
#include "extern.h"
|
|
#include <string.h>
|
|
|
|
/*
|
|
* The sysctl(2) system call, handled by the MIB service.
|
|
*/
|
|
int
|
|
__sysctl(const int * name, unsigned int namelen, void * oldp, size_t * oldlenp,
|
|
const void * newp, size_t newlen)
|
|
{
|
|
message m;
|
|
int r;
|
|
|
|
memset(&m, 0, sizeof(m));
|
|
m.m_lc_mib_sysctl.oldp = (vir_bytes)oldp;
|
|
m.m_lc_mib_sysctl.oldlen = (oldlenp != NULL) ? *oldlenp : 0;
|
|
m.m_lc_mib_sysctl.newp = (vir_bytes)newp;
|
|
m.m_lc_mib_sysctl.newlen = newlen;
|
|
m.m_lc_mib_sysctl.namelen = namelen;
|
|
m.m_lc_mib_sysctl.namep = (vir_bytes)name;
|
|
if (namelen <= CTL_SHORTNAME)
|
|
memcpy(m.m_lc_mib_sysctl.name, name, sizeof(*name) * namelen);
|
|
|
|
r = _syscall(MIB_PROC_NR, MIB_SYSCTL, &m);
|
|
|
|
/*
|
|
* We copy the NetBSD behavior of replying with the old length also if
|
|
* the call failed, typically with ENOMEM. This is undocumented
|
|
* behavior, but unfortunately relied on by sysctl(8) and other NetBSD
|
|
* userland code. If the call failed at the IPC level, the resulting
|
|
* value will be garbage, but it should then not be used anyway.
|
|
*/
|
|
if (oldlenp != NULL)
|
|
*oldlenp = m.m_mib_lc_sysctl.oldlen;
|
|
|
|
return r;
|
|
}
|