diff options
author | Ludovic Courtès <ludo@gnu.org> | 2019-10-23 14:22:36 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2019-10-23 14:53:50 +0200 |
commit | c96863bc7cc019661dc3235bbb3fbdb870b3d474 (patch) | |
tree | 43a27ea791ccd68e8caf8a3cb728aaf2bab2522a /src | |
parent | 9acb0aa55b5787edef885bb812e2ee66d4401e80 (diff) | |
download | cuirass-c96863bc7cc019661dc3235bbb3fbdb870b3d474.tar cuirass-c96863bc7cc019661dc3235bbb3fbdb870b3d474.tar.gz |
base: Write to 'evaluate' output to /var/log/cuirass.
This fixes a longstanding issue where evalution output would splatter
over the /var/log/cuirass.log and be inscrutable.
* src/cuirass/base.scm (%cuirass-state-directory): New variable.
(evaluation-log-file): New procedure.
(evaluate)[log-file, log-pipe]: New variables.
Call 'spawn-fiber' with a logging fiber. Wrap 'open-pipe*' call into
'with-error-to-port'. Close 'log-pipe'.
Diffstat (limited to 'src')
-rw-r--r-- | src/cuirass/base.scm | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/cuirass/base.scm b/src/cuirass/base.scm index 2c568c9..00b1daa 100644 --- a/src/cuirass/base.scm +++ b/src/cuirass/base.scm @@ -25,12 +25,14 @@ #:use-module (cuirass logging) #:use-module (cuirass database) #:use-module (cuirass utils) + #:use-module ((cuirass config) #:select (%localstatedir)) #:use-module (gnu packages) #:use-module (guix build utils) #:use-module (guix derivations) #:use-module (guix store) #:use-module (guix git) #:use-module (guix cache) + #:use-module (guix zlib) #:use-module ((guix config) #:select (%state-directory)) #:use-module (git) #:use-module (ice-9 binary-ports) @@ -286,6 +288,17 @@ fibers." (logior (@ (fibers epoll) EPOLLERR) (@ (fibers epoll) EPOLLHUP))))) +(define %cuirass-state-directory + ;; Directory where state files are stored, usually "/var". + (make-parameter (or (getenv "CUIRASS_STATE_DIRECTORY") + %localstatedir))) + +(define (evaluation-log-file eval-id) + "Return the name of the file containing the output of evaluation EVAL-ID." + (string-append (%cuirass-state-directory) + "/log/cuirass/evaluations/" + (number->string eval-id) ".gz")) + (define (evaluate store spec eval-id checkouts) "Evaluate and build package derivations defined in SPEC, using CHECKOUTS. Return a list of jobs that are associated to EVAL-ID." @@ -297,20 +310,50 @@ Return a list of jobs that are associated to EVAL-ID." (#:system . ,(derivation-system drv)) ,@job))) + (define log-file + (evaluation-log-file eval-id)) + + (define log-pipe + (pipe)) + + (mkdir-p (dirname log-file)) + + ;; Spawn a fiber that reads standard error from 'evaluate' and writes it to + ;; LOG-FILE. + (spawn-fiber + (lambda () + (define input + (non-blocking-port (car log-pipe))) + + (define output + ;; Note: Don't use 'call-with-gzip-output-port' as it doesn't play well + ;; with fibers (namely, its dynamic-wind handler would close the output + ;; port as soon as a context switch occurs.) + (make-gzip-output-port (open-output-file log-file) + #:level 8 #:buffer-size 16384)) + + (dump-port input output) + (close-port input) + (close-port output))) + (let* ((port (non-blocking-port - (open-pipe* OPEN_READ "evaluate" - (object->string spec) - (object->string checkouts)))) + (with-error-to-port (cdr log-pipe) + (lambda () + (open-pipe* OPEN_READ "evaluate" + (object->string spec) + (object->string checkouts)))))) (result (match (read/non-blocking port) ;; If an error occured during evaluation report it, ;; otherwise, suppose that data read from port are ;; correct and keep things going. ((? eof-object?) (db-set-evaluation-done eval-id) ;failed! + (close-port (cdr log-pipe)) (raise (condition (&evaluation-error (name (assq-ref spec #:name)))))) (data data)))) + (close-port (cdr log-pipe)) (close-pipe port) (match result (('evaluation jobs) |