summary refs log tree commit diff
path: root/gnu/services
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-06-25 23:31:11 +0200
committerLudovic Courtès <ludo@gnu.org>2023-06-25 23:46:03 +0200
commit6c0e7b266523a2cc381c76392c830a237d9e41a9 (patch)
treec6be730d497099c7e93f50f96c93f9899c313b1c /gnu/services
parentd08cb9bf44d93bad6135dfd5047cfd3a38ffbf22 (diff)
downloadguix-6c0e7b266523a2cc381c76392c830a237d9e41a9.tar.gz
services: Validate 'provision' field of <shepherd-service>.
Fixes <https://issues.guix.gnu.org/63979>.

* gnu/services/shepherd.scm (validate-provision): New procedure.
(<shepherd-service>)[provision]: Use it.

Co-authored-by: Bruno Victal <mirai@makinata.eu>
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/shepherd.scm18
1 files changed, 16 insertions, 2 deletions
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index de40454f7d..e9d3a631c2 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -27,8 +27,9 @@
   #:use-module (guix store)
   #:use-module (guix records)
   #:use-module (guix packages)
-  #:use-module (guix derivations)                 ;imported-modules, etc.
   #:use-module (guix utils)
+  #:use-module ((guix diagnostics)
+                #:select (define-with-syntax-properties formatted-message))
   #:use-module (gnu services)
   #:use-module (gnu services herd)
   #:use-module (gnu packages admin)
@@ -186,12 +187,25 @@ DEFAULT is given, use it as the service's default value."
     ((guix build utils) #:hide (delete))
     (guix build syscalls)))
 
+(define-with-syntax-properties (validate-provision (provision properties))
+  (match provision
+    (((? symbol?) ..1) provision)
+    (_
+     (raise
+      (make-compound-condition
+       (condition
+        (&error-location
+         (location (source-properties->location properties))))
+       (formatted-message
+        (G_ "'provision' must be a non-empty list of symbols")))))))
+
 (define-record-type* <shepherd-service>
   shepherd-service make-shepherd-service
   shepherd-service?
   (documentation shepherd-service-documentation        ;string
                  (default "[No documentation.]"))
-  (provision     shepherd-service-provision)           ;list of symbols
+  (provision     shepherd-service-provision            ;list of symbols
+                 (sanitize validate-provision))
   (requirement   shepherd-service-requirement          ;list of symbols
                  (default '()))
   (one-shot?     shepherd-service-one-shot?            ;Boolean