home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9548 < prev    next >
Encoding:
Text File  |  1992-07-29  |  2.0 KB  |  60 lines

  1. Path: sparky!uunet!olivea!decwrl!csus.edu!csusac!cindy!rat!zeus!ctuel
  2. From: ctuel@zeus.calpoly.edu (Cliff Tuel)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Changing Idle Time
  5. Message-ID: <1992Jul29.200554.180990@zeus.calpoly.edu>
  6. Date: 29 Jul 92 20:05:54 GMT
  7. References: <19115@fritz.filenet.com>
  8. Organization: Cal Poly, San Luis Obispo
  9. Lines: 49
  10.  
  11. scotth@fritz.filenet.com (Scott Hopson) said...
  12. |If you have people checking up on you by looking at your idle time
  13. |which is displayed by finger, then this might help. This program
  14. |constantly updates you terminal idle time so you appear to be working all the
  15. |time. This program runs as a daemon and updates any terminal you happen to
  16. |logon to.   Have Fun....
  17.  
  18. [ Program based on "utime(ttypath,NULL)" deleted ]
  19.  
  20. Maybe this wasn't the intent of your program, but our local network kicks
  21. off anyone idle for more than 30 minutes, and changing the atime and mtime
  22. of the tty has no effect.  You need to simulate terminal activity using
  23. "ioctl(1, TIOCSTI, s)".  For example:
  24.  
  25.     void typestring (s)
  26.     char *s;
  27.     {
  28.         while (*s) {
  29.             ioctl(1, TIOCSTI, s);
  30.             *s++;
  31.         }
  32.         ioctl(1, TIOCSTI, "^M");
  33.     }
  34.  
  35. Run this from a background process, first doing a "signal (SIGTTOU, SIG_IGN)"
  36. to allow writes from the background.  Try stuff like: typestring ("uptime").
  37.  
  38. Another thing to consider is to have the forked process commit suicide if
  39. you log out.  Passing the shell's pid to the forked child is a little tricky
  40. but not impossible.  Once you have the pid, you can do:
  41.  
  42.     if (kill (shellpid, 0) == -1) 
  43.         exit (1);
  44.  
  45. Finally, you should watch the idle time on the tty, and only call typestring()
  46. if the time is greater than some threshold:
  47.  
  48.     timenow = time ((time_t *) NULL);
  49.     stat (ttyname, stbuf);
  50.  
  51.     if ((timenow - stbuf->st_mtime) > IDLETIME) 
  52.         typestring (s);
  53.  
  54.  
  55. -- 
  56. Cliff Tuel                   __o o__ 
  57. HP/Apollo System Admin       \( v )/       YELLO & ART OF NOISE mailing lists:
  58. Cal Poly, San Luis Obispo     /___\      Yello-request@polyslo.CSc.CalPoly.edu
  59. ctuel@nike.CalPoly.edu         ^ ^         AoN-request@polyslo.CSc.CalPoly.edu
  60.