Index: test.tcl ================================================================== --- test.tcl +++ test.tcl @@ -1,10 +1,12 @@ #! /usr/bin/env tclsh puts [exec ./build-dyn.sh] load ./tuapi.so + +::tuapi::modprobe fuse ::tuapi::syscall::tsmf_start_svc blah /bin/true /tmp/logfile [list PATH=/bin] / 022 0 0 10 foreach iface [tuapi::syscall::ifconfig] { #lo0:2: flags=2001000849 mtu 8232 index 1 Index: tuapi.tcl ================================================================== --- tuapi.tcl +++ tuapi.tcl @@ -252,5 +252,56 @@ } } } } + +proc ::tuapi::internal::foreach_line {fd {sep ""} code} { + while {![eof $fd]} { + gets $fd line + + regsub { *#.*$} $line {} line + + if {$line == ""} { + continue + } + + if {$sep == ""} { + set line [split $line] + } else { + set line [split $line $sep] + } + + uplevel 1 [list set line $line] + uplevel 1 $code + } + uplevel 1 [list unset -nocomplain line] +} + +proc ::tuapi::modprobe args { + # Load aliases + set modules_dir [file join /lib/modules $::tcl_platform(osVersion)] + set aliases_file [file join $modules_dir modules.alias] + set fd [open $aliases_file] + ::tuapi::internal::foreach_line $fd { + set alias [lindex $line 1] + set module [lindex $line 2] + + set alias2module($alias) $module + } + + close $fd + + # Load dependencies + set deps_file [file join $modules_dir modules.dep] + ::tuapi::internal::foreach_line $fd ":" { + set module [string trim [lindex $line 0]] + set deps [split [string trim [lrange $line 1 end]]] + puts "$module -> $deps" + } + + # Load modules + foreach modules $args { + foreach module $modules { + } + } +}