aboutsummaryrefslogtreecommitdiff
path: root/src/util.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-09-18 15:22:36 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-10-28 17:07:07 -0700
commit8837b71e02d93787de60d454a493a8801a6427a5 (patch)
tree8be191d883b2831f6d9778e90379174cb84d90c7 /src/util.lisp
parentd8f3404ba4cf1f9a7232cc7c068c9872ba0bd3de (diff)
downloadconsfigurator-8837b71e02d93787de60d454a493a8801a6427a5.tar.gz
basic systemctl(1) properties: add USER argument for --user
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/util.lisp')
-rw-r--r--src/util.lisp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util.lisp b/src/util.lisp
index cb3eace..1bed222 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -171,6 +171,30 @@ supported."
(doplist (k v plist args)
(push (strcat "--" (string-downcase (symbol-name k)) "=" v) args)))
+(defun systemd--user (&rest args)
+ "Where ARGS are args to RUN or MRUN for an invocation of a systemd command
+which can take \"--user\", insert the \"--user\" parameter, and modify or
+insert an :ENV parameter so that the call is more likely to succeed."
+ (loop with xrd = (format nil "/run/user/~D" (get-connattr :remote-uid))
+ with dsba = (format nil "unix:path=~A/bus" xrd)
+ with arg-done and env-done while args
+ as next = (pop args) collect next into accum
+ if (and (not arg-done) (stringp next))
+ collect "--user" into accum and do (setq arg-done t)
+ if (eql :env next)
+ collect (aprog1 (copy-list (pop args))
+ (setf (getf it :XDG_RUNTIME_DIR) xrd
+ (getf it :DBUS_SESSION_BUS_ADDRESS) dsba
+ env-done t))
+ into accum
+ if (eql :input next)
+ collect (pop args)
+ finally (return (if env-done
+ accum
+ (list* :env `(:XDG_RUNTIME_DIR ,xrd
+ :DBUS_SESSION_BUS_ADDRESS ,dsba)
+ accum)))))
+
(defmacro with-local-temporary-directory ((dir) &body forms)
"Execute FORMS with a local temporary directory's pathname in DIR.
Currently assumes GNU mktemp(1).