[comp.windows.x] Xterm console window problems

craa79@vaxa.strath.ac.uk (Bruce Rodger.) (06/03/91)

Sorry if this has been asked before - but i didnt see anything in the FAQ
list.....

Problem:

rlogin to a sun (3/80, running sunos 4.0.3), and start up an Xterm console
window. 

The normal console (NOT running a window system) gets grabbed - if a user
is logged onto the console, the user who started the xterm gets BOTH sessions
connected to the xterm.

If the Xterm is now killed, control is NOT returned to the console - the only
solution is to reboot......

Any solutions ?

Bruce.

-- 
R.B. Rodger        |JANET:   R.B.Rodger@uk.ac.strath.vaxa
                   |Internet:R.B.Rodger@vaxa.strath.ac.uk
Computer Centre    |
Strathclyde Univ   | Thank you for dealing with ByteSabre Software Inc. Your
Glasgow G4 0LN     | bill is in the post. When it arrives, remember our motto:
Scotland.          | "We know where you live!"

anthony@gucis.sct.gu.edu.au (Anthony Thyssen) (06/04/91)

craa79@vaxa.strath.ac.uk (Bruce Rodger.) writes:
>Problem:
>rlogin to a sun (3/80, running sunos 4.0.3), and start up an Xterm console
>window.
>The normal console (NOT running a window system) gets grabbed - if a user
>is logged onto the console, the user who started the xterm gets BOTH sessions
>connected to the xterm.
>If the Xterm is now killed, control is NOT returned to the console - the only
>solution is to reboot......
>Any solutions ?

>Bruce.

A simular problem exists when using Xterminals or X servers that query
on a remote machine for a XDM login. If the session starts a console (-C flag)
the previous console on the machine (either the real console or another
persons xterm -C console) is lost, as there can only ever be one console right!

My solution in installing X is to give the user (in the default Xsesson
file of xdm ( I changed startx script to also use the) ) a console
ONLY if he is running on the machine with the server (local)
EG:-

cd                              # go home!
HOST=`/bin/hostname`
case "$DISPLAY" in              # fix any display problems
  unix:0.0|unix:0|:0.0|:0|'')     DISPLAY="$HOST:0.0" ;;
esac

< resource stuff and window manager start deleted >

if [ "$HOST:0.0" = $DISPLAY ]; then
  xterm -g 80x8+5+5 -T "Console" -n "Console" -C &   # console
fi

< the rest of the setup >

xlogout -g -5-5   # the logout button
xclosedown        # clean up nicely first

x-window@uni-paderborn.de (X-Window Betreuung) (06/04/91)

In article <1991Jun3.125642.11785@vaxa.strath.ac.uk> craa79@vaxa.strath.ac.uk (Bruce Rodger.) writes:

   Problem:

   rlogin to a sun (3/80, running sunos 4.0.3), and start up an Xterm console
   window. 

   The normal console (NOT running a window system) gets grabbed - if a user
   is logged onto the console, the user who started the xterm gets BOTH sessions
   connected to the xterm.

   If the Xterm is now killed, control is NOT returned to the console - the only
   solution is to reboot......

   Any solutions ?

Here's a little program I wrote a few months ago to solve this very
problem - it occured here often, when X got killed and didn't clean up
right, especially on our SLC's. I added the program as the last client
in the .xstartrc, and now there are no more problems. Ok, here it is.

--------------- snip snip ---------------------------

 /* program: kbd_recover                                        */
 /* purpose: recovers the console after dirty exits of X        */
 /* usage:   kbd_recover -force (option to prevent calling this */
 /*          program accidentially)                             */

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sundev/kbio.h>
#include <sundev/kbd.h>
#include <stdio.h>
#include <strings.h>

extern int stat(), geteuid(), getegid();
extern int open();
extern void close();
extern int ioctl();
extern void fprintf();
extern void exit();

static void die(), usage();


void
main (argc, argv)
     int argc;
     char *argv[];
{
  int kbd_fd;
  int translate;
  struct stat buf;
  int tmp=0;
  short uid;
  
  
  argc--;
  argv++;
  if (argc-- && **argv == '-')
    ++*argv;
  else
    usage();
  
  if (stat("/dev/console", &buf) != 0)
    die ("Couldn't find /dev/console.");
  
  uid = buf.st_uid;
  if (((short) geteuid() != uid) &&  /* not owner of console */
      (geteuid()  != 0 ))            /* no root */
    {
      die("Only the owner of /dev/console or root is allowed to run this program");
    }
  
  
  if (strcmp(*argv,"force")!=0)
    usage();
  
  if ((kbd_fd = open ("/dev/kbd", O_RDWR, 0)) < 0)
    die("Couldn't open /dev/kbd");
  
  translate = TR_ASCII;
  
  if (ioctl(kbd_fd, KIOCTRANS, (caddr_t) &translate))
    die("Couldn't initialize translation to Event");
  
  if (ioctl (kbd_fd, KIOCSDIRECT, (caddr_t) &tmp))
    die("Couldn't recover console");
  
  close( kbd_fd );
  exit(0);
}

static void
die(msg)
     char        *msg;
{
  fprintf(stderr, "%s\n", msg);
  exit(1);
}

static void
usage()
{
  fprintf(stderr, "Usage: kbd_recover -force\n");
  fprintf(stderr, "\tRecovers the console after dirty exits of Xsun\n");
  fprintf(stderr, "\tWarning! Calling this program from within X11\n");
  fprintf(stderr, "\twill kill your Server!\n");
  exit(1);
}

------------- snip snip ----------------

Hope this helps.
Regards, Swen
--

---->  Swen Thuemmler  *  X-Betreuung  *  <swen@uni-paderborn.de>  <----