Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!ukma!husc6!bu-cs!madd From: madd@bu-cs.BU.EDU (Jim Frost) Newsgroups: comp.unix.wizards Subject: Re: Enforcing session timeout under csh Message-ID: <22987@bu-cs.BU.EDU> Date: 29 May 88 17:48:20 GMT References: <21319@labrea.STANFORD.EDU> Reply-To: madd@bu-it.bu.edu (Jim Frost) Followup-To: comp.unix.wizards Organization: Boston University Distributed Systems Group Lines: 87 In article <21319@labrea.STANFORD.EDU> philf@med-isg.stanford.edu (Phil Fernandez) writes: |One of my users with a Sun 3/60 wishes to enforce an idle session |timeout under SunOS 3.5. That is, after a login session has been idle |for, say, 10 minutes, he wants the line (most likely a telnet |connection) to be automatically logged out. Should work for any |shell. Is there a way to do this? How? I haven't seen much discussion about this, but here's my solution (which should work on BSD-ish systems, and definitely works under SunOS). Run the following program from .login and it'll idle out the csh after HOWLONG minutes. This is actually quite generic and could time out just about anything. jim frost madd@bu-it.bu.edu -- cut here -- /* timeout.c: * * this program attempts to kill its parent (presumably a shell) when * the controlling tty has been idle too long. * * written by jim frost (madd@bu-it.bu.edu) on 5.27.88. this program * is placed in the public domain. */ #include #include #include #include #define HOWLONG 10 /* number of minutes before we kill something */ long ttytime() { struct stat stb; if (ttyname(0) == NULL) /* don't know who our tty is */ exit(1); if (stat(ttyname(0),&stb) < 0) /* stat failed -- no device */ exit(1); else return(stb.st_mtime); /* last time since something happened */ } main(argc,argv) { int cshpid; long t; /* get parent's (csh's) pid */ cshpid= getppid(); /* fork off so csh looses us */ switch(fork()) { case -1 : printf("fork failed! will not timeout.\n"); exit(1); case 0 : break; default : exit(0); } /* loop until either ttytime() kills us or our idle time is too large */ for (;;) { time(&t); if (t - ttytime() > (HOWLONG * 60)) /* we've been idle too long. send HUP signal to parent */ if (kill(cshpid,SIGHUP) != -1) { printf("\nIdle timeout\n"); exit(0); } /* sleep to keep down overhead */ sleep(60); } }