home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / linux / 22467 < prev    next >
Encoding:
Internet Message Format  |  1993-01-02  |  2.8 KB

  1. Path: sparky!uunet!stanford.edu!rutgers!igor.rutgers.edu!geneva.rutgers.edu!hedrick
  2. From: hedrick@geneva.rutgers.edu (Charles Hedrick)
  3. Newsgroups: comp.os.linux
  4. Subject: diffs to allow xterm to get console output
  5. Message-ID: <Jan.2.15.22.55.1993.26424@geneva.rutgers.edu>
  6. Date: 2 Jan 93 20:22:55 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 86
  9.  
  10. In 0.99pl2, Linus added a feature to allow xterm to snarf console
  11. output.  Here's a diff for xterm to implement it.  This only works if
  12. xterm is setuid root, which of course it normally should be.
  13.  
  14. The one loose end is cleaning up the subprocess if xterm terminates.
  15. Normally when I exit from xterm, the cat subprocess goes away.  But
  16. once it didn't.  I'm not sure what is going on.  I suspect most people
  17. start up X and leave it active.  If so, this isn't an issue.
  18.  
  19. *** main.c.O    Thu Apr  9 21:43:26 1992
  20. --- main.c    Sat Jan  2 14:57:15 1993
  21. ***************
  22. *** 982,992 ****
  23.   #ifdef TIOCCONS
  24.           {
  25.               struct stat sbuf;
  26.   
  27.               /* Must be owner and have read/write permission.
  28.                  xdm cooperates to give the console the right user. */
  29.               if ( !stat("/dev/console", &sbuf) &&
  30. !              (sbuf.st_uid == getuid()) &&
  31.                !access("/dev/console", R_OK|W_OK))
  32.               {
  33.               Console = TRUE;
  34. --- 1023,1034 ----
  35.   #ifdef TIOCCONS
  36.           {
  37.               struct stat sbuf;
  38. +             int myuid = getuid();
  39.   
  40.               /* Must be owner and have read/write permission.
  41.                  xdm cooperates to give the console the right user. */
  42.               if ( !stat("/dev/console", &sbuf) &&
  43. !              (sbuf.st_uid == myuid || myuid == 0) &&
  44.                !access("/dev/console", R_OK|W_OK))
  45.               {
  46.               Console = TRUE;
  47. ***************
  48. *** 2127,2132 ****
  49. --- 2177,2183 ----
  50.   #endif /* sony */
  51.   #endif    /* !USE_SYSV_TERMIO */
  52.   #ifdef TIOCCONS
  53. + #ifndef linux
  54.               if (Console) {
  55.               int on = 1;
  56.               if (ioctl (tty, TIOCCONS, (char *)&on) == -1)
  57. ***************
  58. *** 2133,2138 ****
  59. --- 2184,2190 ----
  60.                   fprintf(stderr, "%s: cannot open console\n",
  61.                       xterm_name);
  62.               }
  63. + #endif  /* ! linux */
  64.   #endif    /* TIOCCONS */
  65.           }
  66.   
  67. ***************
  68. *** 2371,2376 ****
  69. --- 2425,2450 ----
  70.           (void)write(cp_pipe[1], (char *)&handshake, sizeof(handshake));
  71.   #endif /* USE_HANDSHAKE */
  72.   #endif/* UTMP */
  73. + #ifdef linux
  74. +         if (Console) {
  75. + /* the obvious thing would be system("cat </proc/kmsg&").  Unfortunately
  76. +  * that isn't safe for a setuid program, which this is.  This is also why
  77. +  * we use an explicit path for cat.
  78. +  */
  79. +           if (fork() == 0) {
  80. +             int procfd;
  81. +             if ((procfd = open("/proc/kmsg", 0)) < 0)
  82. +               exit(1);
  83. +             dup2(procfd, 0);
  84. +             close(procfd);
  85. +             execl("/bin/cat", "cat", 0);
  86. +             execl("/usr/bin/cat", "cat", 0);
  87. +             exit(1);
  88. +           }
  89. +         }
  90. + #endif
  91.   
  92.           (void) setgid (screen->gid);
  93.   #ifdef HAS_BSD_GROUPS
  94.