VboxXPCOMIPCD binding on wrong ports

Discussions related to using VirtualBox on Linux hosts.
Post Reply
Rynor
Posts: 1
Joined: 11. Aug 2008, 17:28

VboxXPCOMIPCD binding on wrong ports

Post by Rynor »

Hello,

I'm currently playing around a bit with python / django and I though it might be fun to create some kind of webbased manager for VirtualBox.

To test my code I use the builtin webserver in Django, this webserver runs on port 8000 by default, but can be run on any port specified.

I'm currently using the following call to start a virtual machine through the web interface:

Code: Select all

output = os.popen("VBoxManage startvm "+uuid+" -type gui").read()
Now as long as the builtin webserver is running, nothing is wrong. The webserver restarts itself as soon as I modify the code.

The weird thing is that every time a virtual machine is started VboxXPCOMIPCD binds on the port used by the django builtin webserver as soon as the server releases the port, for example to reload the python code.

Here's an example, I've started it on port 12625 now, but it happens with every port I specify.

Code: Select all

Django version 0.96.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:12625/
Quit the server with CONTROL-C.

[11/Aug/2008 17:35:27] "GET /machine/e3544270-83a0-4b1e-60a9-58ebb6cef2db/start/ HTTP/1.1" 200 302
Then I restart the server:

Code: Select all

Django version 0.96.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:12625/
Quit the server with CONTROL-C.
Error: That port is already in use.
and netstat shows:

Code: Select all

netstat -lnp | grep -i vbox
tcp        0      0 127.0.0.1:12625         0.0.0.0:*               LISTEN      10945/VBoxXPCOMIPCD
Does anyone know why this is happening?
jdimpson
Posts: 1
Joined: 10. Feb 2009, 02:53

Post by jdimpson »

I don't know python/django, but i would guess that the following is occurring. When the web server starts, it opens the listen socket on port 8000. Then it starts vboxmanage, which in turn starts up all the virtual box processes, including vboxxpcomipcd.

In order to start the virtualbox child processes, any unix/linux-based system uses the fork() and exec() system calls (technically, linux systems could use clone(), but it usually has the same behaviour). Child processes inherit from the parent all the parent's open file descriptors. In this case, I would imagine vboxxpcomipcd isn't actually opening the listen socket, but always has it open and is just not closing it.

Again, I don't know the python/django environments, but I imagine that a fork()/exec() is going on under the call to os.popen(). Your simplest solution is to call os.popen() before binding on the listen socket. If that's not possible, you'll either have to figure out how to make popen() close the socket file descriptor between doing for() and exec(), or perhaps you'll have to forgo using os.popen() and do the direct fork()/exec() calls yourself, closing the socket after fork() but before exec(). You could also try to make vboxmanage and/or vboxxpcomipcd close the inherited socket on start up, but I assume you don't want to modify them just to achieve this.

Jeremy
Post Reply