[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/10: installer: Add 'syslog' macro to write to syslog.
From: |
guix-commits |
Subject: |
02/10: installer: Add 'syslog' macro to write to syslog. |
Date: |
Wed, 19 Feb 2020 17:48:47 -0500 (EST) |
civodul pushed a commit to branch wip-installer-test
in repository guix.
commit 1f9b8707be7d75af8331071857741fe20f8939b0
Author: Ludovic Courtès <address@hidden>
AuthorDate: Tue Feb 18 18:23:19 2020 +0100
installer: Add 'syslog' macro to write to syslog.
* gnu/installer/utils.scm (open-syslog-port, syslog-port): New
procedures.
(syslog): New macro.
---
gnu/installer/utils.scm | 43 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
diff --git a/gnu/installer/utils.scm b/gnu/installer/utils.scm
index ddb96bc..a5f390e 100644
--- a/gnu/installer/utils.scm
+++ b/gnu/installer/utils.scm
@@ -1,6 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Mathieu Othacehe <address@hidden>
-;;; Copyright © 2019 Ludovic Courtès <address@hidden>
+;;; Copyright © 2019, 2020 Ludovic Courtès <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -24,12 +24,16 @@
#:use-module (srfi srfi-34)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 regex)
+ #:use-module (ice-9 format)
#:use-module (ice-9 textual-ports)
#:export (read-lines
read-all
nearest-exact-integer
read-percentage
- run-shell-command))
+ run-shell-command
+
+ syslog-port
+ syslog))
(define* (read-lines #:optional (port (current-input-port)))
"Read lines from PORT and return them as a list."
@@ -91,3 +95,38 @@ COMMAND exited successfully, #f otherwise."
(newline)
(pause)
#t))))
+
+
+;;;
+;;; Logging.
+;;;
+
+(define (open-syslog-port)
+ "Return an open port (a socket) to /dev/log or #f if that wasn't possible."
+ (let ((sock (socket AF_UNIX SOCK_DGRAM 0)))
+ (catch 'system-error
+ (lambda ()
+ (connect sock AF_UNIX "/dev/log")
+ (setvbuf sock 'line)
+ sock)
+ (lambda args
+ (close-port sock)
+ #f))))
+
+(define syslog-port
+ (let ((port #f))
+ (lambda ()
+ "Return an output port to syslog."
+ (unless port
+ (set! port (open-syslog-port)))
+ (or port (%make-void-port "w")))))
+
+(define-syntax syslog
+ (lambda (s)
+ "Like 'format', but write to syslog."
+ (syntax-case s ()
+ ((_ fmt args ...)
+ (string? (syntax->datum #'fmt))
+ (with-syntax ((fmt (string-append "installer[~d]: "
+ (syntax->datum #'fmt))))
+ #'(format (syslog-port) fmt (getpid) args ...))))))
- branch wip-installer-test created (now 299ae5b), guix-commits, 2020/02/19
- 01/10: marionette: 'wait-for' procedures no longer leak a port., guix-commits, 2020/02/19
- 02/10: installer: Add 'syslog' macro to write to syslog.,
guix-commits <=
- 04/10: DRAFT installer: Use a Guile-Newt snapshot that supports 'form-watch-fd'., guix-commits, 2020/02/19
- 07/10: installer: Bypass connectivity check when /tmp/installer-assume-online exists., guix-commits, 2020/02/19
- 05/10: DRAFT installer: Implement a dialog on /var/guix/installer-socket., guix-commits, 2020/02/19
- 09/10: installer: Honor /tmp/installer-system-init-options., guix-commits, 2020/02/19
- 06/10: DRAFT installer: Better support for multiple clients., guix-commits, 2020/02/19
- 10/10: DRAFT tests: install: Add "gui-installed-os"., guix-commits, 2020/02/19
- 08/10: installer: Run commands without hopping through the shell., guix-commits, 2020/02/19
- 03/10: installer: Log important bits to syslog., guix-commits, 2020/02/19