From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cG4RGuhx12GzTAAAgWs5BA (envelope-from ) for ; Thu, 06 Jan 2022 23:49:12 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id UIupFuhx12GHGwAAauVa8A (envelope-from ) for ; Thu, 06 Jan 2022 23:49:12 +0100 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 E35D236469 for ; Thu, 6 Jan 2022 23:49:11 +0100 (CET) Received: from localhost ([::1]:43910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5bZH-0007Qi-1c for larch@yhetil.org; Thu, 06 Jan 2022 17:49:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5bZ9-0007PP-70 for guix-patches@gnu.org; Thu, 06 Jan 2022 17:49:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:49724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5bZ8-00074W-Tk for guix-patches@gnu.org; Thu, 06 Jan 2022 17:49:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n5bZ8-000052-T2 for guix-patches@gnu.org; Thu, 06 Jan 2022 17:49:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53063] [PATCH wip-harden-installer 02/14] installer: Generalize logging facility. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 06 Jan 2022 22:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53063 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53063@debbugs.gnu.org Cc: Josselin Poiret Received: via spool by 53063-submit@debbugs.gnu.org id=B53063.164150931832596 (code B ref 53063); Thu, 06 Jan 2022 22:49:02 +0000 Received: (at 53063) by debbugs.gnu.org; 6 Jan 2022 22:48:38 +0000 Received: from localhost ([127.0.0.1]:42584 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5bYk-0008Te-2g for submit@debbugs.gnu.org; Thu, 06 Jan 2022 17:48:38 -0500 Received: from jpoiret.xyz ([206.189.101.64]:35958) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5bYh-0008T2-Dr for 53063@debbugs.gnu.org; Thu, 06 Jan 2022 17:48:35 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 9D7BE184F83; Thu, 6 Jan 2022 22:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1641509314; h=from:from: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; bh=comZ3T0WPU6rg1EpDXPEwhpUMK5cwKjVah2oaCEIaCs=; b=ZKINZqToxP3Ys6TYAHN1ZV+nhF3GW3eJMB8TQVYsi8kUK43jQDcMaIBYcwIrgLq3qXdlqQ dTrjE+cFkjt4vOanUfpOeUwKxXD8Yk2nFJMjL3OntxtTxVbILtcz3uB+rtuYygLhr+up7r qbG23MCIjbIul8r90vQBJUPo8tjv7lt3Bov79dBZDsBq070cQMtafC4heTTSAH6PbrlG/T 1Csq3tYnw4F8z4OVSqTTm9kl+XdSLLSRZ69lOnfIwjpErBQ/cWg9N0S/2qfu8JnxO5OgUB 3+gmoGNeao7iB7l1id5Luy/q4dPEpyQnVQQB8UquWps1pbA/4SsKcI/fJjzx1w== Date: Thu, 6 Jan 2022 23:48:00 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches From: Josselin Poiret via Guix-patches via X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641509352; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=comZ3T0WPU6rg1EpDXPEwhpUMK5cwKjVah2oaCEIaCs=; b=D/8v2TWr3LBmushbus7LuHlRR/rV3Uojph9e3KlBSOx+O0ioIRdkzdeBiXv318D7HFog9d +cdqTv7oDuP4q6qpUyQJt/vOCiy8egxtQspom9TCqGlAg7bnYCmP4RrqhD2AE1SLpGCdTE m/Wchf3fyMZsA7ExtEX5wun3bLDoXFJ0/22JhPp44bT54MaHN9iFCs0yRBaL8G0aja6Tzs qKwtlNwtZxmi2eBF8jLO+37uWQb1PGTQEysbgHTvo5Oy8mBGd3djhYuV4jEoAYuiqzJxnb IhPqKj1csL3oeyoq1ydpQaodfUnMO5rBb/zlhltTTTEkiSYXSJ4LClkOn4wrrg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641509352; a=rsa-sha256; cv=none; b=kT6mRIlTns/FhQ50qLNcKDyl13nrHX0OXjR8liwNRJUA5v1CEWff24wicdzSpAfjX68tN8 lJlNd/u4wsbi6H4MM53H+sb3wJVud4FLB9GU3rqZgVZA+9Prwrbp2+Z2rfjNSCE9AKLMF9 yzQUBn7yfI45fOz1pizpwFXRpvu43oWOrs0SKjC389x6NUz99LezivS7vQuOBu2YmHRAbw p40cjETvxeEUYYAkawi8Y0u2+usl6JjRLP7R6QlEs+tfOc0mGktHLW6r3j8QxppKqv2xRQ x4t8eNEdIRbGvsFsZeuoV3MBJKqXezO+tSwNGey4b2Iy+tEjOJC05+c/mN7rsw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=ZKINZqTo; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.90 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=ZKINZqTo; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: E35D236469 X-Spam-Score: -3.90 X-Migadu-Scanner: scn0.migadu.com X-TUID: Y6TaRZ+1wE9q * gnu/installer/utils.scm (%syslog-line-hook, open-new-log-port, installer-log-port, %installer-log-line-hook, %display-line-hook, %default-installer-line-hooks, installer-log-line): Add new variables. --- gnu/installer/utils.scm | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gnu/installer/utils.scm b/gnu/installer/utils.scm index 9bd41e2ca0..b1b6f8b23f 100644 --- a/gnu/installer/utils.scm +++ b/gnu/installer/utils.scm @@ -37,7 +37,12 @@ (define-module (gnu installer utils) run-command syslog-port + %syslog-line-hook syslog + installer-log-port + %installer-log-line-hook + %default-installer-line-hooks + installer-log-line call-with-time let/time @@ -142,6 +147,9 @@ (define syslog-port (set! port (open-syslog-port))) (or port (%make-void-port "w"))))) +(define (%syslog-line-hook line) + (format (syslog-port) "installer[~d]: ~a~%" (getpid) line)) + (define-syntax syslog (lambda (s) "Like 'format', but write to syslog." @@ -152,6 +160,43 @@ (define-syntax syslog (syntax->datum #'fmt)))) #'(format (syslog-port) fmt (getpid) args ...)))))) +(define (open-new-log-port) + (define now (localtime (time-second (current-time)))) + (define filename + (format #f "/tmp/installer.~a.log" + (strftime "%F.%T" now))) + (open filename (logior O_RDWR + O_CREAT))) + +(define installer-log-port + (let ((port #f)) + (lambda () + "Return an input and output port to the installer log." + (unless port + (set! port (open-new-log-port))) + port))) + +(define (%installer-log-line-hook line) + (format (installer-log-port) "~a~%" line)) + +(define (%display-line-hook line) + (display line) + (newline)) + +(define %default-installer-line-hooks + (list %syslog-line-hook + %installer-log-line-hook)) + +(define-syntax installer-log-line + (lambda (s) + "Like 'format', but uses the default line hooks, and only formats one line." + (syntax-case s () + ((_ fmt args ...) + (string? (syntax->datum #'fmt)) + #'(let ((formatted (format #f fmt args ...))) + (for-each (lambda (f) (f formatted)) + %default-installer-line-hooks)))))) + ;;; ;;; Client protocol. -- 2.34.0