[kernel,cmds] Add sysctl system call and option get/set command by ghaerr · Pull Request #1897 · ghaerr/elks (original) (raw)

Adds new lightweight sysctl(int op, char *name, int *value) system call and
sysctl [-a] [option_name[=value]] utility. syscall -a lists all available options and their values.

These enhancements are for some upcoming functionality that allows for turning on and off various options at runtime, such as malloc debugging information, TCP/IP options, etc. The combination allows for both querying a human-readable option "name" value and and its associated (currently numeric only) value. The sysctl command is also scriptable, for easy test integration. The combination allows for application programs to query and set information, which previously required special techniques.

The planned usage might be something like sysctl malloc.debug=1 to turn on level 1 malloc debug output, for instance, or communicating with a running ktcp by using sysctl net.debug=3, etc. The option names are just string values defined in the kernel and associated with an int variable.

The current list of options are:

# sysctl -a
kern.debug=1       # ^P kernel debug messages on/off
kern.strace=0      # kernel strace=1, kstack=2 with CONFIG_TRACE=y
kern.console=1024  # console device (e.g. 0x440 for /dev/ttyS0)
malloc.debug=0     # not yet implemented
net.debug=0        # not yet implemented

Ideas for future options are welcomed.