# # Copyright (C) 2010 Alexandros Stergiakis <alsterg@gmail.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # #//# # The "kernel" module defines command for low level system configuration. #//# module require base 1.0 module provide kernel 1.0 namespace eval ::module::kernel { namespace import ::helper::* ::module::api::* proc description {} { return "Low level system functions" } proc version {} { } proc check {} { foreach feature [list \ CONFIG_DEPMOD \ CONFIG_LSMOD \ CONFIG_RMMOD \ CONFIG_MODPROBE \ CONFIG_PS \ CONFIG_MOUNT \ CONFIG_WHO \ CONFIG_BB_SYSCTL \ CONFIG_FREE] { if {! [::helper::busybox_has $feature]} { ;# Can return error. error "Busybox doesn't have support for $feature." } } } proc reset {} { variable kernel_modules foreach mod [lreverse $kernel_modules] { exec rmmod $mod lremove kernel_modules $mod } } proc constructor {} { log::Info "Loading \"kernel\" module: [description]" check variable kernel_modules {} reset # Finally load Command Specs sysconf loadspecs "modules/kernel/kernel.specs" } proc destructor {} { # First unload Command Specs sysconf remove "kernel" reset } ################ # Handlers ################ # @limit display IPs command ShUsers {cmdline argstart sid out no arguments args} { if {[dict exists $arguments all]} { exec who -a } else { exec who } } command ShMemory {cmdline argstart sid out no arguments args} { Global PROC_DIR if {[dict exists $arguments detailed]} { ::fileutil::cat [file join $PROC_DIR "meminfo"] } else { exec free } } command ShProtocols {cmdline argstart sid out no arguments args} { Global PROC_DIR ::fileutil::cat [file join $PROC_DIR "net" "protocols"] } command ShKernelFilesystems {cmdline argstart sid out no arguments args} { Global PROC_DIR ::fileutil::cat [file join $PROC_DIR "filesystems"] } command ShProcs {cmdline argstart sid out no arguments args} { exec ps } command ShKernelModules {cmdline argstart sid out no arguments args} { exec lsmod } command ShKernelMounts {cmdline argstart sid out no arguments args} { exec mount } command ShKernelSwaps {cmdline argstart sid out no arguments args} { Global PROC_DIR ::fileutil::cat [file join $PROC_DIR "swaps"] } # @todo Improve formatting. command ShCpu {cmdline argstart sid out no arguments args} { Global PROC_DIR ::fileutil::cat [file join $PROC_DIR "cpuinfo"] } command ShKernelParams {cmdline argstart sid out no arguments args} { if {[dict exists $arguments NAME]} { exec sysctl [dict get $arguments NAME] } else { exec sysctl -a } } command UpdateModules {cmdline argstart sid out no arguments args} { bgexec depmod } # Note: It will try to unload modules loaded by other means as well. # Note: It won't record modules loaded by 'modprobe' in order to satisfy dependencies. command KernelModule {cmdline argstart sid out no arguments args} { variable kernel_modules set mod [dict get $arguments MODULE] if {$no} { exec rmmod $mod lremove kernel_modules $mod ;# will ignore if not loaded by MikroConf } else { exec modprobe $mod lappend kernel_modules $mod } return } proc print_KernelModule {} { variable kernel_modules set result {} foreach m $kernel_modules { append result "kernel module $m\n" } if {! [lempty $result]} { set result "#\n# Kernel Modules:\n${result}\n" } return $result } proc dlist_modules {sid args} { Global MOD_DIR set modules [list] foreach f [::fileutil::findByPattern $MOD_DIR -- *.ko] { if {! [file isfile $f]} { break } lappend modules [file rootname [file tail $f]] } return $modules } } ;# End of Namespace