Wednesday, January 13, 2010

Executing host commands from Inferno using cmd filesystem interface ( '#C' )

This blog is about using ability of inferno to execute commands on host OS using filesystem interface. As this project plans to use Inferno as middleware for distributing jobs transparently this interface is important.

The easiest way to execute host command on inferno is by using os command.

; os ls /

Above is the example of executing ls / on host OS.

For using filesystem interface, you can use devcmd or devcmd2 synthetic filesystems.
devcmd2 is extension of devcmd with few improvements. We will stick to devcmd
for purpose of this blog.

You can go into this filesystem by either doing cd or by binding it.

; cd '#C'

This filesystem can be binded to your namespace by following command.

bind '#C' /cmd
cd /cmd


Now, lets see how we can execute commands using this filesystm.

; cd cmd
; ls
clone
; cat clone
0
; cd 0
; ls
ctl
data
status
stderr
wait
; echo exec fortune > ctl
; cat data
Hope that the day after you die is a nice day.
;

What has happened above is we created new resource by catting clone. This resource was 0. So, we cd to 0 for using this resource. We execute the fortune command by echoing it into ctl file. You can execute any command here. After this you can cat the data file for command output and stderr for any errors.

For devcmd2 output will be in stdio file instead of data.

If you don't have fortune command on your system, then go ahead and install it using apt-get install fortune. It is brilliant way to waste time :-).

No comments:

Post a Comment