Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!usc!julius.cs.uiuc.edu!rpi!uwm.edu!psuvax1!ukma!usenet.ins.cwru.edu!ncoast!util20!devon!eds1!wa3wbu!gdx!jay From: jay@gdx.UUCP (Jay A. Snyder) Newsgroups: alt.sources Subject: logout idle users on selected ports Message-ID: <114@gdx.UUCP> Date: 27 Jan 91 01:07:05 GMT Organization: GDX-BBS,Central Pa Unix BBS (717)737-3249 2400/1200/300 24hrs Lines: 78 I wanted to be able to do idle logout for dialins only, but not console jobs (to keep the dialin lines open). So I wrote this little program. It must be run as root. This is a simpile little utility that will logout selected terminals after a specified idle time is reached. usage: idleout [time in minutes] list of ttys --- idleout.c ---- #include #include #include #include #include kill_process(pid) short pid; { if (kill(pid,SIGHUP)) /* try hangup */ if (kill(pid,SIGTERM)) /* try term */ kill(pid,SIGKILL); /* just brute force kill it! */ } time_t idletime(linename) char *linename; { char filename[40]; struct stat s; sprintf(filename,"/dev/%s",linename); stat(filename,&s); return((time((time_t *) 0)-s.st_mtime)/60); } main(argc,argv) int argc; char *argv[]; { struct utmp *u,uu; int i; time_t t,maxidle; if (argc<3) { fprintf(stderr,"usage: idletime [time] [tty] ...\n"); exit(-1); } if (fork()) exit(0); /* run as daemon */ close(0); close(1); close(2); setpgrp(); /* detach from process group */ maxidle=atoi(argv[1]); uu.ut_user[0]=0; uu.ut_id[0]=0; uu.ut_line[0]=0; uu.ut_pid=0; uu.ut_type=0; for (;;) { for (i=2;iut_type==USER_PROCESS) { if (idletime(u->ut_line)>maxidle) { kill_process(u->ut_pid); } } } sleep(60); } }