[ From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 11-OCT-1990 19:08:15.12  To:	MRGATE::"ARISIA::EVERHART" CC:	0 Subj:	Cheap WDOG for people who forget to logout  * Received:  by crdgw1.ge.com (5.57/GE 1.73)) 	 id AA08421; Thu, 11 Oct 90 18:55:05 EDT Y Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Thu, 11 OCT 90 13:57:24 PDT , Received: by ucbvax.Berkeley.EDU (5.63/1.42)* 	id AA02245; Thu, 11 Oct 90 13:26:25 -07009 Received: from USENET by ucbvax.Berkeley.EDU with netnews . 	for info-vax@kl.sri.com (info-vax@kl.sri.com); 	(contact usenet@ucbvax.Berkeley.EDU if you have questions)  Date: 11 Oct 90 19:10:09 GMT4 From: motcsd!dms!shepperd@apple.com  (Dave Shepperd), Organization: Atari Games Inc., Milpitas, CA3 Subject: Cheap WDOG for people who forget to logout  Message-Id: <1168@dms.UUCP> # Sender: info-vax-request@kl.sri.com  To: info-vax@kl.sri.com     C Someone asked about a cheap watchdog that will logout your terminal @ if you forget to logout yourself. This'll do the trick. It ain't? bullet proof (just delete the process), but it might be all you  need.   6 $! ------------------ CUT HERE -----------------------( $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $!A $! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990 3 $!   On 11-OCT-1990 11:54:46.45   By user SHEPPERD   $! $! This VMS_SHARE Written by: * $!    Andy Harper, Kings College London UK $! $! Acknowledgements to: + $!    James Gray       - Original VMS_SHARE < $!    Michael Bednarek - Original Concept and implementation $!< $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER2 $! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  ) $!9 $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:  $!       1. WDOG.COM;22  $!
 $set="set"$ $set symbol/scope=(nolocal,noglobal)? $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID")) # $e="write sys$error  ""%UNPACK"", " # $w="write sys$output ""%UNPACK"", " ) $ if f$trnlnm("SHARE_LOG") then $ w = "!"  $ ve=f$getsyi("version")7 $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START * $ e "-E-OLDVER, Must run at least VMS 4.4" $ v=f$verify(v) 	 $ exit 44 . $UNPACK: SUBROUTINE ! P1=filename, P2=checksum2 $ if f$search(P1) .eqs. "" then $ goto file_absent, $ e "-W-EXISTS, File ''P1' exists. Skipped."
 $ delete 'f'*  $ exit
 $file_absent: + $ if f$parse(P1) .nes. "" then $ goto dirok  $ dn=f$parse(P1,,,"DIRECTORY")* $ w "-I-CREDIR, Creating directory ''dn'." $ create/dir 'dn'  $ if $status then $ goto dirok: $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
 $ delete 'f'*  $ exit $dirok: ( $ w "-I-PROCESS, Processing file ''P1'."7 $ if .not. f$verify() then $ define/user sys$output nl: 1 $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1' H PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(M SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:= E CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b)); F LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(M BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1); K IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE; K MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1; M ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")= G 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF"; M POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r); M ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1; F COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,+ "output_file"));ENDPROCEDURE;Unpacker;QUIT;  $ delete/nolog 'f'*  $ CHECKSUM 'P1' + $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT - $ e "-E-CHKSMFAIL, Checksum of ''P1' failed."  $ ENDSUBROUTINE  $START:  $ create 'f'! X$       old_verify = f$verify(0) > X$! This command file is intended to be SPAWNED as a watchdog.; X$! If it is not spawned, it will just exit with a message. C X$! It watches the CPU time, the buffered and unbuffered I/O count, = X$! and all subprocesses.  If there are less than 3 CPU ticks J X$! in each scan period and no I/O (for all processes in the tree but us),= X$! the master process is deleted, logging us off the system. K X$! The scans occur once each minute.  The number of scans with no apparent E X$! activity (including the creation or deletion of subprocesses that > X$! straddle a snapshot) is user selectable, defaulting to 45. X$! G X$! It is intended to be fired up with this line in anyone's LOGIN.COM: D X$!      $ SPAWN/NOWAIT/NOLOG/NONOTIFY/IN=_NL: @WDOG `5B<minutes>`5DM X$!              Notice:  The /OUTPUT goes to CRT for the final warning messa  Vge. X$! K X$! It can now be started with @WDOG `5B<minutes>`5D, interactively or from  X$! a command file.  X$! M X$! Written on a V5.0 system, upgraded on a V5.2 (spawn environment different  V!)  X$ X$& X$       on warning then $exit $status X$ X$       bleep = "   " X$       bleep`5B0,7`5D = 7  X$       bleep`5B8,7`5D = 13 X$       bleep`5B16,7`5D = 10  X$       debug := if 0 then $  X$       prodn := if 1 then $  X$( X$       god = f$getjpi("","master_pid")  X$       us = f$getjpi("","PID")# X$       mom = f$getjpi("","OWNER") " X$`09tty = f$getjpi("","TERMINAL")& X$`09godtty = f$getjpi(god,"TERMINAL")' X$`09if us .eqs. god then $ goto fakeit & X$`09if mom .eqs. god then $ goto doit! X$       Copy sys$input sys$error M X%WATCHDOG-?-TOOFARAWAY, This must be done from the root process to be effect  Vive. 3 X$       exit %x10000001 + 0*(f$verify(old_verify))  X$ X$G X$fakeit:`09! We are our own man; we are the master PID; we must spawn. ; X$`09if f$mode() .nes. "INTERACTIVE" .or. godtty .eqs. "" - 8 X`09`09then $ exit %x10000001 + 0*(f$verify(old_verify))5 X$!`09`09'cuz we don't monitor batch or detached jobs  X$> X$`09SPAWN/NOWAIT/NOLOG/NONOTIFY/IN=_NL: @'f$env("procedure")'3 X$       exit %x10000001 + 0*(f$verify(old_verify))  X$ X$B X$doit:`09`09! We are properly spawned, so do the actual watchdog. X$       pass_interval := 0:1:0  X$       all_of_them = 45 " X$`09if f$type(p1) .eqs. "INTEGER"	 X$`09then * X$`09`09if 'p1' .ge. 5 .and. 'p1' .le. 120 X$`09`09then X$`09`09`09all_of_them = 'p1'  X$`09`09else' X$       `09`09Copy sys$input sys$error M X%WATCHDOG-?-BADPARAM, You may specify a number of minutes between 5 and 120. M X%WATCHDOG-S-DEFAULTING, Using the normal default of 45 minutes of idle time. 
 X$`09`09endif 	 X$`09else 8 X$`09`09if f$len(p1) .gt. 0`09! if he typed something... X$`09`09then' X$       `09`09Copy sys$input sys$error M X%WATCHDOG-?-BADPARAM, You may specify a number of minutes between 5 and 120. M X-WATCHDOG-?-BADNUMBER, You may only specify the number of minutes as an inte  Vger. M X%WATCHDOG-S-DEFAULTING, Using the normal default of 45 minutes of idle time. 
 X$`09`09endif 
 X$`09endif" X$       scans_to_go = all_of_them X$7 X$! MAKE SURE WE ARE THE ONLY ONE (UNIQUE PROCESS NAME)  X$       set noon 9 X$       set message/notext/noseverity/nofacility/noident & X$       set process/name='godtty'wdog* X$       if .not. $status then $ stop/id=01 X$       set message/text/severity/facility/ident  X$       set on  X$ X$next_pass: X$       context = 0 X$next_pid: ! X$       current = f$pid(context) 4 X$       if current .eqs. "" then $ goto end_of_passJ X$       if f$getjpi(current, "MASTER_PID") .nes. god then $ goto next_pid1 X$       if current .eqs. us then $ goto next_pid  X$K X$       if f$type(PID_'current') .eqs. "" then $ scans_to_go = all_of_them J X$       if f$type(PID_'current') .eqs. "" then $ PID_'current' := 0,0,0,0- X$       prccnt = f$getjpi(current, "PRCCNT") L X$       if current .eqs. mom then $ if prccnt .gt. 0 then $ prccnt = prccnt V - 1 - X$       cputim = f$getjpi(current, "CPUTIM") + X$       bufio = f$getjpi(current, "BUFIO") + X$       dirio = f$getjpi(current, "DIRIO") = X$       if prccnt .ne. f$element(0,",",PID_'current') then - * X        $       scans_to_go = all_of_themC X$       if cputim .ge. (f$element(1,",",PID_'current') + 3) then - * X        $       scans_to_go = all_of_them< X$       if bufio .ne. f$element(2,",",PID_'current') then -* X        $       scans_to_go = all_of_them< X$       if dirio .ne. f$element(3,",",PID_'current') then -* X        $       scans_to_go = all_of_them; X$       PID_'current' := 'prccnt','cputim','bufio','dirio'R X$ X$       goto next_pid X$ X$ X$end_of_pass:& X$       scans_to_go = scans_to_go - 18 X$       if scans_to_go .lt. 0 then $ goto jelly_blaster	 X$rewait:E& X$debug  write sys$output "at REWAIT:" X$debug  sho sym pid_* X$debug  sho sym scans_to_go X$debug  write sys$output "" X$       wait 'pass_interval'  X$       goto next_passr X$ X$ X$jelly_blaster:5 X$       if scans_to_go .lt. -1 then $ goto drop_dead.E X$       write sys$output bleep, "Automatic logoff will occur in ", -e> X                ( f$cvtime(pass_interval,"DELTA") - "0 " ), -< X                        " unless you DO SOMETHING!!", bleep X$       goto rewait X$drop_dead:) X$debug  write sys$output "at DROP_DEAD:"l X$debug  sho sym pid_* X$debug  sho sym scans_to_goC X$       write sys$output bleep, "Automatic logoff enforced at ", - B X                f$edit(f$cvtime("+0", "ABSOLUTE"), "TRIM"), bleep X$prodn  stop/id='god'7 X$       stop/id=0               ! if we live this long!$ $ CALL UNPACK WDOG.COM;22 1914907277 $ v=f$verify(v)  $ EXIT   -- R; Dave Shepperd.	    shepperd@dms.UUCP or weitek!dms!shepperd!? Atari Games Corporation, 675 Sycamore Drive, Milpitas CA 95035._@ Nobody knows what I'm saying. I don't even know what I'm saying.  