home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!noiro.acs.uci.edu!ucivax!dhw68k!felix!fritz!scotth
- From: scotth@felix.filenet.com (Scott Hopson)
- Newsgroups: comp.unix.questions
- Subject: Changing Idle Time
- Message-ID: <19115@fritz.filenet.com>
- Date: 29 Jul 92 00:39:07 GMT
- Reply-To: scotth@fritz.filenet.com (Scott Hopson)
- Organization: FileNet Corp., Costa Mesa, CA
- Lines: 72
-
-
- A few people have asked me about this so I'll pass it on.
-
- If you have people checking up on you by looking at your idle time
- which is displayed by finger, then this might help. This program
- constantly updates you terminal idle time so you appear to be working all the
- time. This program runs as a daemon and updates any terminal you happen to
- logon to. Have Fun....
-
- -----------------------------------CUT HERE----------------------------------
- #include <stdio.h>
- #include <string.h>
- #include <utmp.h>
- #include <sys/ioctl.h>
- #include <sys/file.h>
- #include <sys/time.h>
-
- char user[9];
-
- update()
- {
- char *utmpFile = "/etc/utmp";
- struct utmp utmp;
- char ttypath[80];
- FILE *fp;
-
- if((fp = fopen(utmpFile, "r")) == NULL)
- return;
-
- while(fread((char *)&utmp, sizeof(utmp), 1, fp) == 1)
- {
- if(strncmp(utmp.ut_name, user, 8)) /* is it me */
- continue;
- strcpy(ttypath, "/dev/");
- strncat(ttypath, utmp.ut_line, 8);
- utime(ttypath,NULL); /* reset the atime and mtime */
- }
- fclose(fp);
- return;
- }
-
- main()
- {
- register int x;
- int sleepNum = 45; /* num of secs to sleep */
- int fd;
-
- strcpy(user, getlogin()); /* get user name */
-
- nice(20); /* lower the priority so we don't */
- /* take time from more important things */
-
- if(fork() != 0) exit(0); /* fork off a child and kill parent so */
- /* we can become a daemon */
- close(0); /* need to close stdin,stdout,stderr */
- close(1);
- close(2);
-
- fd = open("/dev/tty",O_RDWR); /* open the controlling TTY so we can */
- ioctl(fd,TIOCNOTTY,0); /* detach the process from the TTY */
- close(fd); /* now close the TTY */
-
- while(1<2) /* now go into an infinite loop */
- { /* like a good little daemon */
- update();
- sleep(sleepNum); /* ok bedtime */
- }
- }
- -----------------------------------CUT HERE----------------------------------
-
- --
- Scott Hopson (scotth@filenet.com)
-