unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Michael <fedora.dm0@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH] dmd: Allow storing early logs before writing to disk
Date: Wed, 10 Sep 2014 19:58:11 -0400	[thread overview]
Message-ID: <87d2b36nak.fsf@gmail.com> (raw)

* modules/dmd.scm (main): Start logging to a buffer instead of a
  file when the logfile option is set to "delayed".
* modules/dmd/comm.scm (start-logging-to-buffer): New procedure.
  (start-logging): If logs were being written to a string port,
  write its contents to the log file.
---

Hi,

When using dmd to bring up a read-only file system, it will quit when it
fails to open a log file for writing.

This is a proof-of-concept patch that adds the option to start writing
logs to a string port.  It allows having a dmdconf.scm that runs fsck,
makes the disk writable, and then starts writing past and future log
messages to disk with (start-logging "/var/log/dmd.log").

Does anyone have any thoughts on this?  Is there a better way to handle
this case?

Thanks.

David

 modules/dmd.scm      |  7 +++++--
 modules/dmd/comm.scm | 17 ++++++++++++++---
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/modules/dmd.scm b/modules/dmd.scm
index cf72d7a..e0f69c7 100644
--- a/modules/dmd.scm
+++ b/modules/dmd.scm
@@ -97,7 +97,8 @@
 		  (make <option>
 		    #:long "logfile" #:short #\l
 		    #:takes-arg? #t #:optional-arg? #f #:arg-name "FILE"
-		    #:description "log actions in FILE"
+		    #:description
+		    "log actions in FILE or to a buffer if FILE is \"delayed\""
 		    #:action (lambda (file)
 			       (set! logfile file)))
 		  (make <option>
@@ -137,7 +138,9 @@
     (and socket-file
 	 (verify-dir (dirname socket-file) insecure))
     ;; Enable logging as first action.
-    (start-logging logfile)
+    (if (string-ci=? logfile "delayed")
+      (start-logging-to-buffer)
+      (start-logging logfile))
 
     ;; Send output to log and clients.
     (set-current-output-port dmd-output-port)
diff --git a/modules/dmd/comm.scm b/modules/dmd/comm.scm
index fb08629..aeb45ca 100644
--- a/modules/dmd/comm.scm
+++ b/modules/dmd/comm.scm
@@ -37,6 +37,7 @@
             read-command
 
             start-logging
+            start-logging-to-buffer
             stop-logging
             %current-client-socket
             dmd-output-port))
@@ -103,10 +104,20 @@ return the socket."
 ;; Port for logging.  This must always be a valid port, never `#f'.
 (define log-output-port (%make-void-port "w"))
 (define (start-logging file)
-  (let ((directory (dirname file)))
+  (let ((directory (dirname file)) (oldport log-output-port))
     (unless (file-exists? directory)
-      (mkdir directory)))
-  (set! log-output-port (open-file file "al")))   ; line-buffered port
+      (mkdir directory))
+    (set! log-output-port (open-file file "al"))  ; line-buffered port
+    ;; Attempt to dump any buffered log data to the given log file.  This only
+    ;; succeeds if log-output-port was an open output string port, as verified
+    ;; by get-output-string.  Otherwise, logging to a file is started normally.
+    (catch #t
+      (lambda ()
+        (display (get-output-string oldport) log-output-port)
+        (close-output-port oldport))
+      noop)))
+(define (start-logging-to-buffer)
+  (set! log-output-port (open-output-string)))
 (define (stop-logging)
   (close-port log-output-port)
   (set! log-output-port (%make-void-port "w")))
-- 
1.9.3

             reply	other threads:[~2014-09-10 23:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-10 23:58 David Michael [this message]
2014-09-11 14:31 ` [PATCH] dmd: Allow storing early logs before writing to disk Ludovic Courtès
2014-09-12  2:09   ` David Michael
2014-09-13 12:16     ` Ludovic Courtès
2014-09-17 21:36       ` David Michael
2014-09-19  7:57         ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d2b36nak.fsf@gmail.com \
    --to=fedora.dm0@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).