This is the mail archive of the cygwin-xfree mailing list for the Cygwin XFree86 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: remote xterm's can't open display after upgrade


JimE wrote:


Hi Don,
I'm in the same boat. I just upgraded cygwin and now I can't get remote xterms to display on the local machine.
----
	Question -- Is your local machine on a closed net?

I.e. My windows machine is on a local subnet (example: 192.168.x.y) that isn't
(usually) exposed to the internet.

1st thing to note, is that my win X server starts automatically
when I log into windows (well it usually does unless some "upgrade"[sic]
makes something incompat), BUT, less likely to have problems, as
I start the X-server via my *own* script in my homedir's "bin" dir.

I.e. the shortcut on my QuickLaunch Bar (yeah, running W7 and still
using that...)... has

Target:  C:\bin\bash.exe -c '"%USERPROFILE%/bin/startxwin.sh"'
Startin: %HOMEDRIVE%%HOMEPATH%
---

my startxwin.sh is mostly free of non-cygwin deps, except
for a tray-message util, "notify" which lets me put up messages
if the server is already running and such.

----
I'll leave in the comments (mostly NOTES to self or
OLD code...)... but if you know shell script, shouldn't be
hard to modify to your use case.

Some things (like a "mount -c /") at the beginning
of the script have been added over the years to
increase robustness.

This script hasn't been "cleaned" for looking good
or best coding style, but given how often I need to
maintain or change it, I haven't been motivated.

It has disabled code that tried to start dbus, but
it didn't work reliably, so it's commented out.

Parts were rewritten to try to minimize use of non-shell,
external commands (minimize deps, efficiency).

Note 1: If you want to use this in an unsecure network,
then you need to start this through an "ssh" command to
the remote machine and not reset the DISPLAY...

Note 2: one thing this script does that the cygwin
script does not do -- it tries to read your display's
"DPI" and set the corresponding option in the X-display.



---------------------extra config file: (optional) ~/.mind/Xserver-dflt-overrrides----
+ac
---------------------bash script: startxwin.sh





#!/bin/bash
# (c) LA Walsh 2004-2014, licenced under GPLv2 and/or to nice people
#export DISPLAY=:0
#export XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
#export XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
#export XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
#export XNLSPATH=/usr/X11R6/lib/X11/locale
#unexport XAPPLRESDIR XCMSDB XKEYSYMDB XNLSPATH

# see cygwin Xwin for more option examples
# relevant ops:
# -multiwindow = use windows manage; not w/(-rootless|-fullscreen)
# -clipboard = use built-in version (integrated w/windows)
# -unixkill = Enable Ctrl-Alt-BS as X-server shutdown cmnd
# -nowinkill = Disable Alt+F4 as a server shutdown key combination.
# -trayicon = (default) windows tray icon enabled

mount -c /
export PATH=/bin:$(/bin/cygpath "$USERPROFILE")/bin:$PATH #ensure our bin is 1st
shopt -s expand_aliases extglob
alias notify=$(type -P notifu)
alias int=declare\ -i
alias sub=function
alias xset=$(type -P xset);
alias array=declare\ -a
alias my=declare

export DISPLAY="${DISPLAY:-":0"}"

sub xup {
  local stat
  read -t .1 stat <<<$(xset q >&/dev/null; echo $?)   &&
        return $stat
  ((-1))
}
sub Xwin_pids {
  ( cd /proc  &&
      for p in +([0-9])/ ;do
        p2=${p%/}
        prg=$(<${p2}/exename)
        if [[ $prg =~ .*XWin ]]; then
          printf "%d:%s\n" "$p2" "$prg"
        fi
      done
  )
}

#sub Xwin_pid { echo $(/bin/ps -s|/bin/awk -- '/\?.*XWin/{print $1}') ; }

sub Xwin_pid {
  array Xprgs
  readarray Xprgs< <(Xwin_pids)
  if ((!${#Xprgs[@]}));then
    echo 0
    return 1
  fi
  my x=${Xprgs[0]}
  my pid=${x%%:**} prg=${x##*:}
  array out=( "$pid" "$prg")
  printf "%s " "${out[@]}"
  printf "\n"
  return 0
}

sub Xwin_running {
  int pd; my pg
  read pd pg < <(Xwin_pid)
  return $(((!pd)))
}
export -f Xwin_pids Xwin_pid


#sub Xwin_pid { echo $(/bin/ps -s|/bin/awk -- '/\?.*XWin/{print $1}') ; }
#export -f Xwin_pid
#sub Xwin_running { [[ $(Xwin_pid) ]] ; }
#export TERM=15 KILL=9

sub tidy_old_Xwin {
  local -a sigs=(TERM TERM KILL)  # try 2 TERMs then KILL upto maxsigs
  int pd; my pg
  int maxsigs=3 lastsig=${#sigs[*]}
  while ((1)); do
    read pd pg < <(Xwin_pid)
    ((pd)) || break
    #int i=--maxsigs>lastsig ? lastsig:maxsigs
    kill -${sigs[--maxsigs>lastsig ? lastsig:maxsigs]} $pd
    ((maxsigs)) || break
    sleep 1
  done
  rm -fr /tmp/.X11-unix
}


sub get_dpi {
dpi=$(regtool -d get '/HKLM/Software/Microsoft/Windows NT/CurrentVersion/FontDPI/LogPixels')
  # check for insane values
  ((dpi<50||dpi>>400)) && dpi=96
  echo "$dpi"
}

sub get_fontpath {
local fontpath="/usr/share/TTF,built-ins,/usr/share/fonts/misc,/usr/share/fonts/100dpi"
  echo -n "$fontpath"
}

sub start_XWin {
local fontpath="/usr/share/fonts/TTF,built-ins,/usr/share/fonts/misc,/usr/share/fonts/100dpi"
  int dpi=$(get_dpi)
  cmd="/bin/run /bin/XWin  ${dpi:+-dpi $dpi}
    -nomultimonitors -clipboard  -ac -unixkill -nowinkill -wgl
    -bs -fp "$fontpath" -multiwindow"
  echo cmd="$cmd"
  $cmd
}

declare -a default_switches=(-dpi -clipboard -unixkill -nowinkill -bs -ac -fp -multiwindow -wgl)

readarray -t args< <(
a="$default_switches[@]"; IFS=$'\n'; echo "${a[*]#?}"|sort -k1.2 )

sub read_users_mind { #(reads file in lieu of HW support for actual)
  if [[ -O ~/.mind && -O ~/.mind/Xserver-dflt-overrides ]]; then
    readarray -t overrides < <( -x
    <~/.mind/Xserver-dflt-overrides perl -wnE '
    chomp; s/\s*(?:#.*)?$//; s/^\s*// s/\s\s+/\s/ ; $_ || next;
    print $_."\n" ')
  fi
  typeset -a switches
}

sub  start_dbus {
  /bin/run /bin/dbus-launch --exit_with_session ~/.Xsession
}


sub _in {
  local x=${1:?};shift
  for ((;$#>0;)); do [[ $x == $1 ]] && return 0;shift; done
  return 1
}


int tries=3

if Xwin_running && xup; then
  notify /t info /m "Xserver already running and ready" /d 5000
else
  echo Cannot contact X Server
  tidy_old_Xwin
while ((1)); do

    start_XWin $(read_users_mind)
    sleep 1

    for ((i=0;i<5;++i)); do
      xup && break 2
      sleep 1
    done

    if ((--tries<=0)); then
      m="EXITING: Timeout Waiting for Xserver Startup!!"
      echo "$m"
      notify /t error /m "$m"
      exit 1;
    fi
  done
#start_dbus || { m="Error Starting Dbus"; echo "$m"; notify /t error /m "$m"; }
fi

# vim: ts=2:sw=2

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]