diff --git a/adams.asd b/adams.asd
index 148dee1..342f41d 100644
--- a/adams.asd
+++ b/adams.asd
@@ -33,7 +33,6 @@
"cl-ppcre"
"closer-mop"
"ironclad"
- "iterate"
"parse-number"
"re"
"str"
diff --git a/core/defs.lisp b/core/defs.lisp
index 2fcc89a..08d2714 100644
--- a/core/defs.lisp
+++ b/core/defs.lisp
@@ -245,16 +245,6 @@
;; Operators on property lists
(defmacro remf* (place indicator)
- `(iter (while (remf ,place ,indicator))
- (counting t)))
-
-(iterate:defmacro-clause (for* vars in list)
- (let ((l (gensym "LIST-")))
- `(progn
- (with ,l = ,list)
- (while ,l)
- ,@(iter (for var in vars)
- (collect `(for ,var = (if ,l
- (pop ,l)
- (error "~S is not congruent to ~S"
- ',list ',vars))))))))
+ `(loop
+ (unless (remf ,place ,indicator)
+ (return))))
diff --git a/core/host.lisp b/core/host.lisp
index e3081be..bb895b5 100644
--- a/core/host.lisp
+++ b/core/host.lisp
@@ -149,9 +149,9 @@
(cons :hostname (run "hostname")))
(defmethod probe-boot-time ((host host) (os os-unix))
- (iter (uptime<1> (time uptime users load1 load5 load15) in (run "uptime"))
- (return (list :boot-time (chronicity:parse
- (str uptime " seconds ago"))))))
+ (with-uptime<1> (time uptime users load1 load5 load15) (run "uptime")
+ (return (list :boot-time (chronicity:parse
+ (str uptime " seconds ago"))))))
(defmethod probe-host-user ((host host) (os os-unix))
(list :user (first (run "whoami"))))
diff --git a/core/operation.lisp b/core/operation.lisp
index 5c8bff4..67478ff 100644
--- a/core/operation.lisp
+++ b/core/operation.lisp
@@ -38,14 +38,19 @@
'operation)
(defmethod compute-operations ((rc resource-class))
- (iter (for class in (closer-mop:class-precedence-list rc))
- (for direct-ops = (when (typep class 'resource-class)
- (direct-operations class)))
- (dolist (op-definition direct-ops)
- (collect (apply #'make-instance
- (operation-class rc)
- :name
- op-definition)))))
+ (let ((class-precedence-list (closer-mop:class-precedence-list rc))
+ (ops))
+ (loop
+ (when (endp class-precedence-list)
+ (return))
+ (let* ((class (pop class-precedence-list))
+ (direct-ops (when (typep class 'resource-class)
+ (direct-operations class))))
+ (dolist (op-definition direct-ops)
+ (let ((op (apply #'make-instance (operation-class rc)
+ :name op-definition)))
+ (push op ops)))))
+ (nreverse ops)))
(defmethod operation-properties ((rc resource-class))
(let ((properties nil))
@@ -73,13 +78,22 @@
(operations-of r)))
(defmethod list-operations (res plist os)
- (iter (for* (property value) in plist)
- (adjoining (or (find-operation res property os)
- (error 'resource-operation-not-found
- :resource res
- :property property
- :host (current-host)
- :os os)))))
+ (let (operations)
+ (loop
+ (when (endp plist)
+ (return))
+ (let* ((property (pop plist))
+ (value (pop plist))
+ (op (find-operation res property os)))
+ (declare (ignore value))
+ (unless op
+ (error 'resource-operation-not-found
+ :resource res
+ :property property
+ :host (current-host)
+ :os os))
+ (push op operations)))
+ (nreverse operations)))
(defun sort-operations (operations)
(sort operations (lambda (op1 op2)
@@ -88,10 +102,14 @@
(defmethod operate ((res resource) (plist list))
(let* ((os (host-os (current-host)))
(operations (list-operations res plist os))
- (sorted-ops (sort-operations operations)))
- (iter (for op in sorted-ops)
- (collect (apply (operation-generic-function op)
- res os plist)))))
+ (sorted-ops (sort-operations operations))
+ (results))
+ (loop
+ (let* ((op (pop sorted-ops))
+ (result (apply (operation-generic-function op)
+ res os plist)))
+ (push result results)))
+ (nreverse results)))
;; Conditions
diff --git a/core/probe.lisp b/core/probe.lisp
index 91841f0..2468083 100644
--- a/core/probe.lisp
+++ b/core/probe.lisp
@@ -35,14 +35,19 @@
'probe)
(defmethod compute-probes ((rc resource-class))
- (iter (for class in (closer-mop:class-precedence-list rc))
- (for direct-probes = (when (typep class 'resource-class)
- (direct-probes class)))
- (dolist (probe-definition direct-probes)
- (collect (apply #'make-instance
- (probe-class rc)
- :name
- probe-definition)))))
+ (let ((class-precedence-list (closer-mop:class-precedence-list rc))
+ (probes))
+ (loop
+ (when (endp class-precedence-list)
+ (return))
+ (let* ((class (pop class-precedence-list))
+ (direct-probes (when (typep class 'resource-class)
+ (direct-probes class))))
+ (dolist (probe-definition direct-probes)
+ (let ((probe (apply #'make-instance (probe-class rc)
+ :name probe-definition)))
+ (push probe probes)))))
+ (nreverse probes)))
(defmethod probe-properties ((rc resource-class))
(let ((properties nil))
diff --git a/core/properties.lisp b/core/properties.lisp
index 2be489f..c30dd3b 100644
--- a/core/properties.lisp
+++ b/core/properties.lisp
@@ -27,9 +27,15 @@
(when (and (consp (first vars))
(endp (rest vars)))
(setq vars (first vars)))
- `(list ,@(iter (for v in vars)
- (collect (make-keyword v))
- (collect v))))
+ (let ((properties))
+ (loop
+ (when (endp vars)
+ (return))
+ (let ((v (pop vars)))
+ (push (make-keyword v) properties)
+ (push v properties)))
+ (cons 'list
+ (nreverse properties))))
(defmacro values* (&rest vars)
(when (and (consp (first vars))
@@ -41,11 +47,16 @@
`(getf ,properties ,property +undefined+))
(defun get-properties (keys properties)
- (iter (for k in keys)
- (for v = (get-property k properties))
- (unless (eq v +undefined+)
- (collect k)
- (collect v))))
+ (let ((plist))
+ (loop
+ (when (endp keys)
+ (return))
+ (let* ((k (pop keys))
+ (v (get-property k properties)))
+ (unless (eq v +undefined+)
+ (push v plist)
+ (push k plist))))
+ (nreverse plist)))
(defmethod compare-property-values (resource property value1 value2)
(equalp value1 value2))
@@ -75,16 +86,18 @@ Keeping old value by default."
(defun merge-properties (resource &rest properties)
(let* ((result (cons nil nil))
(tail result))
- (dolist (p properties)
- (iter
- (for* (key val) in p)
- (let ((result-val (getf (cdr result) key +undefined+)))
- (cond ((eq result-val +undefined+)
- (setf (cdr tail) (list key val)
- tail (cddr tail)))
- ((not (equalp result-val val))
- (setf (getf (cdr result) key)
- (merge-property-values resource key result-val val)))))))
+ (loop
+ (when (endp properties)
+ (return))
+ (let* ((key (pop properties))
+ (val (pop properties))
+ (result-val (getf (cdr result) key +undefined+)))
+ (cond ((eq result-val +undefined+)
+ (setf (cdr tail) (list key val)
+ tail (cddr tail)))
+ ((not (equalp result-val val))
+ (setf (getf (cdr result) key)
+ (merge-property-values resource key result-val val))))))
(cdr result)))
(let ((p ()))
diff --git a/core/resource-container.lisp b/core/resource-container.lisp
index 7a343af..008f6f4 100644
--- a/core/resource-container.lisp
+++ b/core/resource-container.lisp
@@ -46,14 +46,18 @@
parent)
child))
-(iterate:defmacro-clause (for-resource var in container)
+(defmacro do-resources ((var) container &body body)
(let ((x (gensym)))
- `(for (,x ,var) in-hashtable (resource-registry ,container))))
+ `(maphash (lambda (,x ,var)
+ (declare (ignore ,x))
+ ,@body)
+ (resource-registry ,container))))
(defmethod child-resources ((res resource-container))
- (sort (iter (for-resource child in res)
- (collect child))
- #'resource-before-p))
+ (let ((resources))
+ (do-resources (child) res
+ (push child resources))
+ (sort resources #'resource-before-p)))
;; Resource container
diff --git a/core/resource.lisp b/core/resource.lisp
index 7bc9597..c808f3b 100644
--- a/core/resource.lisp
+++ b/core/resource.lisp
@@ -74,13 +74,18 @@
(defun pprint-plist (plist &optional (stream *standard-output*))
(pprint-logical-block (stream plist)
- (iter (for* (k v) in plist)
- (for first-line-p initially t then nil)
- (unless first-line-p
- (pprint-newline :mandatory stream))
- (write k :stream stream)
- (write-char #\Space stream)
- (write v :stream stream))))
+ (let ((first-line-p t))
+ (loop
+ (when (endp plist)
+ (return))
+ (let ((k (pop plist))
+ (v (pop plist)))
+ (unless first-line-p
+ (pprint-newline :mandatory stream))
+ (setq first-line-p nil)
+ (write k :stream stream)
+ (write-char #\Space stream)
+ (write v :stream stream))))))
#+nil
(pprint-plist '(:a "aaa" :b "foo" :xyz "bar"))
@@ -102,17 +107,28 @@
(mapcar #'resource-id value)
value))
+(defun plist-keys (plist)
+ (let ((keys))
+ (loop
+ (when (endp plist)
+ (return))
+ (let ((key (pop plist))
+ (value (pop plist)))
+ (declare (ignore value))
+ (push key keys)))
+ keys))
+
+(declaim (ftype (function (list) list) plist-keys))
+
(defmethod describe-probed% ((res resource) (out (eql :form)))
(let* ((props (probe-all-properties res))
- (sorted-keys (sort (iter (for* (k v) in props)
- (collect k))
- #'string<))
- (sorted-props (iter (for key in sorted-keys)
- (for value = (describe-probed-property-value
- res key (get-property key props)))
- (when value
- (collect key)
- (collect value)))))
+ (sorted-keys (sort (plist-keys props) #'string<))
+ (sorted-props (mapcan (lambda (key)
+ (let ((value (describe-probed-property-value
+ res key (get-property key props))))
+ (when value
+ (list key value))))
+ sorted-keys)))
`(resource ',(class-name (class-of res))
,(resource-id res)
,@sorted-props)))
@@ -147,6 +163,25 @@
;; Sync
+(defun sync-op (host res op op-keys op-plist os)
+ (let ((failed))
+ (dolist (property op-keys)
+ (let ((specified (get-property property op-plist)))
+ (when (not (eq specified +undefined+))
+ (let* ((probed (get-probed res property))
+ (desc (describe-probed-property-value res property
+ probed)))
+ (unless (match-specified-value res property specified desc)
+ (push (list property specified desc) failed))))))
+ (setq failed (nreverse failed))
+ (when failed
+ (error 'resource-operation-failed
+ :diff failed
+ :operation op
+ :os os
+ :host host
+ :resource res))))
+
(defmethod sync ((res resource))
(when-let ((diff (resource-diff res)))
(let* ((plist (resource-diff-to-plist diff))
@@ -154,37 +189,26 @@
(os (host-os host))
(ops (list-operations res plist os))
(sorted-ops (sort-operations ops)))
- (iter (for op in sorted-ops)
- (for op-keys = (operation-properties op))
- (for op-plist = (get-properties op-keys plist))
- (apply (operation-generic-function op)
- res os op-plist)
- (clear-probed res op-keys)
- (for failed = (iter (for property in op-keys)
- (for specified = (get-property property
- op-plist))
- (when (not (eq specified +undefined+))
- (for probed = (get-probed res property))
- (for desc = (describe-probed-property-value
- res property probed))
- (unless (match-specified-value
- res property specified desc)
- (collect property)
- (collect specified)
- (collect desc)))))
- (when failed
- (error 'resource-operation-failed
- :diff failed
- :operation op
- :os os
- :host host
- :resource res))))))
+ (loop
+ (when (endp sorted-ops)
+ (return))
+ (let* ((op (pop sorted-ops))
+ (op-keys (operation-properties op))
+ (op-plist (get-properties op-keys plist))
+ (op-fun (operation-generic-function op)))
+ (apply op-fun res os op-plist)
+ (clear-probed res op-keys)
+ (sync-op host res op op-keys op-plist os))))))
(defmethod sync ((res resource-container))
(call-next-method)
(with-parent-resource res
- (iter (for child in (child-resources res))
- (sync child))))
+ (let ((child-resources (child-resources res)))
+ (loop
+ (when (endp child-resources)
+ (return))
+ (let ((child (pop child-resources)))
+ (sync child))))))
(defmethod sync ((host host))
(with-host host
diff --git a/core/spec.lisp b/core/spec.lisp
index 082c5fa..7782432 100644
--- a/core/spec.lisp
+++ b/core/spec.lisp
@@ -52,14 +52,15 @@
res)
(defmethod parse-specification ((res resource) (spec cons))
- (iter (while spec)
- (for next-spec = (parse-next-specification res spec))
- (when (eq spec next-spec)
- (error "Invalid specification : ~S" spec))
- (setq spec next-spec))
+ (loop
+ (when (endp spec)
+ (return))
+ (let ((next-spec (parse-next-specification res spec)))
+ (when (eq spec next-spec)
+ (error "Invalid specification : ~S" spec))
+ (setq spec next-spec)))
res)
-
#+nil
(parse-specification *localhost*
'(:hostname "arrakis.lowh.net"))
@@ -115,33 +116,45 @@ Second value lists properties in line with spec. Format is
(PROPERTY-NAME VALUE)"))
(defmethod resource-diff ((res resource))
- (iter (for* (property specified) in (specified-properties res))
- (for probed = (get-probed res property))
- (for desc = (describe-probed-property-value res property probed))
- (if (match-specified-value res property specified desc)
- (collect `(,property ,specified) into ok)
- (collect `(,property ,specified ,desc) into diff))
- (finally (return diff))))
+ (let ((specified-properties (specified-properties res))
+ ok diff)
+ (loop
+ (when (endp specified-properties)
+ (return))
+ (let* ((sp (pop specified-properties))
+ (property (first sp))
+ (specified (second sp))
+ (probed (get-probed res property))
+ (desc (describe-probed-property-value res property probed)))
+ (if (match-specified-value res property specified desc)
+ (push sp ok)
+ (push `(,property ,specified ,desc) diff))))
+ diff))
#+nil
(resource-diff (resource 'directory "/" :owner "root" :uid 0))
(defmethod resource-diff ((res resource-container))
- (append (call-next-method res)
- (sort (iter (for-resource r in res)
- (for d = (resource-diff r))
- (when d
- (collect (cons r d))))
- #'resource-before-p
- :key #'first)))
+ (let ((diffs))
+ (do-resources (r) res
+ (let ((d (resource-diff r)))
+ (when d
+ (push (cons r d) diffs))))
+ (append (call-next-method res)
+ (sort diffs #'resource-before-p :key #'first))))
(defmethod resource-diff ((host host))
(with-host host
(call-next-method)))
(defun resource-diff-to-plist (diff)
- (iter (for item in diff)
- (for key = (first item))
- (when (keywordp key)
- (collect key)
- (collect (second item)))))
+ (let ((plist))
+ (loop
+ (when (endp diff)
+ (return))
+ (let* ((item (pop diff))
+ (key (first item)))
+ (when (keywordp key)
+ (push (second item) plist)
+ (push key plist))))
+ (nreverse plist)))
diff --git a/core/syntaxes.lisp b/core/syntaxes.lisp
index c79f298..24269cb 100644
--- a/core/syntaxes.lisp
+++ b/core/syntaxes.lisp
@@ -22,36 +22,52 @@
;; Simple regexp-based parser generator with ITERATE support
-(defmacro define-syntax (name vars re &body body)
- (let ((parse-name (sym 'parse- name))
- (doc (when (stringp (first body)) (pop body)))
- (values (or (first (last body))
- `(values ,@(iter (for spec in vars)
- (if (consp spec)
- (dolist (var (cdr spec))
- (collect var))
- (collect spec)))))))
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defun collect-vars (specs)
+ (let ((vars))
+ (dolist (spec specs)
+ (if (consp spec)
+ (dolist (var (rest spec))
+ (push var vars))
+ (push spec vars)))
+ (nreverse vars))))
+
+(defmacro define-syntax (name specs re &body body)
+ (let* ((parse-name (sym 'parse- name))
+ (with-name (sym 'with- name))
+ (doc (when (stringp (first body)) (pop body)))
+ (vars (collect-vars specs))
+ (values (or (first (last body)) `(values ,@vars))))
`(progn
(defun ,parse-name (line)
,@(when doc (list doc))
+ (declare (type string line))
(re-bind ,re ,vars line
,@(or body `(,values))))
- (iterate:defmacro-clause (,name iter-vars in lines)
+ (defmacro ,with-name ((,@vars) lines &body with-body)
,@(when doc (list doc))
- (let ((line (gensym ,(format nil "~A-LINE-" (symbol-name name)))))
- `(progn (for ,line in ,lines)
- (for (values ,@iter-vars) = (,',parse-name ,line))))))))
+ `(dolist (line ,lines)
+ (declare (type string line))
+ (multiple-value-bind (,,@vars) (,',parse-name line)
+ (declare (ignorable ,,@vars))
+ ,@with-body))))))
;; Host
(defun parse-uptime (string)
- (or (re-bind #~|^\s*([0-9]+ days,\s*)?([0-9]+):([0-9]+)\s*$| (d h m) string
- (* 60 (+ (parse-integer m)
- (* 60
- (+ (parse-integer h)
- (if d
- (* 24 (parse-integer d :junk-allowed t))
- 0))))))
+ (or (re-bind #~|^\s*([0-9]+ days,\s*)?([0-9]+):([0-9]+)\s*$|
+ (d h m) string
+ (let* ((im (if m (parse-integer m) 0))
+ (ih (if h (parse-integer h) 0))
+ (id (if d (parse-integer d :junk-allowed t) 0))
+ (id-hours (* 24 id))
+ (hours (+ ih id-hours))
+ (hours-minutes (* 60 hours))
+ (minutes (+ im hours-minutes))
+ (seconds (* 60 minutes)))
+ (declare (type fixnum im ih id id-hours hours
+ hours-minutes minutes seconds))
+ seconds))
(error "Invalid uptime ?")))
(define-syntax uptime<1> ((#'chronicity:parse time)
diff --git a/unix/defs.lisp b/unix/defs.lisp
index 3ede6ef..38f4a11 100644
--- a/unix/defs.lisp
+++ b/unix/defs.lisp
@@ -76,9 +76,12 @@
(define-resource-class file (vnode)
()
((probe-file-content :properties (:content))
- . #.(iter (for algorithm in *cksum-algorithms*)
- (collect `(,(sym 'probe-file-cksum- algorithm)
- :properties (,algorithm))))))
+ . #.(let ((algorithms))
+ (dolist (algorithm *cksum-algorithms*)
+ (push `(,(sym 'probe-file-cksum- algorithm)
+ :properties (,algorithm))
+ algorithms))
+ (nreverse algorithms))))
(defgeneric probe-file-content (resource os))
diff --git a/unix/freebsd.lisp b/unix/freebsd.lisp
index 8b3becd..8d18dad 100644
--- a/unix/freebsd.lisp
+++ b/unix/freebsd.lisp
@@ -22,9 +22,9 @@
(defun get-sh-var (name file)
(let (value)
- (iter (sh-var (var val) in (egrep (str "^" name "=") file))
- (when (string= name var)
- (setq value val)))
+ (with-sh-var (var val) (egrep (str "^" name "=") file)
+ (when (string= name var)
+ (setq value val)))
value))
(defsetf get-sh-var (name file) (value)
@@ -96,14 +96,15 @@
#~|^([-_0-9A-Za-z]+)-([_.,0-9A-Za-z]+)\s+([=<>?!])$|)
(defmethod probe-host-packages ((host host) (os os-freebsd))
- (properties :packages (iter (freebsd-pkg-version<8> (name version ensure)
- in (run "pkg version"))
- (when (and name version ensure)
- (let ((pkg (resource 'freebsd-pkg name))
- (versions (list version)))
- (add-probed-properties pkg (properties*
- versions ensure))
- (collect pkg))))))
+ (let ((packages))
+ (with-freebsd-pkg-version<8> (name version ensure)
+ (run "pkg version")
+ (when (and name version ensure)
+ (let ((pkg (resource 'freebsd-pkg name))
+ (versions (list version)))
+ (add-probed-properties pkg (properties* versions ensure))
+ (push pkg packages))))
+ (properties :packages (nreverse packages))))
(define-resource-class freebsd-pkg (pkg)
()
@@ -114,12 +115,11 @@
(let ((id (resource-id pkg))
(ensure :absent)
versions)
- (iter (freebsd-pkg-version<8> (name ver status) in
- (run "pkg version | egrep ^"
- (sh-quote id) "-"))
- (when (equal id name)
- (setq ensure status)
- (push ver versions)))
+ (with-freebsd-pkg-version<8> (name ver status)
+ (run "pkg version | egrep ^" (sh-quote id) "-")
+ (when (equal id name)
+ (setq ensure status)
+ (push ver versions)))
(properties* ensure versions)))
(defmethod op-freebsd-pkg ((pkg freebsd-pkg) (os os-freebsd)
diff --git a/unix/openbsd.lisp b/unix/openbsd.lisp
index c045ea1..2aae430 100644
--- a/unix/openbsd.lisp
+++ b/unix/openbsd.lisp
@@ -33,12 +33,12 @@
(defmethod probe-openbsd-pkg ((pkg openbsd-pkg) (os os-openbsd))
(let ((id (resource-id pkg)))
- (multiple-value-bind #1=(versions)
- (iter (pkg_info<1> (name versions) in
- (run "pkg_info | egrep ~A" (sh-quote (str "^" id "-"))))
- (when (string= id name)
- (return (values* #1#))))
- (properties* #1#))))
+ (multiple-value-bind (versions)
+ (with-pkg_info<1> (name versions)
+ (run "pkg_info | egrep ~A" (sh-quote (str "^" id "-")))
+ (when (string= id name)
+ (return (values versions))))
+ (properties* versions))))
(defmethod merge-property-values ((pkg openbsd-pkg)
(property (eql :versions))
@@ -49,11 +49,12 @@
(defmethod probe-installed-packages% ((host host) (os os-openbsd))
(with-host host
- (iter (pkg_info<1> #1=(name versions flavors)
- in (run "pkg_info"))
- (for pkg = (resource 'openbsd-pkg name))
- (add-probed-properties pkg (properties* #1#))
- (adjoining pkg))))
+ (let ((packages))
+ (with-pkg_info<1> (name versions) (run "pkg_info")
+ (let ((pkg (resource 'openbsd-pkg name)))
+ (add-probed-properties pkg (properties* name versions))
+ (push pkg packages)))
+ (nreverse packages))))
(defun probe-installed-packages (&optional (host (current-host)))
(probe-installed-packages% host (host-os host)))
diff --git a/unix/probes.lisp b/unix/probes.lisp
index ed3793f..a1b3beb 100644
--- a/unix/probes.lisp
+++ b/unix/probes.lisp
@@ -24,12 +24,12 @@
(let ((id (resource-id group))
(ensure :absent))
(multiple-value-bind #1=(name passwd gid members)
- (iter (group<5> #1# in (grep (str id) "/etc/group"))
- (when (etypecase id
- (integer (= id gid))
- (string (string= id name)))
- (setq ensure nil)
- (return (values* #1#))))
+ (with-group<5> #1# (grep (str id) "/etc/group")
+ (when (etypecase id
+ (integer (= id gid))
+ (string (string= id name)))
+ (setq ensure nil)
+ (return (values* #1#))))
(properties* (ensure . #1#)))))
;; User
@@ -38,17 +38,17 @@
(let ((id (resource-id user))
(ensure :absent))
(multiple-value-bind #1=(login pass uid gid realname home shell)
- (iter (passwd<5> #1# in
- (etypecase id
- (integer (grep (str #\: id #\:) "/etc/passwd"))
- (string (egrep (str #\^ id #\:) "/etc/passwd"))))
- (when (etypecase id
- (string (string= id login))
- (integer (= id uid)))
- (setq ensure nil
- home (resource 'directory home)
- shell (resource 'file shell))
- (return (values* #1#))))
+ (with-passwd<5> #1#
+ (etypecase id
+ (integer (grep (str #\: id #\:) "/etc/passwd"))
+ (string (egrep (str #\^ id #\:) "/etc/passwd")))
+ (when (etypecase id
+ (string (string= id login))
+ (integer (= id uid)))
+ (setq ensure nil
+ home (resource 'directory home)
+ shell (resource 'file shell))
+ (return (values* #1#))))
(properties* (ensure . #1#)))))
(defmethod probe-user-groups-in-/etc/group ((user user) (os os-unix))
@@ -60,13 +60,13 @@
(get-probed user :login)))
(user-gid (get-probed user :gid))
(user-group nil))
- (setq groups (iter (group<5> (name passwd gid members)
- in (grep user-login "/etc/group"))
- (cond ((= user-gid gid)
- (setq user-group (resource 'group name)))
- ((find user-login members :test #'string=)
- (collect (resource 'group name)))))
- groups (sort groups #'string< :key #'resource-id)
+ (with-group<5> (name passwd gid members)
+ (grep user-login "/etc/group")
+ (cond ((= user-gid gid)
+ (setq user-group (resource 'group name)))
+ ((find user-login members :test #'string=)
+ (push (resource 'group name) groups))))
+ (setq groups (sort groups #'string< :key #'resource-id)
groups (if user-group
(cons user-group groups)
groups))))
@@ -77,53 +77,60 @@
(defmethod probe-vnode-using-ls ((vnode vnode) (os os-unix))
(let ((id (resource-id vnode)))
(multiple-value-bind #1=(mode links owner group size mtime)
- (iter (ls<1>-lT #.(cons 'name '#1#)
- in (ls "-ldT" id))
- (when (string= id name)
- (setq mode (mode (mode-permissions mode))
- owner (resource 'user owner)
- group (resource 'group group))
- (return (values* #1#))))
+ (with-ls<1>-lT #.(cons 'name '#1#)
+ (ls "-ldT" id)
+ (when (string= id name)
+ (setq mode (mode (mode-permissions mode))
+ owner (resource 'user owner)
+ group (resource 'group group))
+ (return (values* #1#))))
(properties* #1#))))
(defmethod probe-vnode-using-stat ((vnode vnode) (os os-unix))
(let ((id (resource-id vnode)))
(multiple-value-bind #1=(dev ino mode links uid gid rdev size
atime mtime ctime blksize blocks flags)
- (iter (stat<1>-r #.(cons 'name '#1#)
- in (stat "-r" id))
- (when (string= id name)
- (setq mode (mode (mode-permissions mode)))
- (return (values* #1#))))
- (properties* #1#))))
+ (with-stat<1>-r #.(cons 'name '#1#)
+ (stat "-r" id)
+ (when (string= id name)
+ (setq mode (mode (mode-permissions mode)))
+ (return (values* #1#))))
+ (properties* #1#))))
;; Regular file
-#.(cons 'progn
- (iter (for algorithm in *cksum-algorithms*)
- (for name = (sym 'probe-file-cksum- algorithm))
- (for legacy = (member algorithm *cksum-legacy-algorithms*))
- (for iterator = (if legacy
- 'cksum<1>-legacy
- 'cksum<1>))
- (for vars = (if legacy
- '(sum size name)
- '(algo name sum)))
- (for cmd = (str "cksum -a " algorithm " "))
- (for match-p = (if legacy
- `(string= id name)
- `(and (string= ,algorithm algo)
- (string= id name))))
- (for var = (sym algorithm))
- (collect `(defgeneric ,name (file os)))
- (collect `(defmethod ,name ((file file) (os os-unix))
- (let* ((id (resource-id file))
- (,var (iter (,iterator ,vars
- in (run ,cmd
- (sh-quote id)))
- (when ,match-p
- (return sum)))))
- (properties* ,var))))))
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defparameter *cksum-defs* nil))
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defun cksum-defs ()
+ (dolist (algorithm *cksum-algorithms*)
+ (declare (type symbol algorithm))
+ (let* ((name (sym 'probe-file-cksum- algorithm))
+ (legacy (member algorithm *cksum-legacy-algorithms*))
+ (iterator (if legacy 'with-cksum<1>-legacy
+ 'with-cksum<1>))
+ (vars (if legacy '(sum size name) '(algo name sum)))
+ (cmd (str "cksum -a " algorithm " "))
+ (match-p (if legacy
+ `(string= id name)
+ `(and (string= ,algorithm algo)
+ (string= id name))))
+ (var (sym algorithm)))
+ (push `(defmethod ,name ((file file) (os os-unix))
+ (let* ((id (resource-id file))
+ (,var (,iterator ,vars
+ (run ,cmd (sh-quote id)))
+ (when ,match-p
+ (return sum))))
+ (properties* ,var)))
+ *cksum-defs*)
+ (push `(defgeneric ,name (file os)) *cksum-defs*)))
+ (setf *cksum-defs* (nreverse *cksum-defs*))
+ (push 'progn *cksum-defs*)))
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ #.(cksum-defs))
(defmethod probe-file-content ((file file) (os os-unix))
(let* ((size (get-probed file :size))
@@ -147,12 +154,11 @@
(defmethod probe-mount ((m mount) (os os-unix))
(let ((id (resource-id m)))
(multiple-value-bind (dev mp fstype options)
- (iter (mount<8> (dev mp fstype options)
- in (run "mount | grep "
- (sh-quote (str id " "))))
- (when (or (string= id dev)
- (string= id mp))
- (return (values dev mp fstype options))))
+ (with-mount<8> (dev mp fstype options)
+ (run "mount | grep " (sh-quote (str id " ")))
+ (when (or (string= id dev)
+ (string= id mp))
+ (return (values dev mp fstype options))))
(properties :mounted-device dev
:mounted-mount-point mp
:mounted-fstype fstype
@@ -161,13 +167,11 @@
(defmethod probe-fstab ((m mount) (os os-unix))
(let ((id (resource-id m)))
(multiple-value-bind (dev mp fstype options freq passno)
- (iter (fstab<5> (dev mp fstype options freq passno)
- in (run "grep "
- (sh-quote (str id " "))
- " /etc/fstab"))
- (when (or (string= id dev)
- (string= id mp))
- (return (values dev mp fstype options freq passno))))
+ (with-fstab<5> (dev mp fstype options freq passno)
+ (run "grep " (sh-quote (str id " ")) " /etc/fstab")
+ (when (or (string= id dev)
+ (string= id mp))
+ (return (values dev mp fstype options freq passno))))
(properties :fstab-device dev
:fstab-mount-point mp
:fstab-fstype fstype
@@ -183,16 +187,16 @@
(defmethod probe-ps-auxww ((process process) (os os-unix))
(let ((id (resource-id process)))
(multiple-value-bind #1=(user pid cpu mem vsz rss tt state start time cmd)
- (iter (ps<1>-u #1# in (run "ps auxww | grep " (sh-quote id)))
- (print #.(cons 'list '#1#))
- (when (typecase id
- (integer (= id pid))
- (string (and (<= (length id) (length cmd))
- (string= id cmd :end2 (length id))
- (or (= (length id) (length cmd))
- (char= #\Space (char cmd (length id)))))))
- (return (values* #1#))))
- (properties* #1#))))
+ (with-ps<1>-u #1# (run "ps auxww | grep " (sh-quote id))
+ (print #.(cons 'list '#1#))
+ (when (typecase id
+ (integer (= id pid))
+ (string (and (<= (length id) (length cmd))
+ (string= id cmd :end2 (length id))
+ (or (= (length id) (length cmd))
+ (char= #\Space (char cmd (length id)))))))
+ (return (values* #1#))))
+ (properties* #1#))))
#+nil
(probe-all-properties (resource 'process "svscan"))
diff --git a/unix/syntaxes.lisp b/unix/syntaxes.lisp
index 8dd14a8..24d077e 100644
--- a/unix/syntaxes.lisp
+++ b/unix/syntaxes.lisp
@@ -73,13 +73,19 @@
"Syntax for /etc/fstab, see fstab(5)."
(values device mp type
(re-matches #~|[^,]+| options)
- (parse-integer freq)
- (parse-integer passno)))
+ (when freq (parse-integer freq))
+ (when passno (parse-integer passno))))
(defun parse-ps-time (string)
(or (re-bind #~|^\s*([0-9]+):([0-9]*\.[0-9]*)$| (d h) string
- (+ (* 3600 24 (the non-negative-fixnum (parse-integer d)))
- (truncate (* 3600 (parse-number h)))))
+ (let* ((id (if d (parse-integer d) 0))
+ (nh (if h (parse-number h) 0))
+ (id-sec (* 3600 24 id))
+ (nh-sec (* 3600 nh))
+ (ih-sec (truncate nh-sec))
+ (sec (+ id-sec ih-sec)))
+ (declare (type fixnum id nh id-sec nh-sec sec))
+ sec))
(error "Invalid ps(1) time ?")))
(define-syntax ps<1>-u (user
@@ -107,28 +113,25 @@
(find char +sh-word-delimiters+ :test #'eq))
(defun parse-sh-var-value (string)
+ (declare (type string string))
(with-output-to-string (out)
- (iter (with quote = nil)
- (with backslash = nil)
- (for i below (length string))
- (for c = (char string i))
- (cond
- (backslash
- (setq backslash nil)
- (write-char c out))
- ((and (eq #\\ c) (not (eq #\' quote)))
- (setq backslash t))
- ((eq quote c)
- (setq quote nil))
- ((and (null quote) (or (eq #\" c) (eq #\' c)))
- (setq quote c))
- ((and (null quote) (sh-word-delimiter-p c))
- (finish))
- (:otherwise
- (write-char c out)))
- (finally
- (when (or quote backslash)
- (error "Unmatched quote"))))))
+ (let ((quote)
+ (backslash)
+ (i 0))
+ (declare (type fixnum i))
+ (loop
+ (unless (< i (length string))
+ (return))
+ (let ((c (char string i)))
+ (cond
+ (backslash (setq backslash nil) (write-char c out))
+ ((and (eq #\\ c) (not (eq #\' quote))) (setq backslash t))
+ ((eq quote c) (setq quote nil))
+ ((and (null quote) (or (eq #\" c) (eq #\' c))) (setq quote c))
+ ((and (null quote) (sh-word-delimiter-p c)) (return))
+ (:otherwise (write-char c out)))))
+ (when (or quote backslash)
+ (error "Unmatched quote")))))
(define-syntax sh-var (var (#'parse-sh-var-value value))
#~|^\s*(\w*)=(.*)|)