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

  1. Path: sparky!uunet!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!noiro.acs.uci.edu!ucivax!dhw68k!felix!fritz!scotth
  2. From: scotth@felix.filenet.com (Scott Hopson)
  3. Newsgroups: comp.unix.questions
  4. Subject: Changing Idle Time
  5. Message-ID: <19115@fritz.filenet.com>
  6. Date: 29 Jul 92 00:39:07 GMT
  7. Reply-To: scotth@fritz.filenet.com (Scott Hopson)
  8. Organization: FileNet Corp., Costa Mesa, CA
  9. Lines: 72
  10.  
  11.  
  12. A few people have asked me about this so I'll pass it on.
  13.  
  14. If you have people checking up on you by looking at your idle time
  15. which is displayed by finger, then this might help. This program
  16. constantly updates you terminal idle time so you appear to be working all the
  17. time. This program runs as a daemon and updates any terminal you happen to
  18. logon to.   Have Fun....
  19.  
  20. -----------------------------------CUT HERE----------------------------------
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <utmp.h>
  24. #include <sys/ioctl.h>
  25. #include <sys/file.h>
  26. #include <sys/time.h>
  27.  
  28. char user[9];
  29.  
  30. update()
  31. {
  32. char *utmpFile = "/etc/utmp";
  33. struct utmp utmp;
  34. char ttypath[80];
  35. FILE *fp;
  36.  
  37.     if((fp = fopen(utmpFile, "r")) == NULL)
  38.         return;
  39.  
  40.     while(fread((char *)&utmp, sizeof(utmp), 1, fp) == 1)
  41.     {
  42.     if(strncmp(utmp.ut_name, user, 8))    /* is it me */
  43.         continue;
  44.     strcpy(ttypath, "/dev/");
  45.     strncat(ttypath, utmp.ut_line, 8);
  46.     utime(ttypath,NULL); /* reset the atime and mtime */
  47.     }
  48.     fclose(fp);
  49.     return;
  50. }
  51.  
  52. main()
  53. {
  54. register int x;
  55. int sleepNum = 45;        /* num of secs to sleep */
  56. int fd;
  57.  
  58.     strcpy(user, getlogin());    /* get user name */
  59.  
  60.     nice(20);            /* lower the priority so we don't */
  61.                 /* take time from more important things */
  62.  
  63.     if(fork() != 0) exit(0);    /* fork off a child and kill parent so */
  64.                 /* we can become a daemon */
  65.     close(0);            /* need to close stdin,stdout,stderr */
  66.     close(1);
  67.     close(2);
  68.  
  69.     fd = open("/dev/tty",O_RDWR); /* open the controlling TTY so we can */
  70.     ioctl(fd,TIOCNOTTY,0);      /* detach the process from the TTY */
  71.     close(fd);              /* now close the TTY */
  72.  
  73.     while(1<2)            /* now go into an infinite loop */
  74.     {                /* like a good little daemon */
  75.     update();
  76.     sleep(sleepNum);    /* ok bedtime */
  77.     }
  78. }
  79. -----------------------------------CUT HERE----------------------------------
  80.  
  81. -- 
  82. Scott Hopson   (scotth@filenet.com)
  83.