From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kGYwM4PnqGKa2QAAbAwnHQ (envelope-from ) for ; Tue, 14 Jun 2022 21:54:43 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id UMsaM4PnqGI9hQAA9RJhRA (envelope-from ) for ; Tue, 14 Jun 2022 21:54:43 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 128AA966C for ; Tue, 14 Jun 2022 21:54:43 +0200 (CEST) Received: from localhost ([::1]:49402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1Ccb-0008Cw-In for larch@yhetil.org; Tue, 14 Jun 2022 15:54:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1CcX-0008CH-M7 for gwl-devel@gnu.org; Tue, 14 Jun 2022 15:54:37 -0400 Received: from smtp.polymtl.ca ([132.207.4.11]:49528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1CcU-00055A-Ns for gwl-devel@gnu.org; Tue, 14 Jun 2022 15:54:36 -0400 Received: from laura.hitronhub.home (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 25EJrc8Q020673 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 14 Jun 2022 15:54:33 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 25EJrc8Q020673 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1655236473; bh=JUlT95yF6DSFMUlblwGm5B81S2HCFUZglj8M3o/Q3bQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yxb6hD7qbEdQevZJC8PkB6/Xyeb8hI+ppamGqk0oswsylzm+wo6x2xuFHoElXfeqh rxftrAAioNgMVFixyNnkP3MiZBjfYwR0J/CoGasouUJ+zJ4Q4/9jENcU4o4+fGGLZ9 IQdj+G80IBrQX0JW4zJOaFxygDsqf3qUTJJTsSyQ= From: Olivier Dion To: Olivier Dion via Cc: Olivier Dion Subject: [PATCH 2/2] gwl/ui: Protect format to currnt-error-port with mutex Date: Tue, 14 Jun 2022 15:53:37 -0400 Message-Id: <20220614195337.30570-2-olivier.dion@polymtl.ca> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614195337.30570-1-olivier.dion@polymtl.ca> References: <87edzxuyis.fsf@laura> <20220614195337.30570-1-olivier.dion@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Tue, 14 Jun 2022 19:53:38 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: gwl-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gwl-devel-bounces+larch=yhetil.org@gnu.org Sender: "gwl-devel" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1655236483; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=JUlT95yF6DSFMUlblwGm5B81S2HCFUZglj8M3o/Q3bQ=; b=q+gqRGfuAFQiCkeVYjdEbP0uoO9syxoix/NPTtMPF2/CS+3UeKkxkOrTHNucL1U7kgoOEq myK0Ri962doUI817cgvqyE8o9ve+6pD0lbQ1LDlgvUFUiODEcOOYFZpQx4ezMnHTthO8Tp gHG9NAAnAUevVte3b5FKzq5nntHI7LqAoc7totewEj6Pc6YngpPCePLkhU7lTNVrNrSOaa mlqlQxXXUHTcrYiV/g9BV1BN+XDDYvNxnIRlbJyzEt/x6+raS+QNzZdH5BHnek0Jw4nV87 B4b5+J+aH2ydVWAwNgapgxIhMqXjhfeuJ2yhBhAd2NYDi67r0n9rBvbjluXlDQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1655236483; a=rsa-sha256; cv=none; b=K9VZ1OZaIBr8QzsiTfuoKiErdVGedtEnyNbnFjXxtKSzVFS/b7l/XpB/b0baipDQcrdr3U StzRRUu5VAUOIDUMUrJBUk51N117zV/hkkUpCRoQr6+55MKk3ezJ+yPVSl0IvCMRqTBeYW cuKx77E0o5/NPnwZ+mvyFaEPTiyatY4MP7n+EunsFyaZgyA2ehziMOl39982PGIABUfYPP 8DGYTFJc/ilxg0DG6iqXdjG4PMC8q7FFh5YY1UFFfF1oxZgeyBlvDz79IKwDAU59bBkMhj ZxfLLAstBJkBsynWszw7TWZ6Cg7/35cz8bidp+La00lvacMAZ9O5+FH058pxtQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=polymtl.ca header.s=default header.b=Yxb6hD7q; dmarc=pass (policy=quarantine) header.from=polymtl.ca; spf=pass (aspmx1.migadu.com: domain of "gwl-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="gwl-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -6.19 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=polymtl.ca header.s=default header.b=Yxb6hD7q; dmarc=pass (policy=quarantine) header.from=polymtl.ca; spf=pass (aspmx1.migadu.com: domain of "gwl-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="gwl-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 128AA966C X-Spam-Score: -6.19 X-Migadu-Scanner: scn0.migadu.com X-TUID: 7S9KMBs96Fns When executing processes in parallel, outputs from threads can be mangled together if the access is not exclusive. --- gwl/ui.scm | 59 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/gwl/ui.scm b/gwl/ui.scm index 35bd127..339649c 100644 --- a/gwl/ui.scm +++ b/gwl/ui.scm @@ -19,6 +19,7 @@ #:use-module (guix colors) #:use-module (srfi srfi-26) #:use-module (ice-9 format) + #:use-module (ice-9 threads) #:export (G_ log-event @@ -39,6 +40,8 @@ (define %debug-color (color BOLD MAGENTA)) (define %execute-color (color BOLD YELLOW)) +(define log-mutex (make-recursive-mutex)) + (define* (print-diagnostic-prefix prefix #:optional location #:key (colors (color))) "Print PREFIX as a diagnostic line prefix." @@ -56,36 +59,38 @@ (colorize-string prefix colors)) identity)) - (if (location? location) - (format (current-error-port) "~a: ~a" - (location-color (location->string location)) - (prefix-color prefix)) - (format (current-error-port) "~a" - (prefix-color prefix)))) + (with-mutex log-mutex + (if (location? location) + (format (current-error-port) "~a: ~a" + (location-color (location->string location)) + (prefix-color prefix)) + (format (current-error-port) "~a" + (prefix-color prefix))))) (define (log-event type . message) (define print? (or (member 'all (%config 'log-events)) (member type (%config 'log-events)))) (when print? - (case type - ((error) - (print-diagnostic-prefix (G_ "error: ") #:colors %error-color)) - ((info) - (print-diagnostic-prefix (G_ "info: ") #:colors %info-color)) - ((execute) - (print-diagnostic-prefix (G_ "run: ") #:colors %execute-color)) - ((cache) - (print-diagnostic-prefix (G_ "cache: ") #:colors %debug-color)) - ((debug) - (print-diagnostic-prefix (G_ "debug: ") #:colors %debug-color)) - ((process) - (print-diagnostic-prefix (G_ "process: ") #:colors %execute-color)) - ((guix) - (print-diagnostic-prefix (G_ "guix: ") #:colors %execute-color)) - (else #true)) - (force-output (current-error-port)) - (format (current-error-port) "~2,2f " - (/ (get-internal-real-time) - internal-time-units-per-second)) - (apply format (current-error-port) message))) + (with-mutex log-mutex + (case type + ((error) + (print-diagnostic-prefix (G_ "error: ") #:colors %error-color)) + ((info) + (print-diagnostic-prefix (G_ "info: ") #:colors %info-color)) + ((execute) + (print-diagnostic-prefix (G_ "run: ") #:colors %execute-color)) + ((cache) + (print-diagnostic-prefix (G_ "cache: ") #:colors %debug-color)) + ((debug) + (print-diagnostic-prefix (G_ "debug: ") #:colors %debug-color)) + ((process) + (print-diagnostic-prefix (G_ "process: ") #:colors %execute-color)) + ((guix) + (print-diagnostic-prefix (G_ "guix: ") #:colors %execute-color)) + (else #true)) + (force-output (current-error-port)) + (format (current-error-port) "~2,2f " + (/ (get-internal-real-time) + internal-time-units-per-second)) + (apply format (current-error-port) message)))) -- 2.36.1