From patchwork Tue Oct 17 14:06:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1850244 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=pN94OdAv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::b38; helo=mail-yb1-xb38.google.com; envelope-from=swupdate+bncbaabbbvkxkuqmgqe4r2pgji@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-yb1-xb38.google.com (mail-yb1-xb38.google.com [IPv6:2607:f8b0:4864:20::b38]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S8wlZ1HyQz20d4 for ; Wed, 18 Oct 2023 01:07:05 +1100 (AEDT) Received: by mail-yb1-xb38.google.com with SMTP id 3f1490d57ef6-d9ace796374sf6935756276.0 for ; Tue, 17 Oct 2023 07:07:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697551623; cv=pass; d=google.com; s=arc-20160816; b=QSJImcv/rTM3WGpOm5jTG60SezAvcvEpbo7awEnM5uxk4vfnFdqDRStb8OZB7SxXPr g+vC9ftK+8Svxif3RtwOtBABM6zAKkTyPn+GYaZHNce25Y2feoa0N2eJ/KICkUv9hmwF pMpsHIyTimWd6olgfI+2u+9a9iFzhNMVTJXwUoEKERB3/n6mUnac1FEF0YjsEjYSWBUZ jSZYclXhkwJT4cGgGwg3inCD6d6EQW0pUbR0OOIOQ00MKEulxkamTT7GOm6etKxv6sdx 1PZfArZs7tRVP9ARmRRTl1pIpHRweSKn0zBj8ySd/czoc1TghtGRWoGshxZbeO8T6nun yQtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:ui-outboundreport:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=AVaeEOrtO3+Fdny7LRU4ajq2MWn432haZQiTgUiUQKo=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=WGm0heuv+MxgkyzqtGwC3mpO2zGaUQbC4zUHvty0Tyq19Fe4tNwhqj9JnBmDwIrrWI YT+0seiEDlo3JjZTjn+1XDCh5OP2NNt33l+0DJvAnpOczEldGVYeni7GksnkfnecvGAw gWEGGiOMRCe1EdaPIR9WiNE4KeMkLwgIDFfw2EY6qeF1lJvFa9V/PW2wQLrvf6WaXaae lH0UfV8MHHxMwD6HEbUqTrbpPzwmMkdIWuEWoob2b1iRy9+vWdj2PMkwygKaDl//ucYW 1YruCK4jvewWW3K7d1zq/EjhAsCfFaffJl35Zbkx3V5TtUv689RHAJf3CznuVUHvUmS7 hyZg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.75 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1697551623; x=1698156423; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:ui-outboundreport:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:sender:from:to:cc :subject:date:message-id:reply-to; bh=AVaeEOrtO3+Fdny7LRU4ajq2MWn432haZQiTgUiUQKo=; b=pN94OdAv8ZxolEHOZMSILMvUbZoSeRnMhIRmBD2DzhpgzS3OeFmPl1V96gHSlhzgn0 xhjlboq513FaPL1BVsHi761e/ir3bSFy+ZBYBcrypuSW6xuoYuFdcag2ANFI5P6N9oKd FNNwgbaKLN7rnnoXU69geRBQXI0GqH4rMagvd24wq2ouSRkeYS8mE/B46xK1TLwtpKM4 N3VXj3oN/ZGBLtU1vdbtKKD7nodVdd7X/ea+JQdLR5gkN6jJ8HTKfqOYtnK8DxXol24A r9ecPaw7mbF0FUSNG/tQhhOnSf6Y6pl4ONSsf+Q1C3z2RsxlD57otiB66MJGyp73TVmo dPHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697551623; x=1698156423; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender :ui-outboundreport:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:x-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=AVaeEOrtO3+Fdny7LRU4ajq2MWn432haZQiTgUiUQKo=; b=MyknJU8LIVbffWkyHvDfZCDTZlM9hLMYXg8CDlJRZgCd99CJkG8uHD/haHSQjvvlpA eZtUsRCsMAUP9LBJ+8AzqXkhOv5XDIUNTvh4/vvoVhsa1iewqxaVwZ+WdTdVn7jqYwF9 hczciHbDKiGQRK87PyI4vvBrR2nmF0gfknOUP6VoEZwkp9IsP0ABFsPh59xqkSbVsSRC A9hdaCsj+w0NAb7Sl4y+xjyZz15qQmM1IrWlMvtpUaNJPzhuertgCGDTRIf9yA5Uf88E Cc0Z8su9tyGzTKw8jVdbrGdQ8ukxnQMIyYpWuloi+MmLMa25hz1s6nsqyWFa4mhCjWhI IfxQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOJu0Yw+oEFCBTlWCvgM/MHq7Kb+CI/K+oSZ9hNtb9EdkNch68cIdsnM PEeVsSQjXZhZgjhpQ1zn2Gs= X-Google-Smtp-Source: AGHT+IGR4r3xKu2+UrvANOfyvfJ87YXilzT0SyFIpMvWzjC83PnfqykG7zLkDlKYk+50d3xmPOCvsw== X-Received: by 2002:a25:d602:0:b0:d9a:c4cf:a06a with SMTP id n2-20020a25d602000000b00d9ac4cfa06amr2229372ybg.36.1697551622618; Tue, 17 Oct 2023 07:07:02 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a25:da10:0:b0:d86:29c:2155 with SMTP id n16-20020a25da10000000b00d86029c2155ls4219238ybf.2.-pod-prod-01-us; Tue, 17 Oct 2023 07:07:01 -0700 (PDT) X-Received: by 2002:a25:c74e:0:b0:d91:c3fe:6144 with SMTP id w75-20020a25c74e000000b00d91c3fe6144mr2319693ybe.3.1697551621495; Tue, 17 Oct 2023 07:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697551621; cv=none; d=google.com; s=arc-20160816; b=ZHb38BwYNEjK6CfxE1f1i48XFLWSm3AnZRnOWS+9FEgs4tWLneRU9FwvlMt5/1kwps /gW3FvKr3fJjYr/BuwqRZaWsrc3PLZJigTG8SvkPtU25Ves+kecl+bysgJbwpytpXq7K HX1d7J3DyhDJvjrw4MpqDKp/kmRhxwpT4nJH8QTRaOsSvN8fPby/1ai2rloUF30Q7O3d XICCs0H+0lqQxRywstVo710t/TntV7GmDvRkXU1ebEYkElAf/JToDomFiwG8qG5a5VFW oz1FJ/Iuig94eb+1FhOMxTAHjm0g63DkhPeqvJkCJIOh5DpY345i5MnZjc54qan7n+ct U5aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=Fb8bz/fz8FF8eMFoknsXWFy5nNbla5teD0s4DVKcY6A=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=r7TPY1ZtjGGeQxD5rZlcTABDq1CBbDNA1HiwOVnIO9+ZCLuxkoHLoWdcA4hvACrMx2 aQaKUuucfd3HsrvgCz1mGYdZEujgDjNA7+MydClK8oKDnR+jESvZHT5IpfArwxn9qCsS xuzS5gSNurzEF3m2BZoniHOC29KKjAgZgB2S1M/exIqaOg4ULlUOEnrGU9YAzjSO19bl 50eNEP/i2HEZF77ctQGBDzx0gx/Gga9OFjgsYvqpDYilJ06D2dkUj0iKWuO9KhzXF17g LUY8MmliZ5ORjBX4Q364tcLo4PIAmKwt/RVIkiuh4qjjoApNibkQLwHQmVpg5m8bLrSx pZEA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.75 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [217.72.192.75]) by gmr-mx.google.com with ESMTPS id h135-20020a25d08d000000b00d866c1128dcsi110742ybg.2.2023.10.17.07.07.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 07:07:01 -0700 (PDT) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.75 as permitted sender) client-ip=217.72.192.75; Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue108 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MSbt9-1qzjpd0nm5-00Sx6U; Tue, 17 Oct 2023 16:07:00 +0200 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH V2 03/11] Implement IPC to set / get SWUpdate's vars Date: Tue, 17 Oct 2023 16:06:49 +0200 Message-Id: <20231017140657.95860-4-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231017140657.95860-1-stefano.babic@swupdate.org> References: <20231017140657.95860-1-stefano.babic@swupdate.org> MIME-Version: 1.0 X-Provags-ID: V03:K1:+1fHqxRSgTXbetPZf66iLPMNS/CvOKHlqBFuNBD2GvV5QdLZ6+/ Sp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OEZFHMQs1ZIkL71mjA5aSkphmTNl+N7mD8bJhaSgsQV E5l2mT4/RQwvpwA== X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.75 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Access to SWUPdate's vars (namespace) is guaranteed for the core, but other processes could need to store some values to store a state between runs. This is not possible from subprocess because rights are not guaranteed for the namespace's storage. Add an IPC as done for bootloader environment to let subprocesses to store persistently variables. Signed-off-by: Stefano Babic --- core/network_thread.c | 17 +++++++++++ core/swupdate_vars.c | 68 +++++++++++++++++++++++++++++++++++++---- include/swupdate_vars.h | 2 ++ 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/core/network_thread.c b/core/network_thread.c index 916caf28..6b349784 100644 --- a/core/network_thread.c +++ b/core/network_thread.c @@ -33,6 +33,7 @@ #include "pctl.h" #include "generated/autoconf.h" #include "state.h" +#include "swupdate_vars.h" #ifdef CONFIG_SYSTEMD #include @@ -451,6 +452,7 @@ void *network_thread (void *data) struct subprocess_msg_elem *subprocess_msg; bool should_close_socket; struct swupdate_cfg *cfg; + char *varvalue; if (!instp) { TRACE("Fatal error: Network thread aborting..."); @@ -690,6 +692,21 @@ void *network_thread (void *data) msg.data.msg[0] = get_state(); msg.type = ACK; break; + case SET_SWUPDATE_VARS: + msg.type = swupdate_vars_set(msg.data.vars.varname, + msg.data.vars.varvalue, + msg.data.vars.varnamespace) == 0 ? ACK : NACK; + break; + case GET_SWUPDATE_VARS: + varvalue = swupdate_vars_get(msg.data.vars.varname, + msg.data.vars.varnamespace); + memset(msg.data.vars.varvalue, 0, sizeof(msg.data.vars.varvalue)); + if (varvalue) { + strlcpy(msg.data.vars.varvalue, varvalue, sizeof(msg.data.vars.varvalue)); + msg.type = ACK; + } else + msg.type = NACK; + break; default: msg.type = NACK; } diff --git a/core/swupdate_vars.c b/core/swupdate_vars.c index 4dd97ff7..f1e536a8 100644 --- a/core/swupdate_vars.c +++ b/core/swupdate_vars.c @@ -17,11 +17,13 @@ #include #include "generated/autoconf.h" #include "util.h" -#include "dlfcn.h" -#include "bootloader.h" +#include "pctl.h" +#include #include "swupdate_vars.h" +char *namespace_default = NULL; + static inline void libuboot_cleanup(struct uboot_ctx *ctx) { libuboot_close(ctx); @@ -32,8 +34,11 @@ int swupdate_vars_initialize(struct uboot_ctx **ctx, const char *namespace) { int ret; - if (!namespace) - return -EINVAL; + if (!namespace || !strlen(namespace)) { + if(!namespace_default) + return -EINVAL; + namespace = namespace_default; + } ret = libuboot_read_config_ext(ctx, get_fwenv_config()); if (ret) { @@ -50,7 +55,7 @@ int swupdate_vars_initialize(struct uboot_ctx **ctx, const char *namespace) return 0; } -char *swupdate_vars_get(const char *name, const char *namespace) +static char *__swupdate_vars_get(const char *name, const char *namespace) { int ret; struct uboot_ctx *ctx = NULL; @@ -65,7 +70,32 @@ char *swupdate_vars_get(const char *name, const char *namespace) return value; } -int swupdate_vars_set(const char *name, const char *value, const char *namespace) +char *swupdate_vars_get(const char *name, const char *namespace) +{ + if (!name) + return NULL; + + if (pid == getpid()) + { + ipc_message msg; + memset(&msg, 0, sizeof(msg)); + + msg.type = GET_SWUPDATE_VARS; + if (namespace) + strlcpy(msg.data.vars.varnamespace, namespace, sizeof(msg.data.vars.varnamespace)); + strlcpy(msg.data.vars.varname, name, sizeof(msg.data.vars.varname)); + + if (ipc_send_cmd(&msg) || msg.type == NACK) { + ERROR("Failed to get variable %s", name); + return NULL; + } + return strdup (msg.data.vars.varvalue); + } + + return __swupdate_vars_get(name, namespace); +} + +static int __swupdate_vars_set(const char *name, const char *value, const char *namespace) { int ret; struct uboot_ctx *ctx = NULL; @@ -81,6 +111,28 @@ int swupdate_vars_set(const char *name, const char *value, const char *namespace return ret; } +int swupdate_vars_set(const char *name, const char *value, const char *namespace) +{ + ipc_message msg; + + if (!name) + return -EINVAL; + + if (pid == getpid()) { + memset(&msg, 0, sizeof(msg)); + msg.magic = IPC_MAGIC; + msg.type = SET_SWUPDATE_VARS; + if (namespace) + strlcpy(msg.data.vars.varnamespace, namespace, sizeof(msg.data.vars.varnamespace)); + strlcpy(msg.data.vars.varname, name, sizeof(msg.data.vars.varname)); + if (value) + strlcpy(msg.data.vars.varvalue, value, sizeof(msg.data.vars.varvalue)); + return !(ipc_send_cmd(&msg) == 0 && msg.type == ACK); + } + + return __swupdate_vars_set(name, value, namespace); +} + int swupdate_vars_unset(const char *name, const char *namespace) { return swupdate_vars_set(name, NULL, namespace); @@ -91,6 +143,10 @@ int swupdate_vars_apply_list(const char *filename, const char *namespace) int ret; struct uboot_ctx *ctx = NULL; + if (pid == getpid()) { + ERROR("This function can be called only by core !"); + return -EINVAL; + } ret = swupdate_vars_initialize(&ctx, namespace); if (!ret) { libuboot_load_file(ctx, filename); diff --git a/include/swupdate_vars.h b/include/swupdate_vars.h index cbff84e5..1dcab972 100644 --- a/include/swupdate_vars.h +++ b/include/swupdate_vars.h @@ -8,9 +8,11 @@ #pragma once #include +#include int swupdate_vars_initialize(struct uboot_ctx **ctx, const char *namespace); int swupdate_vars_apply_list(const char *filename, const char *namespace); char *swupdate_vars_get(const char *name, const char *namespace); int swupdate_vars_set(const char *name, const char *value, const char *namespace); int swupdate_vars_unset(const char *name, const char *namespace); +bool swupdate_set_default_namespace(const char *namespace);