civodul pushed a commit to branch wip-syslogd
in repository shepherd.
commit 30ccc5097ac36bf8d755b426b289ebf5249ed759
Author: Ludovic Courtès <[email protected]>
AuthorDate: Mon Jul 22 23:21:54 2024 +0200
squash! Remove PID/sender parsing.
---
modules/shepherd/service/system-log.scm | 35 ++++++---------------------------
tests/services/system-log-internal.scm | 13 ++----------
2 files changed, 8 insertions(+), 40 deletions(-)
diff --git a/modules/shepherd/service/system-log.scm
b/modules/shepherd/service/system-log.scm
index 297c8fc..9185776 100644
--- a/modules/shepherd/service/system-log.scm
+++ b/modules/shepherd/service/system-log.scm
@@ -40,8 +40,6 @@
#:export (system-log-message?
system-log-message-facility
system-log-message-priority
- system-log-message-pid
- system-log-message-sender
system-log-message-content
system-log-priority
@@ -53,11 +51,9 @@
;; Message sent to the system log (minus its timestamp).
(define-record-type <system-log-message>
- (system-log-message priority+facility sender pid content)
+ (system-log-message priority+facility content)
system-log-message?
(priority+facility system-log-message-priority+facility)
- (sender system-log-message-sender)
- (pid system-log-message-pid)
(content system-log-message-content))
(define-syntax define-enumerate-type
@@ -119,11 +115,7 @@
;; Regexp matching system log messages. Example:
;; <29>Jun 22 16:41:30 wpa_supplicant[303]: whatever
(make-regexp "<([0-9]+)> ?([[:alpha:]]{3} [0-9]+ [0-9]+:[0-9]+:[0-9]+ )?\
-([[:graph:]]+): (.*)"))
-
-(define %process+pid-rx
- ;; Regexp matching "process[123]".
- (make-regexp "([[:graph:]]+)\\[([[:digit:]]+)\\]"))
+(.*)"))
(define %default-priority (system-log-priority notice))
(define %default-facility (system-log-facility user))
@@ -134,19 +126,11 @@ representing it."
(match (false-if-exception (regexp-exec %system-log-message-rx line))
(#f
(system-log-message (logior %default-facility %default-priority)
- #f #f line))
+ line))
(m
- (let* ((facility+priority (string->number (match:substring m 1)))
- (process+pid (match:substring m 3))
- (process pid (match (regexp-exec %process+pid-rx
- process+pid)
- (#f (values process+pid #f))
- (m (values (match:substring m 1)
- (string->number
- (match:substring m 2)))))))
+ (let* ((facility+priority (string->number (match:substring m 1))))
(system-log-message facility+priority
- process pid
- (match:substring m 4))))))
+ (match:substring m 3))))))
(define (read-system-log-message port)
"Read a system log message from @var{port}. Return the end-of-file object
@@ -224,7 +208,7 @@ messages to be logged on @var{socket} and passing them to
@var{dispatcher}."
;; Message logged when nothing was logged for a while.
(system-log-message (logior (system-log-facility internal/mark)
(system-log-priority info))
- #f #f "-- MARK --"))
+ "-- MARK --"))
(define* (log-dispatcher channel log-files #:key max-silent-time)
"Dispatch system log messages received on @var{channel} to log files. Call
@@ -237,13 +221,6 @@ file(s)."
(localtime now))))
;; Avoid (ice-9 format) to reduce heap allocations.
(put-string output prefix)
- (when (system-log-message-sender message)
- (if (system-log-message-pid message)
- (simple-format output "~a[~a]: "
- (system-log-message-sender message)
- (system-log-message-pid message))
- (simple-format output "~a: "
- (system-log-message-sender message))))
(put-string output (system-log-message-content message))
(newline output)
now))
diff --git a/tests/services/system-log-internal.scm
b/tests/services/system-log-internal.scm
index 2520f65..4101909 100644
--- a/tests/services/system-log-internal.scm
+++ b/tests/services/system-log-internal.scm
@@ -25,37 +25,30 @@
(test-equal "read-system-log-message, with PID"
(list (system-log-facility daemon)
(system-log-priority notice)
- "wpa_supplicant" 303
- "wlp0s20f0u2: CTRL-EVENT-BEACON-LOSS")
+ "wpa_supplicant[303]: wlp0s20f0u2: CTRL-EVENT-BEACON-LOSS")
(call-with-input-string "<29>Jun 22 16:41:31 wpa_supplicant[303]: \
wlp0s20f0u2: CTRL-EVENT-BEACON-LOSS"
(lambda (port)
(let ((message (read-system-log-message port)))
(list (system-log-message-facility message)
(system-log-message-priority message)
- (system-log-message-sender message)
- (system-log-message-pid message)
(system-log-message-content message))))))
(test-equal "read-system-log-message, without PID"
(list (system-log-facility authorization/private)
(system-log-priority notice)
- "sudo" #f
- "ludo : TTY=pts/0 ; PWD=/home/ludo ; USER=root ; COMMAND=xyz")
+ "sudo: ludo : TTY=pts/0 ; PWD=/home/ludo ; USER=root ; COMMAND=xyz")
(call-with-input-string "<85>Jun 29 10:45:55 \
sudo: ludo : TTY=pts/0 ; PWD=/home/ludo ; USER=root ; COMMAND=xyz"
(lambda (port)
(let ((message (read-system-log-message port)))
(list (system-log-message-facility message)
(system-log-message-priority message)
- (system-log-message-sender message)
- (system-log-message-pid message)
(system-log-message-content message))))))
(test-equal "read-system-log-message, raw"
(list (system-log-facility user)
(system-log-priority notice)
- #f #f
"shepherd[1]: Stopping service tor...")
;; This message lacks the usual syslog header.
(call-with-input-string "shepherd[1]: Stopping service tor...\n"
@@ -63,8 +56,6 @@ sudo: ludo : TTY=pts/0 ; PWD=/home/ludo ; USER=root ;
COMMAND=xyz"
(let ((message (read-system-log-message port)))
(list (system-log-message-facility message)
(system-log-message-priority message)
- (system-log-message-sender message)
- (system-log-message-pid message)
(system-log-message-content message))))))
(test-end)