From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id kCabHHOagWbVJgEA62LTzQ:P1 (envelope-from ) for ; Sun, 30 Jun 2024 17:48:35 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id kCabHHOagWbVJgEA62LTzQ (envelope-from ) for ; Sun, 30 Jun 2024 19:48:35 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Pk4unipi; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1719769715; 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=xqUvfjh1qFElXrb+oqg58qLaJTONKFDulphphf1i6ZM=; b=RrGrAIXwnzjjuJmewwyzAVBMC/pGteGGwItB4lSCznwbVXZJuo/4HMLowx7cKny77aeS3a c+IfRMSPY4ZiZAt2h50IcUepE/Zz6KzoEsgzlBZpDndpVZ8HAQ4UQaSPvaUERJp/Sq78eD PvDLWXP4R4lrPan4dMAQfrJSoXPLFA227odp6cMsYrxyC7kurPWi37EC5N4+WGpTGCEW+X EEmtjlmrEEe3on+FCk8qW8UryjmvZLcq44lyY0D5OcokZxsqeDXCpXP17hGDXI4mueTFd5 nbgOvB2EReELab6ZCZZnCTHdFQyNvnFpyy7Xhd/ekUKgl1cFDprfetmD79yRfw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Pk4unipi; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1719769715; a=rsa-sha256; cv=none; b=F9kOZkpeHQoUqJAIuLKAlNOCpVq2eSKsvWfVfo4KoYf22P3ts502NfsFa4a3K9csU4gQTu 19VsGyC1qPhLyM/mg+2CPj9y1FoL+xaElyTAxHcXF7zNiXQEQnU6OS+TglTMEuX/zkI+eP jxGsQOAJM7l+Xaj8PSILM1LETjHHso85VhtDyaxpkZRAQYKcTTt3R86zQUDvGX6860mSZg NlYEt/gm+jnlAyKh+dUBJG6BkIMZTJTattkpJ68eyMQShJyucObxoJpVQfGNHD2XgbZI0j XzRIw8gPG5CrCsmGfCFnP3tUzC+Z5InwzmdNhY6HxmBStzu94MN1wQdbxMESrA== 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 487E63CCEC for ; Sun, 30 Jun 2024 19:48:35 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sNyeW-0001d3-H2; Sun, 30 Jun 2024 13:47:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sNxDp-0005OU-Ra for guix-devel@gnu.org; Sun, 30 Jun 2024 12:16:14 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sNxDo-0005FK-1m for guix-devel@gnu.org; Sun, 30 Jun 2024 12:16:13 -0400 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a725a918edaso311519066b.3 for ; Sun, 30 Jun 2024 09:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719764170; x=1720368970; darn=gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xqUvfjh1qFElXrb+oqg58qLaJTONKFDulphphf1i6ZM=; b=Pk4unipiOOzz3vDRrX+Mymjt5A0BEN1zo5v9bieGo8A43Cv3tQWeKVNRHnHlNw/yCr cHvBS9uO18TFJ4pSKrlvptQIxW13GSzIrvE3aFuWxo2pZeH7fH4vRVDSGyAVT947Eza9 ZiVQKJyKEGml0Njgyi3s300/IBXwOiRquKmWpGBuxJGxI8/evGTb58dSAUXkKt2y2ZpJ YzzgZOF99/uHmN4RoZg/49sHzQVHAgPLSducNp1iVDbUhUa21gnJUsoqdShFWTy5P8ZP l/D9Ivfv4wJiANDRPXVdKSiqbbAuVaEENqTioQ4YBCtgCVR6DpOSUUfgykHdoWepY5a6 L1aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719764170; x=1720368970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xqUvfjh1qFElXrb+oqg58qLaJTONKFDulphphf1i6ZM=; b=Nt72FOfvpO//BPk0Bh42dPwyRWZT6eu+/b3hcrckTF78wjg5iHq+teNP6E9uoSiWwf A6cDB1QxoTA3+77S0jO7J1AwJAb98Hfp84FkbHjWB163bQ3TN8nJLcDJea80WHO9OY06 8lDIE/GJtcgy9ngzlGNCxW0HrKR8Mjmn0Y8eisEUU9wDuyfWh54aAfLh7cXEFz73J5ml JtIKEMjC/Ubl5M0Ey6a/y+KWLkz6H+nBiErhUmW7205Fi+FziyVuvVAjwl6n61ZTjiZ1 A9oCwwb42vrrXMckn673pBlqlvxGizwkoCGgMv0Avby/n9ed4PE5Raak5Jjh3t78B3pv 9fKg== X-Gm-Message-State: AOJu0Yzw+1j2+40dQIRe7aES5tLObKoMsbBHg+6ZLADvmIA3Nbkg0/gM SzJ6R2xpR6VjUDbU6N1J40NpTM8lORWxE5Z6+Plx9Oocc4CK+y2mIELKxQ== X-Google-Smtp-Source: AGHT+IEq2jC0Inl5ThRYRnVOEJz9AeA9TUclFEcl37XlbCppFf9yriSev56aRiGKMR4KSUnw8OtsjQ== X-Received: by 2002:a17:907:ea1:b0:a72:4160:105 with SMTP id a640c23a62f3a-a751451318emr316009566b.61.1719764168426; Sun, 30 Jun 2024 09:16:08 -0700 (PDT) Received: from lelap.lan (2a00-1f40-b161-2920--477.pool6.panelnet.hu. [2a00:1f40:b161:2920::477]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf1bc08sm252509666b.28.2024.06.30.09.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 09:16:08 -0700 (PDT) From: attila.lendvai@gmail.com X-Google-Original-From: attila@lendvai.name To: guix-devel@gnu.org Cc: Attila Lendvai Subject: [PATCH shepherd] service: Factor out SEND-TO-REGISTRY. Date: Sun, 30 Jun 2024 18:13:05 +0200 Message-ID: <20240630161303.22507-8-attila@lendvai.name> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240630161303.22507-2-attila@lendvai.name> References: <20240630161303.22507-2-attila@lendvai.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=attila.lendvai@gmail.com; helo=mail-ej1-x634.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 30 Jun 2024 13:47:43 -0400 X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: guix-devel-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 487E63CCEC X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -9.22 X-Spam-Score: -9.22 X-TUID: 2lN+wInU6cN+ From: Attila Lendvai Also assert that (CURRENT-REGISTRY-CHANNEL) is valid. * modules/shepherd/service.scm (with-service-registry): New function. (stop-service), (fold-services), (service-name-count), (lookup-service), (respawn-service), (register-services), (unregister-services): Use it. --- modules/shepherd/service.scm | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index e1c602c..b5f3e23 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -1030,8 +1030,7 @@ in a list." (report-exception 'stop service key args)))))) (when (transient-service? service) - (put-message (current-registry-channel) - `(unregister ,(list service))) + (send-to-registry `(unregister ,(list service))) (local-output (l10n "Transient service ~a unregistered.") (service-canonical-name service))) @@ -1290,6 +1289,10 @@ task is one that should never fail)." (parameterize ((current-registry-channel (spawn-service-registry))) (thunk))) +(define (send-to-registry message) + (assert (current-registry-channel)) + (put-message (current-registry-channel) message)) + (define-syntax-rule (with-service-registry exp ...) "Spawn a new service monitor and evaluate @var{exp}... within that dynamic extent. This allows @var{exp}... and their callees to send requests to delegate @@ -2286,8 +2289,7 @@ This must be paired with @code{make-systemd-destructor}." (lambda (proc init) "Apply PROC to the registered services to build a result, and return that result. Works in a manner akin to `fold' from SRFI-1." - (put-message (current-registry-channel) - `(service-list ,reply)) + (send-to-registry `(service-list ,reply)) (fold (match-lambda* (((name . service) result) (if (eq? name (service-canonical-name service)) @@ -2311,15 +2313,14 @@ returned in unspecified." (define (service-name-count) "Return the number of currently-registered service names." (let ((reply (make-channel))) - (put-message (current-registry-channel) - `(service-name-count ,reply)) + (send-to-registry `(service-name-count ,reply)) (get-message reply))) (define lookup-service (let ((reply (make-channel))) (lambda (name) "Return the service that provides @var{name}, @code{#f} if there is none." - (put-message (current-registry-channel) `(lookup ,name ,reply)) + (send-to-registry `(lookup ,name ,reply)) (get-message reply)))) (define (lookup-services name) @@ -2631,7 +2632,7 @@ then disable it." (disable-service serv) (when (transient-service? serv) - (put-message (current-registry-channel) `(unregister (,serv))) + (send-to-registry `(unregister (,serv))) (local-output (l10n "Transient service ~a terminated, now unregistered.") (service-canonical-name serv)))))) @@ -2657,7 +2658,7 @@ If it is currently stopped, replace it immediately." (assert (list-of-symbols? (service-requirement new))) (assert (boolean? (respawn-service? new))) - (put-message (current-registry-channel) `(register ,new))) + (send-to-registry `(register ,new))) (let ((services (if (service? services) (begin @@ -2681,8 +2682,7 @@ already stopped." services)) ;; Remove STOPPED from the registry. - (put-message (current-registry-channel) - `(unregister ,stopped)) + (send-to-registry `(unregister ,stopped)) #t) (define (deregister-service service-name) -- 2.45.2