services: cleanup-service: Catch 'system-error' instead of everything.

This makes sure that critical errors such as unbound-variable do not go
undetected.

* gnu/services.scm (cleanup-gexp): Introduce local 'fail-safe' macro and
use it.  Remove uses of 'false-if-exception'.
This commit is contained in:
Ludovic Courtès 2016-01-06 14:49:48 +01:00
parent 341ae58213
commit 3c4c8c3e06
1 changed files with 17 additions and 6 deletions

View File

@ -255,12 +255,23 @@ boot."
;; XXX This needs to happen before service activations, so it ;; XXX This needs to happen before service activations, so it
;; has to be here, but this also implicitly assumes that /tmp ;; has to be here, but this also implicitly assumes that /tmp
;; and /var/run are on the root partition. ;; and /var/run are on the root partition.
(false-if-exception (delete-file-recursively "/tmp")) (letrec-syntax ((fail-safe (syntax-rules ()
(false-if-exception (delete-file-recursively "/var/run")) ((_ exp rest ...)
(false-if-exception (mkdir "/tmp")) (begin
(false-if-exception (chmod "/tmp" #o1777)) (catch 'system-error
(false-if-exception (mkdir "/var/run")) (lambda () exp)
(false-if-exception (chmod "/var/run" #o755)))))) (const #f))
(fail-safe rest ...)))
((_)
#t))))
;; Ignore I/O errors so the system can boot.
(fail-safe
(delete-file-recursively "/tmp")
(delete-file-recursively "/var/run")
(mkdir "/tmp")
(chmod "/tmp" #o1777)
(mkdir "/var/run")
(chmod "/var/run" #o755)))))))
(define cleanup-service-type (define cleanup-service-type
;; Service that cleans things up in /tmp and similar. ;; Service that cleans things up in /tmp and similar.