# HG changeset patch # User Richard Westhaver # Date 1723513498 14400 # Node ID 71c05868c4e7424fdc0ce2ecb54c024a945143ba # Parent 16a3cdc06cbc6130d4d91883aad15e15cb52566f init systemd diff -r 16a3cdc06cbc -r 71c05868c4e7 lisp/lib/cli/tools/pkg.lisp --- a/lisp/lib/cli/tools/pkg.lisp Mon Aug 12 21:16:14 2024 -0400 +++ b/lisp/lib/cli/tools/pkg.lisp Mon Aug 12 21:44:58 2024 -0400 @@ -40,7 +40,8 @@ (defpackage :cli/tools/systemd (:use :cl :std :cli/env) - (:export :*systemctl* :run-systemd :run-systemctl)) + (:export :*systemctl* :run-systemd :run-systemctl + :systemd-error)) (defpackage :cli/tools/cargo (:use :cl :std :cli/env) diff -r 16a3cdc06cbc -r 71c05868c4e7 lisp/lib/cli/tools/systemd.lisp --- a/lisp/lib/cli/tools/systemd.lisp Mon Aug 12 21:16:14 2024 -0400 +++ b/lisp/lib/cli/tools/systemd.lisp Mon Aug 12 21:44:58 2024 -0400 @@ -4,3 +4,20 @@ ;;; Code: (in-package :cli/tools/systemd) + +(deferror systemd-error (simple-error error) ()) + +(defun systemd-error (fmt &rest args) + (error 'systemd-error :format-arguments args :format-control fmt)) + +(defparameter *systemctl* (find-exe "systemctl")) + +(defun run-systemctl (&rest args) + (let ((proc (sb-ext:run-program *systemctl* (or args nil) :output :stream))) + (with-open-stream (s (sb-ext:process-output proc)) + (loop for l = (read-line s nil nil) + while l + do (write-line l))) + (if (eq 0 (sb-ext:process-exit-code proc)) + nil + (systemd-error "SYSTEMCTL command failed: ~A ~A" *systemctl* (or args "")))))