Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!unido!pbinfo!pbinfo!x-window From: x-window@uni-paderborn.de (X-Window Betreuung) Newsgroups: comp.windows.x Subject: Re: Xterm console window problems Message-ID: Date: 4 Jun 91 10:29:27 GMT References: <1991Jun3.125642.11785@vaxa.strath.ac.uk> Sender: news@uni-paderborn.de (News Uni-Paderborn) Organization: Uni Paderborn FB 17 Informatik GERMANY Lines: 120 In-Reply-To: craa79@vaxa.strath.ac.uk's message of 3 Jun 91 12:56:42 GMT Nntp-Posting-Host: athene 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 #include #include #include #include #include #include #include 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 * <----