AboutSummaryRefsLogTreeCommitDiffStats
path: root/src/mcron/base.scm
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2016-07-18 14:32:52 +0200
committerMathieu Lirzin <mthl@gnu.org>2016-12-28 22:19:02 +0100
commit74babba80ef6c2084035e1bc5d78d31021341cb6 (patch)
tree5be0e9882b890809c20e7d55cb4b3b816e366331 /src/mcron/base.scm
parent913e3c65e4f56476e8ac69f4892cf92c125751ec (diff)
downloadmcron-74babba80ef6c2084035e1bc5d78d31021341cb6.tar.gz
mcron-74babba80ef6c2084035e1bc5d78d31021341cb6.tar.bz2
mcron-74babba80ef6c2084035e1bc5d78d31021341cb6.zip
base: Rewrite 'run-job-loop'.
* src/mcron/base.scm (run-job-loop): Use #:optional keyword argument, and 'match'.
Diffstat (limited to 'src/mcron/base.scm')
-rw-r--r--src/mcron/base.scm77
1 files changed, 33 insertions, 44 deletions
diff --git a/src/mcron/base.scm b/src/mcron/base.scm
index aae5fe5..b779c8a 100644
--- a/src/mcron/base.scm
+++ b/src/mcron/base.scm
@@ -20,6 +20,7 @@
(define-module (mcron base)
+ #:use-module (ice-9 match)
#:use-module (mcron environment)
#:use-module (srfi srfi-9)
#:export (add-job
@@ -225,50 +226,38 @@
(eqv? (car (waitpid WAIT_ANY WNOHANG)) 0)))
(set! number-children (- number-children 1))))
-
-
-;; Now the main loop. Loop over all job specifications, get a list of the next
-;; ones to run (may be more than one). Set an alarm and go to sleep. When we
-;; wake, run the jobs and reap any children (old jobs) that have
-;; completed. Repeat ad infinitum.
-;;
-;; Note that, if we wake ahead of time, it can only mean that a signal has been
-;; sent by a crontab job to tell us to re-read a crontab file. In this case we
-;; break out of the loop here, and let the main procedure deal with the
-;; situation (it will eventually re-call this function, thus maintaining the
-;; loop).
-
-(define (run-job-loop . fd-list)
-
+(define* (run-job-loop #:optional fd-list)
+ ;; Loop over all job specifications, get a list of the next ones to run (may
+ ;; be more than one). Set an alarm and go to sleep. When we wake, run the
+ ;; jobs and reap any children (old jobs) that have completed. Repeat ad
+ ;; infinitum.
+ ;;
+ ;; Note that, if we wake ahead of time, it can only mean that a signal has
+ ;; been sent by a crontab job to tell us to re-read a crontab file. In this
+ ;; case we break out of the loop here, and let the main procedure deal with
+ ;; the situation (it will eventually re-call this function, thus maintaining
+ ;; the loop).
(call-with-current-continuation
(lambda (break)
-
- (let ((fd-list (if (null? fd-list) '() (car fd-list))))
-
- (let loop ()
-
- (let* ((next-jobs (find-next-jobs))
- (next-time (car next-jobs))
- (next-jobs-list (cdr next-jobs))
- (sleep-time (if next-time (- next-time (current-time))
- 2000000000)))
-
- (and (> sleep-time 0)
- (if (not (null?
- (catch 'system-error
- (lambda ()
+ (let loop ()
+ (match (find-next-jobs)
+ ((next-time . next-jobs-lst)
+ (let ((sleep-time (if next-time
+ (- next-time (current-time))
+ 2000000000)))
+ (when (and
+ (> sleep-time 0)
+ (not (null? (catch 'system-error
+ (λ ()
(car (select fd-list '() '() sleep-time)))
- (lambda (key . args) ;; Exception add by Sergey
- ;; Poznyakoff.
- (if (member (car (last args))
- (list EINTR EAGAIN))
- (begin
- (child-cleanup) '())
- (apply throw key args))))))
- (break)))
-
- (run-jobs next-jobs-list)
-
- (child-cleanup)
-
- (loop)))))))
+ (λ (key . args)
+ (let ((err (car (last args))))
+ (cond ((member err (list EINTR EAGAIN))
+ (child-cleanup)
+ '())
+ (else
+ (apply throw key args)))))))))
+ (break))
+ (run-jobs next-jobs-lst)
+ (child-cleanup)
+ (loop))))))))