[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 04/07: comm: Do not introduce empty lines in the log.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 04/07: comm: Do not introduce empty lines in the log. |
Date: |
Wed, 19 Sep 2018 11:44:28 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit e45820839e23a19a00347d3b8f88206243fb3eb0
Author: Ludovic Courtès <address@hidden>
Date: Wed Sep 19 16:23:49 2018 +0200
comm: Do not introduce empty lines in the log.
Fixes a regression introduced in
329cec8b6fcc57f945e748793470f573b2b449a3 whereby regular "has been
started" etc. lines in the log would be followed by an empty line.
* modules/shepherd/comm.scm (make-shepherd-output-port): Use
'string-index' in a loop instead of 'string-split' to detect newlines in
STR.
* tests/basic.sh: Check for zero empty lines in $log.
---
modules/shepherd/comm.scm | 21 +++++++++++++--------
tests/basic.sh | 5 +++++
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm
index 43110a7..c31bf02 100644
--- a/modules/shepherd/comm.scm
+++ b/modules/shepherd/comm.scm
@@ -308,18 +308,23 @@ available."
;; completed line.
(if (not (string-index str #\newline))
(set! buffer (cons str buffer))
- (let* ((str (string-concatenate-reverse (cons str buffer)))
- (lines (string-split str #\newline)))
+ (let ((str (string-concatenate-reverse (cons str buffer))))
(define prefix
(strftime (%current-logfile-date-format)
(localtime (current-time))))
- ;; Make exactly one 'display' call per line to make sure we
- ;; don't create several entries for each line.
- (for-each (lambda (line)
- (display (string-append prefix line "\n")
- (log-output-port)))
- lines)
+ ;; Note: We want to render as many newlinew as present in STR,
+ ;; so neither 'string-split' nor 'string-tokenize' helps.
+ (let loop ((str str))
+ (let* ((index (string-index str #\newline))
+ (line (if index (string-take str (+ 1 index)) str)))
+ (unless (string-null? str)
+ ;; Make exactly one 'display' call per line to make sure we
+ ;; don't create several entries for each line.
+ (display (string-append prefix line) (log-output-port))
+ (when index
+ (loop (string-drop str (+ index 1)))))))
+
(set! buffer '())))))
;; Flush output.
diff --git a/tests/basic.sh b/tests/basic.sh
index fc53aa7..cd4ade9 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -98,6 +98,11 @@ then false; else true; fi
$herd enable test-2
$herd start test-2
+# Make sure we didn't emit empty lines in the log (strip the timestamp that
+# prefixes each line.)
+test `wc -l < "$log"` -gt 0
+test `cut -c 21- < "$log" | grep "^$" | wc -l` -eq 0
+
# Try a custom action; make sure we get all the lines, including the empty
# lines (this was not the case in 0.4.0.)
$herd doc test-2 action hi | grep "Say hi\."
- [shepherd] branch master updated (0c4d8ec -> e390a78), Ludovic Courtès, 2018/09/19
- [shepherd] 01/07: Remove EINTR-safe, and all references to it., Ludovic Courtès, 2018/09/19
- [shepherd] 04/07: comm: Do not introduce empty lines in the log.,
Ludovic Courtès <=
- [shepherd] 03/07: i18n: Add missing calls to 'l10n'., Ludovic Courtès, 2018/09/19
- [shepherd] 06/07: service: Update use of long gone 'apply-to-args'., Ludovic Courtès, 2018/09/19
- [shepherd] 02/07: Make sure ctrl-alt-del is handled by PID 1., Ludovic Courtès, 2018/09/19
- [shepherd] 05/07: Remove runlevels., Ludovic Courtès, 2018/09/19
- [shepherd] 07/07: nls: Add sv translation., Ludovic Courtès, 2018/09/19