/usr/lib/picolisp/bin/watchdog is in picolisp 17.12+20180218-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #!/usr/bin/picolisp /usr/lib/picolisp/lib.l
# 02sep15abu
# (c) Software Lab. Alexander Burger
# Use: bin/watchdog <host> <port> <from> <to1> <to2> ..
(load "@lib/misc.l")
# *MailHost *MailPort *MailFrom *MailTo *Watch
(argv *MailHost *MailPort *MailFrom . *MailTo)
(setq *MailPort (format *MailPort))
(unless (call 'test "-p" "fifo/beat")
(call 'mkdir "-p" "fifo")
(call 'rm "-f" "fifo/beat")
(call 'mkfifo "fifo/beat") )
(push1 '*Bye '(call 'rm "fifo/beat"))
(de *Err
(prin (stamp))
(space)
(println *Watch) )
(task (open "fifo/beat")
(in @
(let X (rd)
(cond
((not X) (bye))
((num? X)
(let? W (assoc X *Watch)
(when (caddr W)
(msg (car W) " " (stamp) " bye") )
(del W '*Watch) ) )
((atom X) # bin/picolisp -"out 'fifo/beat (pr '$(tty))" -bye
(let D (+ (* 86400 (date T)) (time T))
(out X
(for W *Watch
(prinl
(align 7 (car W))
" "
(- (cadr W) D)
" "
(or (caddr W) "o")
" "
(cdddr W) ) ) ) ) )
((assoc (car X) *Watch) # X = (Pid Tim . Any)
(let W @ # W = (Pid Tim Flg . Any)
(when (caddr W)
(msg (car W) " " (stamp) " resumed") )
(set (cdr W) (cadr X))
(set (cddr W))
(con (cddr W) (or (cddr X) (cdddr W))) ) )
(T (push '*Watch (list (car X) (cadr X) NIL (cddr X)))) ) ) ) )
(task -54321 54321
(let D (+ (* 86400 (date T)) (time T))
(for W *Watch
(cond
((>= (cadr W) D))
((caddr W)
(msg (car W) " " (stamp)
(if (kill (car W) 15) " killed" " gone") )
(del W '*Watch) )
(T
(inc (cdr W) 3600)
(set (cddr W) T)
(let Sub (pack "Timeout " (car W) " " (cdddr W))
(msg (car W) " " (stamp))
(unless (mail *MailHost *MailPort *MailFrom *MailTo Sub)
(msg (cons Sub *MailTo) " mail failed " (stamp)) ) ) ) ) ) ) )
(wait)
|