# vnc-server and FreeBSD 7.2 jail :(



## serhiy (Aug 9, 2009)

Hi, all!

I have FreeBSD 7.2 stable:


```
[root@xxx /]# uname -a
FreeBSD xxx 7.2-STABLE FreeBSD 7.2-STABLE #0: Wed Aug  5 09:46:34 EEST 2009     serhiy@:/usr/obj/usr/src/sys/GENERIC  amd64
```

and i have 2 jails.

I installed vnc-server vnc-4.1.3_2 from port /usr/ports/net/vnc in jail, but i can not run vnc-server 

An error:


```
vncserver: no free display number on xxx.
```

I found this link:
http://www.nabble.com/ports-131758:...fter-multiple-ip-jail-upgrade-td22049448.html

and i do not know how resolved this problem


----------



## osx-addict (Apr 22, 2010)

*Also in F8!!*

I see the same thing w/ FreeBSD 8 stable (in a jail).. I hacked the "vncserver" shell script and the failing call is the socket "bind" that it tries to port 6000 to 6099 and then gives up with the error above.. I modified the perl script to spit out the errno value returned from bind() and I get this :


```
> vncserver
Can't assign requested address at /usr/local/bin/vncserver line 300.
```

Still looking into why this is... Anyone got any ideas?


----------



## osx-addict (Apr 22, 2010)

By the way.. Here's some output captured by truss when running the vncserver script :


```
bind(3,{ sa_len = 2, sa_family = 0, sa_data = { } },16) ERR#49 'Can't assign requested address'
bind(3,{ sa_len = 2, sa_family = 0, sa_data = { } },16) ERR#49 'Can't assign requested address'
```

I'm not sure if possibly the args that perl is providing to the bind() call are correct or not.. Below is errno #49:


```
[EADDRNOTAVAIL]    The specified address is not available from the local
                        machine.
```

I don't think Perl is filling in the bind structure properly if truss is correct.. I don't see a port # or anything as part of the sa_data { }...


----------



## SirDice (Apr 22, 2010)

If I'm not mistaken vncserver only works if there's an already running X.


----------



## osx-addict (Apr 23, 2010)

SirDice said:
			
		

> If I'm not mistaken vncserver only works if there's an already running X.



Nope.. I use it at work all day long.. the "vncserver" script (perl) is there to find an available port and then hand it off to the Xvnc executable which is linked against the X server libraries and is a full x-server but doesn't require a physical display.. I need to write some 'c' code to open a socket, run truss on the code and see if the bind call looks like what the perl code does.. I suspect it'll be different.. Not sure why it's an issue for jails tho..


----------



## osx-addict (Apr 23, 2010)

Ok.. Below is the truss results from some sample server code from here


```
socket(PF_INET,SOCK_STREAM,6)                    = 2 (0x2)
bind(2,{ AF_INET 0.0.0.0:1100 },16)              = 0 (0x0)
```

Just for completeness.. Here's a copy of the above 'bad' lines from the perl script:


```
bind(3,{ sa_len = 2, sa_family = 0, sa_data = { } },16) ERR#49 'Can't assign requested address'
```

I guess the perl script needs tweaking for some reason..


----------



## osx-addict (Apr 23, 2010)

Ok.. Consider this solved.. Can someone please mark it as solved?  Not sure I can do that since i didn't start the thread..

On this page... you will find the changes that are needed for the "vncserver" script.. I've cut-n-pasted the mods below... You'll need to completely replace the CheckDisplayNumber function as follows:


```
#
# CheckDisplayNumber checks if the given display number is available.  A
# display number n is taken if something is listening on the VNC server port
# (5900+n) or the X server port (6000+n).
#
sub CheckDisplayNumber
{
    local ($n) = @_;
    socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
    eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
    if (!bind(S, sockaddr_in(6000 + $n, &INADDR_ANY))) {
        close(S);
        return 0;
    }
    close(S);
    socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
    eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
    if (!bind(S, sockaddr_in(5900 + $n, &INADDR_ANY))) {
        close(S);
        return 0;
    }
    close(S);

    if (-e "/tmp/.X$n-lock") {
        warn "\nWarning: $host:$n is taken because of /tmp/.X$n-lock\n";
        warn "Remove this file if there is no X server $host:$n\n";
        return 0;
    }

    if (-e "/tmp/.X11-unix/X$n") {
        warn "\nWarning: $host:$n is taken because of /tmp/.X11-unix/X$n\n";
        warn "Remove this file if there is no X server $host:$n\n";
        return 0;
    }

    return 1;
}
```

Once this is in place, the vncserver fires up just fine as shown below.. 


```
> ps aux
USER    PID %CPU %MEM   VSZ   RSS  TT  STAT STARTED      TIME COMMAND
myid 18309  0.0  0.1  5540  3100   0  SsJ   9:57PM   0:00.08 -tcsh (tcsh)
myid 18775  0.0  0.3  7884  6116   0  IJ   10:19PM   0:00.02 Xvnc :1 -desktop X -httpd /usr/local/share/tightvnc/classes -auth /home/myid/.Xauthority -geometry 1024x768 -depth 2
myid 18913  0.0  0.0  3396   908   0  R+J  10:25PM   0:00.00 ps aux
```


----------



## osx-addict (Apr 23, 2010)

By the way.. For those of you that may have noticed.. I didn't have a valid 'xstartup' script in my ~/.vnc directory which is why I didn't have anything else running (no twm or equiv,etc).  Once I fixed it, my fvwm came up fine and works like a charm..


----------

