From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 738071FF170 for ; Tue, 3 Dec 2024 14:54:01 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 372CE5B99; Tue, 3 Dec 2024 14:54:08 +0100 (CET) From: Shannon Sterz To: pbs-devel@lists.proxmox.com Date: Tue, 3 Dec 2024 14:53:24 +0100 Message-Id: <20241203135325.298743-1-s.sterz@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.037 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [rust-lang.org, init.rs] Subject: [pbs-devel] [PATCH proxmox 1/2] acme-api: use inner mutability for ACME_ACME_CONFIG X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" in edition 2024 references to mutable static will be disallowed [1]. the recommended way around this is to use types with inner mutability. so use a `OnceLock` for `ACME_ACME_CONFIG` as the directoryfor ACME configuration purposes shouldn't change throughout the run time of an application. [1]: https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html Signed-off-by: Shannon Sterz --- proxmox-acme-api/src/init.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/proxmox-acme-api/src/init.rs b/proxmox-acme-api/src/init.rs index a5287a8e..5dcf048c 100644 --- a/proxmox-acme-api/src/init.rs +++ b/proxmox-acme-api/src/init.rs @@ -1,26 +1,28 @@ use std::path::{Path, PathBuf}; +use std::sync::OnceLock; use anyhow::Error; use proxmox_product_config::create_secret_dir; +#[derive(Debug)] struct AcmeApiConfig { acme_config_dir: PathBuf, acme_account_dir: PathBuf, } -static mut ACME_ACME_CONFIG: Option = None; +static ACME_ACME_CONFIG: OnceLock = OnceLock::new(); /// Initialize the global product configuration. pub fn init>(acme_config_dir: P, create_subdirs: bool) -> Result<(), Error> { let acme_config_dir = acme_config_dir.as_ref().to_owned(); - unsafe { - ACME_ACME_CONFIG = Some(AcmeApiConfig { + ACME_ACME_CONFIG + .set(AcmeApiConfig { acme_account_dir: acme_config_dir.join("accounts"), acme_config_dir, - }); - } + }) + .expect("cannot set acme configuration twice"); if create_subdirs { create_secret_dir(self::acme_config_dir(), false)?; @@ -31,11 +33,9 @@ pub fn init>(acme_config_dir: P, create_subdirs: bool) -> Result< } fn acme_api_config() -> &'static AcmeApiConfig { - unsafe { - ACME_ACME_CONFIG - .as_ref() - .expect("ProxmoxProductConfig is not initialized!") - } + ACME_ACME_CONFIG + .get() + .expect("ProxmoxProductConfig is not initialized!") } fn acme_config_dir() -> &'static Path { -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel