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 mN54H6XR4mGIxwAAgWs5BA (envelope-from ) for ; Sat, 15 Jan 2022 14:52:37 +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 AN1CHKXR4mEflQAAauVa8A (envelope-from ) for ; Sat, 15 Jan 2022 14:52:37 +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 3E63F2A108 for ; Sat, 15 Jan 2022 14:52:37 +0100 (CET) Received: from localhost ([::1]:39178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n8jTw-0005sH-Dv for larch@yhetil.org; Sat, 15 Jan 2022 08:52:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8jSS-0005Dt-6o for guix-patches@gnu.org; Sat, 15 Jan 2022 08:51:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:46620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n8jSR-0004Eq-OM for guix-patches@gnu.org; Sat, 15 Jan 2022 08:51:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n8jSR-0001qq-N9 for guix-patches@gnu.org; Sat, 15 Jan 2022 08:51:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53063] [PATCH v2 wip-harden-installer 02/18] installer: Generalize logging facility. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 15 Jan 2022 13:51:03 +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: Mathieu Othacehe Cc: 53063@debbugs.gnu.org, ludo@gnu.org, Josselin Poiret Received: via spool by 53063-submit@debbugs.gnu.org id=B53063.16422546406976 (code B ref 53063); Sat, 15 Jan 2022 13:51:03 +0000 Received: (at 53063) by debbugs.gnu.org; 15 Jan 2022 13:50:40 +0000 Received: from localhost ([127.0.0.1]:39496 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n8jS2-0001o7-GA for submit@debbugs.gnu.org; Sat, 15 Jan 2022 08:50:39 -0500 Received: from jpoiret.xyz ([206.189.101.64]:48304) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n8jRp-0001mL-Mm for 53063@debbugs.gnu.org; Sat, 15 Jan 2022 08:50:29 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id BF340184F80; Sat, 15 Jan 2022 13:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1642254625; 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=QE8BvtfJBM95AqVB2EV4lVvHLEsCLPJAFOeewadZw3p4Fx5KcokHOwf7tcBtIl8/WDeE3Y 3qEc1hHb3TA/QJI1wPiC2/+IuurOQ5Tusz2IGbE7bzmFAAUqwpTbbh3FE81kvhZIvkCau7 FYF+Y8D8DXbUUyWf+QHmnSeAiqzSMNHVK/5F3jrtoNNzx1L6iXrk/71clIRjzH9SisSx3j Jsoiizeih2Bj7jaPdL3q+4KiLjICoulk7Go5HLSBFqpyu17llSRs2ermD1Ks77ZEieBAlj 8ttaOw1oR94IV1DZtqleEHVHdijZJv//JpXHpUSr2FaawHaLdJfnSy4iqPdUoA== Date: Sat, 15 Jan 2022 14:49:55 +0100 Message-Id: <20220115135011.5817-3-dev@jpoiret.xyz> In-Reply-To: <20220115135011.5817-1-dev@jpoiret.xyz> References: <8735lz4xsv.fsf@gnu.org> <20220115135011.5817-1-dev@jpoiret.xyz> 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=1642254757; 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=DOC52AbAt+FD2PJZRFp+8GXDnTaMMYVU7tMlzk2M/VMjLCHA0XnnsqvEakdjwczcHQDfTG Qeb3djQqUphyLjup76hx8IGvuKQuFaNDQmWS/8Dkw6vTey2qnMBrqgcseGcDl++7hVA20b E5q44ZEePmjKvgPoE2tPMrXth562oYxQ6iz24h1pkAEGFbYPxlG629Yk+3mWAEWmHl/rJQ YYe8Nlq/thtpz80/ppvU9L1pdK8eb3pzjPMURhfgYJIjCR9+1FNl8coGCNWry/DhTCyE/+ Pi38NAb7zqkl/lpUDW/5H2UkkSXLpE80aH61sEq4I9istSeTm13/TZsH+CFTJw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642254757; a=rsa-sha256; cv=none; b=rWpFfYUBIR+1wd//jnk1FNbRU5+AIZYsAG+M3F3F3n3UQjjQaVpjMx/AoR4bxAMvnS/euz r8kPkQUpcfWYvn/m6KmZ2HZdro6bRNVa5i+ikinIVkxUKQPXrKejO5PfGmOScIZUIlDoCz 7F2UGZuQisNWYsA9ZnltEgSVfKxs0511Ts8AZ5G7GxIiztkVlEuIgHR1lo/HjJsQds745X ps+RTY8DmjYK1rKRuZY7Ppko3JT2+botV7RAuTmPuOocRZg1pZmVov3MYbnysPa+ah50vC E1Zb6rcRLWakeQSKJybn9DktehKF+hA3n3A4wMLO5KL/G7DO+Ukoztor7HXC4A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=QE8BvtfJ; 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.93 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=QE8BvtfJ; 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: 3E63F2A108 X-Spam-Score: -3.93 X-Migadu-Scanner: scn0.migadu.com X-TUID: ZSoqALGVtgFj * 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