TurboVNC / turbovnc

Main TurboVNC repository
https://TurboVNC.org
GNU General Public License v2.0
789 stars 142 forks source link

3D window managers: xinitrc clobbers LD_PRELOAD unless SSH_AGENT_PID environment variable is set #55

Closed dcommander closed 8 years ago

dcommander commented 8 years ago

Under RHEL and Fedora, /etc/X11/xinit/xinitrc-common includes the following code:

RHEL 4-7:

# Prefix launch of session with ssh-agent if available and not already running.
SSH_AGENT=
if [ -z "$SSH_AGENT_PID" ] && [ -x /usr/bin/ssh-agent ]; then
    if [ "x$TMPDIR" != "x" ]; then
        SSH_AGENT="/usr/bin/ssh-agent /bin/env TMPDIR=$TMPDIR"
    else
        SSH_AGENT="/usr/bin/ssh-agent"
  fi
fi

Fedora 22, 24 (possibly earlier releases as well):

# Prefix launch of session with ssh-agent if available and not already running.
if [ -z "$SSH_AGENT" ] && [ -z "$SSH_AGENT_PID" ] && [ -x /usr/bin/ssh-agent ]; 
then
    if [ "x$TMPDIR" != "x" ]; then
        SSH_AGENT="/usr/bin/ssh-agent /bin/env TMPDIR=$TMPDIR"
    else
        SSH_AGENT="/usr/bin/ssh-agent"
    fi
fi

If the SSH_AGENT_PID environment variable is blank, then effectively this code causes the window manager to be launched with ssh-agent, and ssh-agent clobbers the LD_PRELOAD environment variable set by VirtualGL. This was only recently discovered, because I run keychain on all of my development and testing machines, and keychain sets SSH_AGENT_PID, thus working around this issue.

The issue can be reproduced in isolation thusly:

  1. Configure the machine to run full-blown GNOME 3. On RHEL 7, for instance, this involves setting DESKTOP="GNOME" in /etc/sysconfig/desktop (otherwise it will run GNOME 3 Classic.)
  2. /opt/TurboVNC/bin/vncserver -3dwm
  3. DISPLAY=:1 vglrun /usr/bin/ssh-agent /opt/VirtualGL/bin/glxspheres64

This produces a very similar failure to the one that is produced by attempting to run GNOME 3 in VirtualGL without the SSH_AGENT_PID environment variable set:

ERROR: ld.so: object 'libdlfaker.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libvglfaker.so' from LD_PRELOAD cannot be preloaded: ignored.
Polygons in scene: 62464 (61 spheres * 1024 polys/spheres)
Xlib:  extension "GLX" missing on display ":1".
ERROR in line 619:
Could not obtain RGB visual with requested properties
Xlib:  extension "GLX" missing on display ":1".

However, if you swap "vglrun" and "/usr/bin/ssh-agent", it works. Setting SSH_AGENT_PID to some fake value is probably not a good idea, since other applications may try to actually use that value. It makes more sense for xstartup.turbovnc to handle this somehow. I'm looking into that.

Known workarounds:

dcommander commented 8 years ago

Update: This happens in Ubuntu as well, due to some code in /etc/X11/Xsession.d/90x11-common_ssh-agent:

STARTSSH=
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS=

if has_option use-ssh-agent; then
  if [ -x "$SSHAGENT" ] && [ -z "$SSH_AUTH_SOCK" ] \
     && [ -z "$SSH2_AUTH_SOCK" ]; then
    STARTSSH=yes
    if [ -f /usr/bin/ssh-add1 ] && cmp -s $SSHAGENT /usr/bin/ssh-agent2; then
      # use ssh-agent2's ssh-agent1 compatibility mode
      SSHAGENTARGS=-1
    fi
  fi
fi

if [ -n "$STARTSSH" ]; then
  STARTUP="$SSHAGENT $SSHAGENTARGS ${TMPDIR:+env TMPDIR=$TMPDIR} $STARTUP"
fi

This is basically doing the same thing as under RHEL/CentOS/Fedora. If there is no active ssh-agent session, then SSH_AUTH_SOCK will be unset, thus causing the xinit machinery to launch the WM using ssh-agent, thus clobbering LD_PRELOAD.