feat[all] Wrote initial read-file functionality

I created the first version of READ-SYSTEM.
It parses a .service file into an associative list of hash-tables.
This commit is contained in:
Judah Sotomayor 2023-12-19 16:29:39 -05:00
commit 9474199299
Signed by: judahsotomayor
SSH Key Fingerprint: SHA256:9Dq4ppxhfAjbX+7HLXEt+ROMiIojI6kqQgUyFUJb9lI
4 changed files with 64 additions and 0 deletions

5
packages-systemd.lisp Normal file
View File

@ -0,0 +1,5 @@
(defpackage :service-edit
(:use :common-lisp))
(defpackage :service-opts
(:use :common-lisp))

28
src/read-service.lisp Normal file
View File

@ -0,0 +1,28 @@
;(in-package :service-edit)
(defun read-service (filename)
(let* ((p (merge-pathnames filename))
(section-scanner (ppcre:create-scanner "^\\[(.*)\\]$"))
(sections nil)
(lines (uiop:read-file-lines p))
(cursec nil))
(dolist (line lines)
(ppcre:register-groups-bind (match) (section-scanner line)
(if match
(progn (setf sections (acons (read-from-string match ) (make-hash-table) sections))
(setf cursec match))
(split-line line (cdr (assoc cursec sections)))
)))
sections))
(defun split-line (line value-table)
(ppcre:register-groups-bind (first second) ("(.*)=(.*)" line)
(setf (gethash first value-table ) second )))
;; Testing macro for convenience
(defmacro test ()
(list 'read-service "/home/user/sst/src/test.service"))

22
src/test.service Normal file
View File

@ -0,0 +1,22 @@
[Unit]
Description=D-Bus System Message Bus
Documentation=man:dbus-broker-launch(1)
DefaultDependencies=false
After=dbus.socket
Before=basic.target shutdown.target
Requires=dbus.socket
Conflicts=shutdown.target
[Service]
Type=notify
Sockets=dbus.socket
OOMScoreAdjust=-900
LimitNOFILE=16384
ProtectSystem=full
PrivateTmp=true
PrivateDevices=true
ExecStart=/usr/bin/dbus-broker-launch --scope system --audit
ExecReload=/usr/bin/busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig
[Install]
Alias=dbus.service

9
sst.asd Normal file
View File

@ -0,0 +1,9 @@
(defsystem :systemd-parse
:depends-on (:cl-ppcre)
:components ((:file "packages-systemd")
(:module "src"
:serial t
:components ((:file "read-service")
(:file "write-service")
(:file "service-opts")
))))