From: adamec@biggles.gsfc.nasa.gov (David Adamec)
Subject: Re: (Arrgh) Logout idle users (NOT w/ tcsh...)
Date: 1995/06/08 [thread overview]
Message-ID: <3r7msb$rh2@post.gsfc.nasa.gov> (raw)
In-Reply-To: 3r78pe$bv2@news.mtu.edu
Below is some a C code I modified to run under OSF/1; it should work
for most machines. Once you get the executable do a chmod +s on it,
then make sure every user is forced to run it when they log in.
David Adamec
_______________________________
/*
** tout - a personal timeout program
**
** Andrew Rudoff, University of Colorado, Boulder
**
** usage: tout minutes
**
** This is a voluntary timeout program. A timeout occurs when the user
** is idle for a time larger than "minutes." The inaccuracy can be as
** much as 1 minute (1 minute granularity). The user is warned 1 minute
** before the timeout; the timeout can be prevented by typing any key to
** clear the idle status of the terminal.
*/
#include <time.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sgtty.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#define BEEP '\007'
main(argc, argv)
int argc;
char **argv;
{
char user[50]; /* name of current user */
char invoker[50]; /* name of invoker */
struct stat statbuf; /* buffer for stats on tty */
long current, timeout; /* times in seconds */
long last_access,diff; /* times in seconds */
int pgrp, tmp = 0;
if (argc != 2)
{
fprintf(stderr, "usage: %s minutes\n", argv[0]);
exit(1);
}
time(¤t);
fstat(0, &statbuf);
diff = statbuf.st_atime-current;
nice(4); /* run gracefully in the background */
if ((timeout = 60 * atoi(argv[1])) == 0)
{
fprintf(stderr, "%s: incomprehensible or zero timeout\n", argv[0]);
exit(1);
}
if (!isatty(0))
{
fprintf(stderr, "%s: stdin not a terminal\n", argv[0]);
exit(1);
}
strcpy(invoker, getlogin());
printf("Idle terminal timeout set for %s (%s minutes)\n", invoker, argv[1]);
fflush(stdout);
if (fork())
{
exit(0);
}
while(1)
{
sleep(60);
strcpy(user, getlogin());
/* Be sure same person is logged in */
if (strcmp(user, invoker))
{
exit(0);
}
if ((fstat(0, &statbuf)) != 0)
{
fprintf(stderr, "%s: couldn't stat tty\n", argv[0]);
exit(1);
}
time(¤t);
fstat(0, &statbuf);
last_access = statbuf.st_atime-diff;
if (current + 60 - last_access >= timeout)
{
fprintf(stderr, "\n WARNING - terminal timeout in 1 minute.%c\n",
BEEP);
}
if (current - last_access >= timeout)
{
fprintf(stderr, "\n\n Terminal timeout - you're outta here!\n\n");
while(ioctl(0, TIOCGPGRP, &pgrp), pgrp != tmp)
{
tmp = pgrp;
killpg(pgrp, SIGHUP);
sleep(5);
}
exit(0);
}
}
}
next prev parent reply other threads:[~1995-06-08 4:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-06-08 4:00 (Arrgh) Logout idle users (NOT w/ tcsh...) Phil Edwards
1995-06-08 4:00 ` Brian A. Bucher
1995-06-08 4:00 ` David Adamec [this message]
1995-06-08 4:00 ` Seth J. Bradley
1995-06-09 4:00 ` Phil Farrell
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox