From patchwork Sat Apr 23 13:11:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liliana Marie Prikler X-Patchwork-Id: 38765 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id CF23227BBEA; Sat, 23 Apr 2022 14:23:58 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 994F127BBE9 for ; Sat, 23 Apr 2022 14:23:58 +0100 (BST) Received: from localhost ([::1]:56854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1niFjx-0005qE-QB for patchwork@mira.cbaines.net; Sat, 23 Apr 2022 09:23:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1niFeE-0005oN-NT for guix-patches@gnu.org; Sat, 23 Apr 2022 09:18:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1niFeE-0000h1-Cz for guix-patches@gnu.org; Sat, 23 Apr 2022 09:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1niFeE-0006O5-9H for guix-patches@gnu.org; Sat, 23 Apr 2022 09:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55080] [PATCH shepherd] service: Gracefully handle non-existing log directories. Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 23 Apr 2022 13:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55080 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55080@debbugs.gnu.org Cc: ludo@gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.165071985324217 (code B ref -1); Sat, 23 Apr 2022 13:18:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Apr 2022 13:17:33 +0000 Received: from localhost ([127.0.0.1]:55462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1niFdk-0006IO-KP for submit@debbugs.gnu.org; Sat, 23 Apr 2022 09:17:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:53812) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1niFdi-0006HN-Rx for submit@debbugs.gnu.org; Sat, 23 Apr 2022 09:17:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1niFdi-0004z1-7x for guix-patches@gnu.org; Sat, 23 Apr 2022 09:17:30 -0400 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]:33336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1niFdg-0000ea-Bz; Sat, 23 Apr 2022 09:17:29 -0400 Received: by mail-ed1-x542.google.com with SMTP id e30so9964941eda.0; Sat, 23 Apr 2022 06:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:subject:to:cc:content-transfer-encoding:message-id :mime-version; bh=LzLJ6HhTZdQMiXZb0LVHUWGq6v6jGE0mOLNURaveW/c=; b=lkcyrcoAZJzIL2LnHAPLzqjnA5jgon2YgEy520ma128SXTs5rMqLrhws30cTOKltv0 EEueM0KcmFdtvQev+KZsGctRpepgetkcOqOHYK/kl8UxUIgdgnl5Ud7+lzkkU7FLL9GK G09HJrNSApWgy+amy1ltJ2AkZ5aM0r8vyazWDUoV/3knwVGB/Cb03jyXGs6EHuAtIRon cZzNtv1uspuDXXAbqBvp9I3hsVagTghaYmI4VGeCawUCetbaWcaU8y4K0P2vdhKGH8eA 2+coEAJBTZmccLeL2Nozod9OU5rY0YsVXVCFUllq2jcnhtwXlbCvAtsBBzU2H3rMO4Gk QxxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:subject:to:cc :content-transfer-encoding:message-id:mime-version; bh=LzLJ6HhTZdQMiXZb0LVHUWGq6v6jGE0mOLNURaveW/c=; b=J/xY9UVLX0DqZ9spplF31hEdegUqyB306Snr+Cq2h2CbAk3RcTmuF9UwK5Cgj/y8r6 sv4iieuos95sHNdtXHVSZMo4pM1GOgRPkpBibuAi60JBivaDOZUYLFy3DV41oRCQW1Tc ee8nmbv/Fk9/m9jmJUQOC3jgnTXx0TqHctGRCZZ1dtbCNMy4/RvjtDou8FRSpGUwyZfF cVFXW9hm/fPX/ezJrv4gK1SrISLr7HpvJENOieGbkcrGUNm9aKFqKlSsdlDXXv4TifC8 0iiZ5c0+BOwWGH0Ttc3cMhrK1cqQMcZppHXC3xClkibIwfmkm+Q3peeg7gTJrbHbxw3/ B+aw== X-Gm-Message-State: AOAM530S97TqeyibpBtiArv7Vw4OdWPnnS/MtnDp280UgClE86lIfEpI 1/wGsU6p9I9eOdhi8PUHZc5yM4PmyEE= X-Google-Smtp-Source: ABdhPJxcOEDoCWbau2L6N86ZiUSRcMdsQj19YI430iE10gDj59WANsnEl8MEJhKseh0dixheUY5ZKQ== X-Received: by 2002:a05:6402:b57:b0:41d:6d9b:7e0d with SMTP id bx23-20020a0564020b5700b0041d6d9b7e0dmr10020860edb.78.1650719844739; Sat, 23 Apr 2022 06:17:24 -0700 (PDT) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id h22-20020a056402281600b004206bd9d0c6sm2287355ede.8.2022.04.23.06.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 06:17:24 -0700 (PDT) From: Liliana Marie Prikler Date: Sat, 23 Apr 2022 15:11:50 +0200 Message-ID: <2e5292c2d45e525aa1b8e4c495704104d4121291.camel@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::542; envelope-from=liliana.prikler@gmail.com; helo=mail-ed1-x542.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/services.scm (%service-file-logger): New variable, implementing... (service-file-logger): ... the old behaviour of this variable. Catch system errors from %service-file-logger and handle them. --- modules/shepherd/service.scm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index 013347b..567a08b 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -873,9 +873,9 @@ daemon writing FILE is running in a separate PID namespace." (try-again) (apply throw args))))))) -(define (service-file-logger file input) - "Return a thunk meant to run as a fiber that reads from INPUT and logs it to -FILE." +(define (%service-file-logger file input) + "Like 'service-file-logger', but doesn't handle the case in which FILE does +not exist." (let* ((fd (open-fdes file (logior O_CREAT O_WRONLY O_APPEND) #o640)) (output (fdopen fd "al"))) (set-port-encoding! output "UTF-8") @@ -894,6 +894,19 @@ FILE." (format output "~a~a~%" prefix line) (loop)))))))))) +(define (service-file-logger file input) + "Return a thunk meant to run as a fiber that reads from INPUT and logs it to +FILE." + (catch 'system-error + (lambda () + (%service-file-logger file input)) + (lambda args + (if (= ENOENT (system-error-errno args)) + (begin + (mkdir-p (dirname file)) + (%service-file-logger file input)) + (apply throw args))))) + (define (service-builtin-logger command input) "Return a thunk meant to run as a fiber that reads from INPUT and logs to 'log-output-port'."