From patchwork Mon Nov 22 03:16:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1557858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=c9miXlEp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::43e; helo=mail-pf1-x43e.google.com; envelope-from=swupdate+bncbcwivbv7sugrbcmx5sgamgqeasddlqy@googlegroups.com; receiver=) Received: from mail-pf1-x43e.google.com (mail-pf1-x43e.google.com [IPv6:2607:f8b0:4864:20::43e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyC976KkMz9t0G for ; Mon, 22 Nov 2021 14:16:27 +1100 (AEDT) Received: by mail-pf1-x43e.google.com with SMTP id 4-20020a621604000000b004a4ab765028sf4463470pfw.13 for ; Sun, 21 Nov 2021 19:16:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1637550985; cv=pass; d=google.com; s=arc-20160816; b=vEPUQqB00H58228QthQdtkEJnvFZ0v9ShuOwefnYC4+dVuo0Gv9OgRZ7wAOITpDGy8 zXYMOvFfqF1LPXIGfibmeDBIg4RQeCgOKgqvaSHAqAV2XffZAJekaUdauSxoyIaB4xck KSm97e7A9EHK/m/EHY6VV8d23MQInMtWgw5HzM8+zEcFZyRB6/VBU5FliwQqK2CjAeMn ap8K2AFygq9rOh0HBETu68T9Qz8pfreMA7BSY0GAp6vR/txbmXMDDZiiqOLdaEv1BTix bPHQ8Qc8pQPrfz2xKKly1gQ6iPEJ4uKo8B3uSFLubiysuDAkjudZRPsHQtMxVozra5Lc yh0Q== 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:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=NzvzJfcXs156rFKPG8nImi8OaJ/X1keUbPQokzEoyeQ=; b=uDJQfisaWrNqHtJKccepW/jHZKrdaUHD9gFOPsc8O6glMA+9xk+jtWQux60Byk39kV yesFW9RLakL0aaIi9fKYGRqsob9VrEhVlukWHLU3D0ww2i2uTSYl5ESVvC+EeUSNBPDU gUxs68lkWSTaSNQBZQBpoQSmBzNUwm2HuCbY7Y8FJIsT9CXcgSasUw+Ik6+bswnA+JSW +9i1kuTmOVXvltCJlWMzX8wDAr1+Xiu98e17PVNN0GT6hcX48Thrh7Hp7sQ34PCF9rVD XzO162MsOp07ZnwU8ayTncUk53lyZMT4xOf+LyFDrD6EjYxh8xoluibeOkwbd62HeCqB WmTQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=NzvzJfcXs156rFKPG8nImi8OaJ/X1keUbPQokzEoyeQ=; b=c9miXlEph7z0C2swyOqZV+W1h2dNNRRUkSt5p1TuRgOCovFm5rjlrKZWJ94btwgG3q mxAHZp+oiF7R9VQb+Pxy+IKpGOEk9NWv55yZq2ZT14ImaVUaUHu1LKGJB8XRk/XdNsaz qVbq3ImMCdBGKYyAeIHqsvY7WF8+ndNAISj+DzmjQHtPGzdFyPZb8GVeVN9NFa1tRz1k 3xdcCOKGg2igUsdiFs+fauXqdgdxs/4xyvukX/Veyi5tDYDmWCJq5/t8V0Wff1yhrh3+ swHhsqFhyGH/obqlkT7yLhm+3n9AWOZ3GK/3AXllHF+O1B/CLFgB8A+uanbayldE0zmd 4wsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=NzvzJfcXs156rFKPG8nImi8OaJ/X1keUbPQokzEoyeQ=; b=xP0D1aTkEsTOyFhVv0dd7ZSjkPYF4TLT3cjSfskspkWk62MyUEgSopFHV6C9FTFfPX CH94x4W0aFZwF+9C+NbZzeCVhIvTKgl6Tg7WIbZuXsP+imRdgpyQ9gXK0ELtQS8gM77C bzrKHEoruXWf29BeCfL28CZ5KtTxVNPmYKq09HeklkL1ABTY32x8dlo8hIA47CNP7Ft2 VEkv02S7myvHVk9rkg+ksXIGWbntgt1dQDq764+uQfMBo7EcyHWXCK8swE2FlU5l989b X1YSUnqX73mmZZQMdMSLWmp0KI8BYTcIevu4OusyHr3qw83qzDmZJt12efS8GFiPT7ar sbtA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533oNZzvJd8oxE+QXfcEAu4Xq0xkRBu/A1boLQX0DP7HdR9KGO9U CIReEulV+p/UL4MHQDWRZF4= X-Google-Smtp-Source: ABdhPJwabGfhGnEt1IviFkTLYbxfqKZ1v7INTMFpGhSFttxHfbJFpU4g/9+SrBKXaaQVaAYkOY7rWQ== X-Received: by 2002:a05:6a00:cc9:b0:49f:b439:8930 with SMTP id b9-20020a056a000cc900b0049fb4398930mr82704622pfv.86.1637550985457; Sun, 21 Nov 2021 19:16:25 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a63:e004:: with SMTP id e4ls1285833pgh.4.gmail; Sun, 21 Nov 2021 19:16:24 -0800 (PST) X-Received: by 2002:aa7:804b:0:b0:4a4:b2e2:e046 with SMTP id y11-20020aa7804b000000b004a4b2e2e046mr19919534pfm.81.1637550984781; Sun, 21 Nov 2021 19:16:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637550984; cv=none; d=google.com; s=arc-20160816; b=aXv4dgCUbFmcQTT/F+zv3uMP5Lh+h8MFzN/IG8H52qCA79pHEAKcdrKtK83NfrIV1u W9b9SJqTgOug+0qd6S4mvNIR5TteciYhJPKbiQ8EQQEW9MQwSzLzjGZgFRUzjsIUGT+B 3IhqBSLyXl5ZBa3IeGMobydG3u9Z7LNAWOGtYvOcnYfyjwn8K73Bp4TwoeOodweMzRwn yJVoIYiC5Lv2Gg4Ky+GQYhTTL1kddLFgjI398N8Y6w7CtWSY53nMqIBOjsNKG/Pj+3Dd fF6/rDA8YhCQh3luL3wUdiatXBeGq/xuZSfAZR9ZhB4wY3di/5+7n4DcKlEnDaVk+OBa iyCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=23Xy32YYan8Yf1RpJKqLP20LQJAw1CUPi5lfdZx1Oqs=; b=x+OuviVm9Zms23Izw4kiWCtij8ctmyKiaaenhzLYCvE2+4tiTgaVemG4K5LIPafmoy pglJl+x4mB7q1PoQ6nMpJCYPYIZAQC8zxHGYGgI0aSKasdft4F7K52ggiCNXBFbgXTRP NLnUyjH0yMH2LuE+Dm2c0S70Qevor4j0d01BEwWq1mGT60v2Cdut+QnHhrr7iVQA9ztg DhNde2OLSP7VaLaRsIV9ksAX2sUVGo65LD75uIDd5Ary0t2VgeRgrZ5m2tfxobuVAthY CVfLMEeZ7vChx3lUNT93HrzqaFBcyEqrd8m4xzQp+ES/D8bbOkFTQdDEyDYdM7xftOqq LwIQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id t14si304707plr.3.2021.11.21.19.16.24 for ; Sun, 21 Nov 2021 19:16:24 -0800 (PST) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id A26BE20D63 for ; Mon, 22 Nov 2021 12:16:23 +0900 (JST) Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by gw2.atmark-techno.com (Postfix) with ESMTPS id 8B39020D41 for ; Mon, 22 Nov 2021 12:16:23 +0900 (JST) Received: by mail-pf1-f200.google.com with SMTP id c131-20020a621c89000000b004a343484969so6258668pfc.3 for ; Sun, 21 Nov 2021 19:16:23 -0800 (PST) X-Received: by 2002:a17:90a:7481:: with SMTP id p1mr26924363pjk.169.1637550982608; Sun, 21 Nov 2021 19:16:22 -0800 (PST) X-Received: by 2002:a17:90a:7481:: with SMTP id p1mr26924335pjk.169.1637550982351; Sun, 21 Nov 2021 19:16:22 -0800 (PST) Received: from pc-0115 (178.101.200.35.bc.googleusercontent.com. [35.200.101.178]) by smtp.gmail.com with ESMTPSA id v10sm6787089pfu.123.2021.11.21.19.16.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Nov 2021 19:16:22 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.94.2) (envelope-from ) id 1mozob-009EyJ-2V; Mon, 22 Nov 2021 12:16:21 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH 1/4] ipc_notify_receive: add timeout_ms argument Date: Mon, 22 Nov 2021 12:16:16 +0900 Message-Id: <20211122031619.2202449-1-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com 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: , allow checking if we have a notify message pending with a timeout. Since we want timeout=0 to mean "check without waiting", also make other timeout_ms in this file logic match for coherence: - timeout < 0 = wait forever - timeout >= 0 = pass timeout to select() Since we now have 3 places in the code that basically do the same optional select, move this to its own __ipc_select_timeout helper Signed-off-by: Dominique Martinet --- The uniformisation is somewhat arbitrary, but the following patch requires a select with immediate timeout as we'll call it in between sending image in file sending loop include/network_ipc.h | 4 +- ipc/network_ipc.c | 86 ++++++++++++++++------------------- mongoose/mongoose_interface.c | 2 +- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/include/network_ipc.h b/include/network_ipc.h index 6dc2521d827f..356931bc4e5c 100644 --- a/include/network_ipc.h +++ b/include/network_ipc.h @@ -129,9 +129,9 @@ int ipc_inst_start_ext(void *priv, ssize_t size); int ipc_send_data(int connfd, char *buf, int size); void ipc_end(int connfd); int ipc_get_status(ipc_message *msg); -int ipc_get_status_timeout(ipc_message *msg, unsigned int timeout_ms); +int ipc_get_status_timeout(ipc_message *msg, int timeout_ms); int ipc_notify_connect(void); -int ipc_notify_receive(int *connfd, ipc_message *msg); +int ipc_notify_receive(int *connfd, ipc_message *msg, int timeout_ms); int ipc_postupdate(ipc_message *msg); int ipc_send_cmd(ipc_message *msg); diff --git a/ipc/network_ipc.c b/ipc/network_ipc.c index 5ccc18b6c6d4..39ca695ec75f 100644 --- a/ipc/network_ipc.c +++ b/ipc/network_ipc.c @@ -92,11 +92,32 @@ int ipc_postupdate(ipc_message *msg) { return -result; } -static int __ipc_get_status(int connfd, ipc_message *msg, unsigned int timeout_ms) -{ +static int __ipc_select_timeout(int connfd, ipc_message *msg, int timeout_ms) { fd_set fds; struct timeval tv; + if (timeout_ms < 0) + return 0; + FD_ZERO(&fds); + FD_SET(connfd, &fds); + + /* + * Invalid the message + * Caller should check it + */ + msg->magic = 0; + + tv.tv_sec = 0; + tv.tv_usec = timeout_ms * 1000; + if ((select(connfd + 1, &fds, NULL, NULL, &tv) <= 0) || + !FD_ISSET(connfd, &fds)) + return -ETIMEDOUT; + + return 0; +} + +static int __ipc_get_status(int connfd, ipc_message *msg, int timeout_ms) +{ memset(msg, 0, sizeof(*msg)); msg->magic = IPC_MAGIC; msg->type = GET_STATUS; @@ -104,22 +125,8 @@ static int __ipc_get_status(int connfd, ipc_message *msg, unsigned int timeout_m if (write(connfd, msg, sizeof(*msg)) != sizeof(*msg)) return -1; - if (timeout_ms) { - FD_ZERO(&fds); - FD_SET(connfd, &fds); - - /* - * Invalid the message - * Caller should check it - */ - msg->magic = 0; - - tv.tv_sec = 0; - tv.tv_usec = timeout_ms * 1000; - if ((select(connfd + 1, &fds, NULL, NULL, &tv) <= 0) || - !FD_ISSET(connfd, &fds)) - return -ETIMEDOUT; - } + if (__ipc_select_timeout(connfd, msg, timeout_ms)) + return -ETIMEDOUT; return -(read(connfd, msg, sizeof(*msg)) != sizeof(*msg)); } @@ -133,7 +140,7 @@ int ipc_get_status(ipc_message *msg) if (connfd < 0) return -1; - ret = __ipc_get_status(connfd, msg, 0); + ret = __ipc_get_status(connfd, msg, -1); close(connfd); return ret; @@ -144,7 +151,7 @@ int ipc_get_status(ipc_message *msg) * -1 : error * else data read */ -int ipc_get_status_timeout(ipc_message *msg, unsigned int timeout_ms) +int ipc_get_status_timeout(ipc_message *msg, int timeout_ms) { int ret; int connfd; @@ -163,11 +170,8 @@ int ipc_get_status_timeout(ipc_message *msg, unsigned int timeout_ms) return ret == 0 ? sizeof(*msg) : -1; } -static int __ipc_start_notify(int connfd, ipc_message *msg, unsigned int timeout_ms) +static int __ipc_start_notify(int connfd, ipc_message *msg, int timeout_ms) { - fd_set fds; - struct timeval tv; - memset(msg, 0, sizeof(*msg)); msg->magic = IPC_MAGIC; msg->type = NOTIFY_STREAM; @@ -175,22 +179,8 @@ static int __ipc_start_notify(int connfd, ipc_message *msg, unsigned int timeout if (write(connfd, msg, sizeof(*msg)) != sizeof(*msg)) return -1; - if (timeout_ms) { - FD_ZERO(&fds); - FD_SET(connfd, &fds); - - /* - * Invalid the message - * Caller should check it - */ - msg->magic = 0; - - tv.tv_sec = 0; - tv.tv_usec = timeout_ms * 1000; - if ((select(connfd + 1, &fds, NULL, NULL, &tv) <= 0) || - !FD_ISSET(connfd, &fds)) - return -ETIMEDOUT; - } + if (__ipc_select_timeout(connfd, msg, timeout_ms)) + return -ETIMEDOUT; return -(read(connfd, msg, sizeof(*msg)) != sizeof(*msg)); } @@ -208,7 +198,7 @@ int ipc_notify_connect(void) /* * Initialize the notify stream */ - ret = __ipc_start_notify(connfd, &msg, 0); + ret = __ipc_start_notify(connfd, &msg, -1); if (ret || msg.type != ACK) { fprintf(stdout, "Notify connection handshake failed..\n"); close(connfd); @@ -218,10 +208,14 @@ int ipc_notify_connect(void) return connfd; } -int ipc_notify_receive(int *connfd, ipc_message *msg) +int ipc_notify_receive(int *connfd, ipc_message *msg, int timeout_ms) { - int ret = read(*connfd, msg, sizeof(*msg)); + int ret; + if (__ipc_select_timeout(*connfd, msg, timeout_ms)) + return -ETIMEDOUT; + + ret = read(*connfd, msg, sizeof(*msg)); if (ret == -1 && (errno == EAGAIN || errno == EINTR)) return 0; @@ -229,14 +223,14 @@ int ipc_notify_receive(int *connfd, ipc_message *msg) fprintf(stdout, "Connection closing..\n"); close(*connfd); *connfd = -1; - return -1; + return -EIO; } if (msg->magic != IPC_MAGIC) { fprintf(stdout, "Connection closing, invalid magic...\n"); close(*connfd); *connfd = -1; - return -1; + return -EIO; } return ret; @@ -330,7 +324,7 @@ int ipc_wait_for_complete(getstatus callback) fd = prepare_ipc(); if (fd < 0) break; - ret = __ipc_get_status(fd, &message, 0); + ret = __ipc_get_status(fd, &message, -1); close(fd); if (ret < 0) { diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index 31548cccb254..16c7b3aaf828 100644 --- a/mongoose/mongoose_interface.c +++ b/mongoose/mongoose_interface.c @@ -173,7 +173,7 @@ static void *broadcast_message_thread(void *data) continue; } - ret = ipc_notify_receive(&fd, &msg); + ret = ipc_notify_receive(&fd, &msg, -1); if (ret != sizeof(msg)) return NULL; From patchwork Mon Nov 22 03:16:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1557860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=fLOPE1uX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::73b; helo=mail-qk1-x73b.google.com; envelope-from=swupdate+bncbcwivbv7sugrbcmx5sgamgqeasddlqy@googlegroups.com; receiver=) Received: from mail-qk1-x73b.google.com (mail-qk1-x73b.google.com [IPv6:2607:f8b0:4864:20::73b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyC984b4Dz9t0G for ; Mon, 22 Nov 2021 14:16:28 +1100 (AEDT) Received: by mail-qk1-x73b.google.com with SMTP id h8-20020a05620a284800b0045ec745583csf13814061qkp.6 for ; Sun, 21 Nov 2021 19:16:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1637550986; cv=pass; d=google.com; s=arc-20160816; b=qBbWui5Nli7GgthGr43D9ifKvkUQOaLuEPp3Rhw8LpxLoD7RYBgQxmGpnp6AtsABFH 8VJtaj4Pjz0EucWIyqHewyCcG6PVrEwWQITCHo1JB23/FqlrJSYVcSx8uEq6FEFloR1f RkFc+UTKN0Pwi2cNOEw0J/Aqptif3UvgEoCtz0AXvoNU2gU4dYcnpPWM4VUJHMblw80Y 5YAcdqJ01Uy7XeOZu93iXfiBrQu1cfrwnJqYF3PCvKWlTonoWPoNkIubcDSga/AQAevT rAgq2eOM58/8S0KHN5tNzw/Sk/9vRnBOFof4kiRSBhrx9b8zzgpKXI7FltdxaqIhDjZ4 md/w== 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:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=0FEUKYkymnTFZzY9OfeLg+jKW4AbnP2TnUEu2OaCaoc=; b=qYpObzZ3MWFJ9qpbedb1OXPA+CeRkPwIYEfk+vkxUT5dRWu12wXR2OpANnAiA8/p46 G0UN2wJFiq8Yk2rsc4tDPoZM7IYWmLrDHW3uTqqdVxFAjhkzprHkIS2jrLjM0ofZYL+d IKH99jzKjR58eLnhUumXJgiQ3RSyebXYvXRfziJS0jceCR3RuL/aGB/G+/ZcTJW5lcJc THBKBrKh24AmqbhtAn7fjRQy+PJKFf781o2ZMcDq7UVMvZEgQGsgzDxdIjuc1fDr2IPO NLZ5QfOG3VtvikCNsxZ3JGzp3/7aX9yr6EDHyI1KOkpLoZo3JWmfbsQayiNul/d3wc0d CZkw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0FEUKYkymnTFZzY9OfeLg+jKW4AbnP2TnUEu2OaCaoc=; b=fLOPE1uXZNE3UaYUgLvg0AaMkoJc2UuU0XRa/Ro7LUtzAerWCEYYgDjRtguHyLpp1I MqLwM9kTKtyzZMrSvWdlCG3mve/ikznA4Bj7M/dRDIsZHBSnav6HS3rtfpqES/x/YzPM zJFy4i/M7YNFAK5sD/jhuVNvG+p7KhQlNONH//bETRnuWfZCTOIIVLnl6J6oipIYZPon fN7/CRuW93zJfIIoa5Xe4bbYyskO/dztfaO5RuKo+6xo/CX1bYftyVQryoimD6naJH8+ twdGPErhfbvh+jMzItfCcXGfETz0HnVv8rYtgfw/KL2dCSBlobEgNutG9cjX5ZSlT4U+ 5YNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0FEUKYkymnTFZzY9OfeLg+jKW4AbnP2TnUEu2OaCaoc=; b=pzKMmQu+0CK8qetFEKd34NkH7T2FXtnhuVlrFqZyVtF3yI5fcXSef5sAViENLpaKrG GlK8rALuvv8iyzWah8Lkn8YbKKZdb9wdkwJxkUq45W4UFcib01192Xcfhwga0Ovw7a+7 ZzztWX/thyspyNYVLOrl7CVbROVinsoUOVUIJ7y8WSuVKwSPG42nvuq8vMZX9hlkNut7 A+LCvamsd3U5sf3dGeJZJfPbXU1ItV9WnMzQERg5MZ5dkiwt8SUlY3hxWN5mkpHFTdzB z7ov1+XT9ek4THfu/cufW4+IYhEBg5rqJe82x0tHwp2uXcXN6JHcT8qTZ+RXjcFG9RyU yV1A== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM530aiVhOgMNgknwiuj7bJlyCOmealhj4Qsw4kbkRH47I2i8fVfgN yTsvCgXNrO86hrsQkqxGfxo= X-Google-Smtp-Source: ABdhPJw8qpC3RaRLR/SpgAlXeYWWJwgHs0JKdtV3Pri9QMs5gbr3GoGPVMAruDYuDZgAwvQnB7SHiA== X-Received: by 2002:a05:620a:454d:: with SMTP id u13mr45311654qkp.221.1637550985845; Sun, 21 Nov 2021 19:16:25 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:620a:bca:: with SMTP id s10ls3379128qki.1.gmail; Sun, 21 Nov 2021 19:16:25 -0800 (PST) X-Received: by 2002:a05:620a:1a9d:: with SMTP id bl29mr25618394qkb.55.1637550985525; Sun, 21 Nov 2021 19:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637550985; cv=none; d=google.com; s=arc-20160816; b=RjzOjeYifg4EXfuDXcYPailQv/IUSreVIjkAlOZxKKrxO+nO574G2z7tZbp8zqok0G dhpq91fcNqgiYku1prDcRzAbj1DBwDpD9zRqKWHkcx18Ba2BgPvu7rHOO7N2/8bUboUD 74bJ9JyOEq4+fc7YVGcizK8Z+yhUo3C1WQgkdKdmRYtRZuvilfJveLb5KbX5eRx8H729 pTKyfQx0dAosKI5ChN6G8iiui118R55Gu4wwPYR7Tq6KPZlNJVREec3mVd0F7CJ/vfx6 Io2oRI5UGJZv8UgQ3foucsoLYWPkJFC+XtB5HEDFqJZN3fHPXJUU2shPcvJk9J2m92HK z/Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=MYhcqAlpHigmPPGAq4e29JtAshG2Q1p/J8MCW0JZt/I=; b=owMzcZ+OShBwL2Clc3yZULfuCsLu5XT6qFn2MfhBd069t+GW0gyEN60qCeMIYhokld 4DesgZplCgetcGN/3jbD+NBohwlI4h8mBtYEivZ05/sbmPuNvJt6DtUFv+c8PfAhojCI 51Opz1Helfu3Azxu0xjgow4rRJGfvYQMMvmAFu6tCi+G/IPTJSBie1xdefSHo3LL2/o2 +zRvxuTIKTpgswfePDpDrOnTDsafsrk/9MbV9bbMdGoScoONbJfqyCkwRfz/LuiqD98q OYPuVJVSLglYhunVG8SsMJWRz2Wp0EZhgKcRB1yrorNUWHL/5G+12ShrWWROsh+qo+KD WK4Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id w22si773011qkp.2.2021.11.21.19.16.25 for ; Sun, 21 Nov 2021 19:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id 012F020D65 for ; Mon, 22 Nov 2021 12:16:24 +0900 (JST) Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by gw2.atmark-techno.com (Postfix) with ESMTPS id D30C720D65 for ; Mon, 22 Nov 2021 12:16:23 +0900 (JST) Received: by mail-pj1-f72.google.com with SMTP id lj10-20020a17090b344a00b001a653d07ad8so11196629pjb.3 for ; Sun, 21 Nov 2021 19:16:23 -0800 (PST) X-Received: by 2002:a05:6a00:24cd:b0:49f:bf3f:c42c with SMTP id d13-20020a056a0024cd00b0049fbf3fc42cmr41105139pfv.54.1637550982938; Sun, 21 Nov 2021 19:16:22 -0800 (PST) X-Received: by 2002:a05:6a00:24cd:b0:49f:bf3f:c42c with SMTP id d13-20020a056a0024cd00b0049fbf3fc42cmr41105120pfv.54.1637550982722; Sun, 21 Nov 2021 19:16:22 -0800 (PST) Received: from pc-0115 (178.101.200.35.bc.googleusercontent.com. [35.200.101.178]) by smtp.gmail.com with ESMTPSA id e13sm4720510pgi.90.2021.11.21.19.16.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Nov 2021 19:16:22 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.94.2) (envelope-from ) id 1mozob-009EyS-GI; Mon, 22 Nov 2021 12:16:21 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH 2/4] ipc_notify_connect: fix return 0 when message was not acked Date: Mon, 22 Nov 2021 12:16:17 +0900 Message-Id: <20211122031619.2202449-2-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122031619.2202449-1-dominique.martinet@atmark-techno.com> References: <20211122031619.2202449-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com 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: , It's possible to return 'ret' if ret == 0 and msg.type != ACK, but that is an error as ret >= 0 values could be a valid connfd (note ret > 0 is not possible in the current code, but it doesn't hurt to check >= 0 instead of == 0) Signed-off-by: Dominique Martinet --- This is an unrelated fix as I was looking at the code, purely code-inspection level. ipc/network_ipc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ipc/network_ipc.c b/ipc/network_ipc.c index 39ca695ec75f..886af0ac2916 100644 --- a/ipc/network_ipc.c +++ b/ipc/network_ipc.c @@ -202,6 +202,8 @@ int ipc_notify_connect(void) if (ret || msg.type != ACK) { fprintf(stdout, "Notify connection handshake failed..\n"); close(connfd); + if (ret >= 0) + ret = -EIO; return ret; } From patchwork Mon Nov 22 03:16:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1557859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=F970IkRe; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::1039; helo=mail-pj1-x1039.google.com; envelope-from=swupdate+bncbcwivbv7sugrbcux5sgamgqeqrj746i@googlegroups.com; receiver=) Received: from mail-pj1-x1039.google.com (mail-pj1-x1039.google.com [IPv6:2607:f8b0:4864:20::1039]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyC983r0Zz9t1Q for ; Mon, 22 Nov 2021 14:16:28 +1100 (AEDT) Received: by mail-pj1-x1039.google.com with SMTP id pg9-20020a17090b1e0900b001a689204b52sf11213730pjb.0 for ; Sun, 21 Nov 2021 19:16:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1637550986; cv=pass; d=google.com; s=arc-20160816; b=q12zd0kcMyWiEn4eIC0ApopIhMWjd/sFD7H68nmW8mv9bjV9tTLryixe9urQADT2QH ikjoL7afxoQ9wCQgC1vpOiH4Xg56iGvJjRQgA4QB2OBfwIDN5NufQmQDSUh3yH9XGVQH tSWnj2GbyTKtjrd2SMArDEqLPxJ65vFYKamSzm5h/Qg0s02ZONViz/7MqcOzCSTButv5 APoCuKzvvqwCOV5rK4m0+n3c00dweQjoweFr4nTeJ/OIlZHrphRh0FYTIF+tPF91nWNy LZk57sAxFnmEjmUS7MhvIyiHJZyIiyH9SW6IXEcQPQ3PUf0h+8XRXaRYMzb1isO2lOM0 5Ltw== 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:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=0Wc5H0iib98eY3T0iLGLwX4mzMOUjOtTbe9YSsnLhpg=; b=RX6M5lqPyi+lwJG85OWN4+Tm6/W3QvNN3LD5Hq+0WFgWJIKn8787aiBZmqm87AMkKb 9vCGU0y3SFSf/689+4yL3GZuzGV4mqXbeEVbIByqxrU+H+aNuKFARUZ1HYKb91PHjGX2 3BkS/PjDLKWw9rHo8bXzLc6tsz1/w40yuPg01+SypN40iG63qKsC3JUpzFB6SD9BMuFR 2/b9hqtEODVc0LMGwX3HEdxbUdBL/YDoKa7QH2biqlun1Ro3lAV9GG3EvwJuNHJnarWN mphkWNViK6oslILiaioUtrFPzJh0XIOkAFhFQ2iSfAkI6ak2YFpj7kLdaH3t+A5rv+RV swXQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0Wc5H0iib98eY3T0iLGLwX4mzMOUjOtTbe9YSsnLhpg=; b=F970IkReJTEj5dikaFTOruhFgSUOZKFvLcywlyMlB06OPYpBds54vx8FNzFeFDvAbH CKNyOPjsa4IpyZIoDF8b+HbUIn3MWLAJMJrJ9A5zbgOMlC4+rQKsdJH4sZsaz4QLMkyW 7R6WQ4HmHv6RBhJ+U7q8ogYnIEjmmDvA65LECqVwOca8i7cSWD56WF+BVn3UfL0JymSh 2C3BDSL2ZYASiT2bPp8Ab2fuubKC4fz59edSOoOE6EBl6HHBhr31nGaRoNal6OwJEt7K wTxrg8TqbUv4Phwzad0lZlYe2sZPypSKiLBeWQxmuSQNFScwnS9Fg5tzfg+LWXIOy/aF hOwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0Wc5H0iib98eY3T0iLGLwX4mzMOUjOtTbe9YSsnLhpg=; b=0W2dCtITZRPTcQha8PLf0nxLHpjyR8hhafQ4yMMvngyI8UrDO3zhnDa5Bp4Z19hGLb CVRWuobjioJvxfw20tEcc1Cp7AZaUWEEDnncbIq7XlgMzSu3uVjVSRBqDiihNdJNR3yL U/1F2ZLjEtttpN0bdYSyItUw3TnzBMlGozvIfRWu0IFraKcKJQU8PubdIresqhQyw7Z7 g3yWwH5TaY4dp6qfncnDhn4Fgsv7gepz4uWevWH4ZBFG3rJCywRvr93bhdWdDEvadlAW ETCYZN4RZWnVIqu5L6skbuqWG0JSWuRfjqI/03Am52q8W14FLPITKqmwbN9Z5xi+7Hic +xAA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531LyywoEYlbajWUrWDSEIoLnefrJkeSZFONVEvslbLZj+t3fzPS JyLKZtclEtqtM8Gr6l9eaqs= X-Google-Smtp-Source: ABdhPJxRIugIitPq1lu0EZMydiKkPOPslMgmb1kM3envfIcieFovuBUnMA6mha367LWVnTFyE0gKxA== X-Received: by 2002:a17:90b:30e:: with SMTP id ay14mr26145751pjb.60.1637550986323; Sun, 21 Nov 2021 19:16:26 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:90b:3ece:: with SMTP id rm14ls9538807pjb.2.canary-gmail; Sun, 21 Nov 2021 19:16:25 -0800 (PST) X-Received: by 2002:a17:902:768b:b0:144:e570:c7d2 with SMTP id m11-20020a170902768b00b00144e570c7d2mr34815889pll.86.1637550985692; Sun, 21 Nov 2021 19:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637550985; cv=none; d=google.com; s=arc-20160816; b=M/aOtJipgY01Pc5k26LsDJUai6RdxGVYdjR0ZwIfFuPkcBL26VdvuEExTth6Yptmkp r9P6ymflPGrSkUkM1p6F72LBtZxD5BgyovNS6sBG1doCCLat6i6SZPiYeX54ckfs2G7R d/7dkwyoVie2zl36Oi/DzD8hdLfNG2sUrERgMlYeQilzch1V26cOfv4eWcHnuOQU/rKv ivbbVqgBrzseSraVLw/Fpun6DuYKwf+g9MblQci4W1o0sCpaczbycSX9fo73b4BHHMaG 9p2SiJCJCargqUiWljAYu48bHveJ/3zeFqysfx+d84hLmAWF2Sn2STE44yMNq5JDy6Vj 2RHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=sK6lII9fyXJgFDVreoa7D8dsGOLFCv7vVbX/wXm6bFw=; b=FgiW7vZ3uzLsi7bnP5d83OfJn7rWERiT2fgvceZ02vhB5cBmKvoXRDllTL40axsUrU lx31SKwM8eX9Osqdf9/Jr5RQrrZsWFiF7dJgqGNSzWyaNO2eOYpyYr46qtokJfWHDr3Q 5PFD0pq1cu7LYcgxEkU/VWHhmxG88HMqBuKrGeA/g8iTmksdLFrKAoQSZfaHq6fer9f2 GAYOflfi8TZ6ImpPI7Uwnzt48pUEdNmW8j3Uojvuz6irgSZX3OSlRxwUt+bryF7nC9/r Cb/aNMf6h5E1dLt0FVNlctkkZeLyvObVK1GrPg5s4vTuM6V1cJFul7TmuDXBo5yiCoz1 91jg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id f6si290606pgh.2.2021.11.21.19.16.25 for ; Sun, 21 Nov 2021 19:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id 8C84E20D67 for ; Mon, 22 Nov 2021 12:16:24 +0900 (JST) Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by gw2.atmark-techno.com (Postfix) with ESMTPS id 6BCDF20D67 for ; Mon, 22 Nov 2021 12:16:24 +0900 (JST) Received: by mail-pf1-f198.google.com with SMTP id a23-20020a62bd17000000b004a3f6892612so5183102pff.22 for ; Sun, 21 Nov 2021 19:16:24 -0800 (PST) X-Received: by 2002:a17:90a:134f:: with SMTP id y15mr26310399pjf.158.1637550983439; Sun, 21 Nov 2021 19:16:23 -0800 (PST) X-Received: by 2002:a17:90a:134f:: with SMTP id y15mr26310363pjf.158.1637550983176; Sun, 21 Nov 2021 19:16:23 -0800 (PST) Received: from pc-0115 (35.112.198.104.bc.googleusercontent.com. [104.198.112.35]) by smtp.gmail.com with ESMTPSA id j18sm4664275pgi.39.2021.11.21.19.16.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Nov 2021 19:16:22 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.94.2) (envelope-from ) id 1mozob-009EyV-UP; Mon, 22 Nov 2021 12:16:21 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH 3/4] network_ipc: update swupdate_async_thread to use notify Date: Mon, 22 Nov 2021 12:16:18 +0900 Message-Id: <20211122031619.2202449-3-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122031619.2202449-1-dominique.martinet@atmark-techno.com> References: <20211122031619.2202449-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com 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: , The former mechanism of sending update then checking for ipc_wait_for_complete is inherently racy: it is possible the update has not started yet when ipc_wait_for_complete sends the first STATUS request, so it is possible the update is considered over before it actually is. Instead of periodically check for status, use the newer notify mechanism to receive updates as they happen: - register a notify socket - send update image while checking that socket does not fill up - wait for notify to come back to IDLE state - if required, query status after all is done to get install result (Bonus: we no longer rely on sleep(1) so test scripts installing small updates in a loop now run much faster) Signed-off-by: Dominique Martinet --- This is the v2 of 'ipc_wait_for_complete: wait a bit if the first status we get was IDLE' from Friday: instead of fiddling with the wait time, use the progress interface as you suggested. I've tested this with the two users of swupdate_async_start() we have: swupdate -i swupdate-client with another swupdate process in the background In both case the exit status still correctly reflects a successful or failed update, and messages from swupdate-client (rq->get callback) are mostly identical to the previous version (mostly because there seems to be an extra blank line with the old code, I'm not sure where it came from... But all non-empty messages are there) FWIW I couldn't get -d to hit this race, so I haven't touched that part of the code. ipc/network_ipc-if.c | 59 ++++++++++++++++++++++++++++++++--------- tools/swupdate-client.c | 4 +-- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/ipc/network_ipc-if.c b/ipc/network_ipc-if.c index fc5419ccaa38..90c49709b0fb 100644 --- a/ipc/network_ipc-if.c +++ b/ipc/network_ipc-if.c @@ -37,17 +37,25 @@ static void *swupdate_async_thread(void *data) sigset_t saved_mask; struct timespec zerotime = {0, 0}; struct async_lib *rq = (struct async_lib *)data; - int swupdate_result; + int notify_fd, ret; + ipc_message msg; + msg.data.notify.status = RUN; sigemptyset(&sigpipe_mask); sigaddset(&sigpipe_mask, SIGPIPE); if (pthread_sigmask(SIG_BLOCK, &sigpipe_mask, &saved_mask) == -1) { - perror("pthread_sigmask"); - exit(1); + perror("pthread_sigmask"); + exit(1); } - /* Start writing the image until end */ + notify_fd = ipc_notify_connect(); + if (notify_fd < 0) { + perror("could not setup notify fd"); + exit(1); + } + + /* Start writing the image until end */ do { if (!rq->wr) break; @@ -55,17 +63,32 @@ static void *swupdate_async_thread(void *data) rq->wr(&pbuf, &size); if (size) swupdate_image_write(pbuf, size); + + /* handle any notification coming */ + while ((ret = ipc_notify_receive(¬ify_fd, &msg, 0)) + != -ETIMEDOUT) { + if (ret < 0) { + perror("ipc_notify receive failed"); + exit(1); + } + if (rq->get) + rq->get(&msg); + } } while(size > 0); ipc_end(rq->connfd); - /* - * Everything sent, ask for status - */ - - swupdate_result = ipc_wait_for_complete(rq->get); - - handle = 0; + /* Everything sent, wait until we are IDLE again */ + while (msg.data.notify.status != IDLE) { + ret = ipc_notify_receive(¬ify_fd, &msg, -1); + if (ret < 0) { + perror("ipc_notify receive failed"); + exit(1); + } + if (rq->get) + rq->get(&msg); + } + ipc_end(notify_fd); if (sigtimedwait(&sigpipe_mask, 0, &zerotime) == -1) { // currently ignored @@ -75,8 +98,18 @@ static void *swupdate_async_thread(void *data) perror("pthread_sigmask"); } - if (rq->end) - rq->end((RECOVERY_STATUS)swupdate_result); + if (rq->end) { + /* Get status to get update return code */ + ret = ipc_get_status(&msg); + if (ret < 0) { + perror("ipc_get_status failed"); + exit(1); + } + + rq->end(msg.data.status.last_result); + } + + handle = 0; pthread_exit(NULL); } diff --git a/tools/swupdate-client.c b/tools/swupdate-client.c index 22e55de3794d..c545fa43fe89 100644 --- a/tools/swupdate-client.c +++ b/tools/swupdate-client.c @@ -85,8 +85,8 @@ static int printstatus(ipc_message *msg) { if (verbose) fprintf(stdout, "Status: %d message: %s\n", - msg->data.status.current, - strlen(msg->data.status.desc) > 0 ? msg->data.status.desc : ""); + msg->data.notify.status, + msg->data.notify.msg); return 0; } From patchwork Mon Nov 22 03:16:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1557861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=nnlJC1kt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::23f; helo=mail-oi1-x23f.google.com; envelope-from=swupdate+bncbcwivbv7sugrbcux5sgamgqeqrj746i@googlegroups.com; receiver=) Received: from mail-oi1-x23f.google.com (mail-oi1-x23f.google.com [IPv6:2607:f8b0:4864:20::23f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyC992jx8z9t0G for ; Mon, 22 Nov 2021 14:16:28 +1100 (AEDT) Received: by mail-oi1-x23f.google.com with SMTP id y20-20020acaaf14000000b002a817a23a1esf11756410oie.23 for ; Sun, 21 Nov 2021 19:16:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1637550986; cv=pass; d=google.com; s=arc-20160816; b=jVkRoGWfzV8wEX3y/yKyo9eiXkArnzx/BiHzA/Xamjgu3IOEUcqtn0aCewASG6cZdj QLf4W/GixPsKXbe6jcjgLIES0W+CgrNvvrqOi9YdFyWViOS6/OVUZmoIspAgk0/5oG3K VIZgIDM+DMQNqzN9Uw4oyaR89qkG04f6DGs4CUQsETftopoIXP4I4R6Khg1rsP/HMGuY Z2cxvEBqC6lWUwSs2J/3nOMkw3ihFsXrw1h7jdwNmqH332+Nu+FPoNHnmSqaLIlqYC86 2e9vuKkwCJpq2ZCjZh9nA9yMfSJxrAg5i4YfJbk0hpoqFLZMNoYIjs9YgSMyBwTdPHhS 91Ow== 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:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=m+HowwBfplmaZ61AySPJXo9BuI7GeZlCxjl955kQ8sk=; b=yvHHzOdXVy2t7QvkGqoiaZxA+632nzhNRR6l+zUyxl2MEAc7wDcwcydgDB56fqNA6+ NqTI6nuuhFQFMdsw9udF3aWkz2N3+v26dQV/3S/ix0uxRlw6w6f9eGAaSBNzEAyLCnJw OzUyHuIAqQ6uczW5p3kjJdN1kl8Oc0clyQGi8KQr7XqSyrqfuTGusiK2L1gBquHOm3ip VXk+M59BMHsaSr7WWRV9jV20iFuAaPw5RcVLLW64WjbzqBTS9LKUQHsSDH9tWnY3pzJv byuprb30qqA7px5iFo2x9K3uGdnucDIKTWpDNkwvfv3lEy/WrWya2t03gS6DQF21SH0O /vKg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=m+HowwBfplmaZ61AySPJXo9BuI7GeZlCxjl955kQ8sk=; b=nnlJC1ktjYGWWt1J65PjPvPAPxZkyYKUUr7uSpTdkARQOOWX+/nGEyIUxGTX9bfq9a aKClabyJ9Co6PHh6zxFVPHX9NN+RXmDg3IwVS/zFdcDjN8Q85hUzmxUtG1mbnUYTNTfg 1fccbkvZwjGxOPRbCnQfonpYW47C5nk2npb5hwmG+jnsIJojuoiMPiKSEYFlmhidSB/k vR+n6ZT/9qu8sdbQQr83DOArYxbesCNvzzQKoZDnkKWhmXuLso4vZs4qHf9dooAkmrii E6TAS61PcemaNNUYyZTzLc6YLMzTlmyYG+3DwcfZX6zKt6ZKJJrG1fouBTUJfPmQGL3+ cUlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=m+HowwBfplmaZ61AySPJXo9BuI7GeZlCxjl955kQ8sk=; b=uwS8pujhvBylXtE1NaUO8bMZVjOuVTBnvSObMMgzFdiQclVx/42SocfHatBQ42+t6t OXH43IK6wMVwJ3mj1l/ET9ESGw575lQWwkj5y8AccjyV/7Y7gniYVKCc5rtHyd6dbJyW rJbVgBm2qthyc20+hfBpbFA/i1XoKM6E5pIbXyJbi8LN+HSsjx7tqi4OIwNNUKe89gZ4 OlDCo/MQuUjFV6plpFhZEJRdiJWc2MXd6VLW04DPTuq1jCVKvTKcl8xn/vo3/fes9dN/ VrXC0am6hQ/zbF334nP+8qxkVD/1vsXkfAgpO45X/DHS2LfmY3eTeN/GwBIvgRN9YyP5 qXnw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533I0egrQK8wHQWmRMXvS0VZm3cfGHrTphO3KC6y0wfwMTqEgSBU cvgtpvAqO+6HJHuATqayxXY= X-Google-Smtp-Source: ABdhPJxzIrfFNcn/c62/HQC9gxPwPR449nJsXDVVRLedIk+GRUNUe8SxcWc4sSs0WJVPJzevwSVexQ== X-Received: by 2002:a05:6808:11c1:: with SMTP id p1mr6769531oiv.113.1637550986735; Sun, 21 Nov 2021 19:16:26 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6808:19a5:: with SMTP id bj37ls2274780oib.0.gmail; Sun, 21 Nov 2021 19:16:26 -0800 (PST) X-Received: by 2002:a05:6808:1396:: with SMTP id c22mr18988720oiw.59.1637550986316; Sun, 21 Nov 2021 19:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637550986; cv=none; d=google.com; s=arc-20160816; b=MAC/FSpwFYlBtFJ4fdooao3jyshEzJa9ime4h8tGlTyMNPYrwZsayqdJcgmUO8jYDa ExHnYZVfvi8owy8I6Ce6/HJH4MNYR8+ac2t3ZSJUOdsGXpts0Y8CTQeu6FW95OhQhN34 +sQ7UVF+BNQgeEdyoMTUH8wDHTzOjeYNKvvxy2iatangk/Y5gqM55MNKq+fRD/lSy6Fv cPwZyeqcSQEki7reUUh8yH0TDssCpyYxm6Ts357EfX8lvsVz4rhAucZnxM5wy+VzjqHW IxrKQmO/zxMtO7PENcpQK9p/ORvhkueGhZZyoDumYPIKZ8nuu7+mSfDDuHPNA4Hoct26 GeLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=oR6X/TPwuobwhPH6iXYxg00HxDCMbIInTnp1K0Oxkm0=; b=t68MYfBihkYMWZi/L7PAkdmRpSYpPAfAC3A1v+GrEp3Htk190oFhBLA+LHkJB9aLiv cO2CLBWj9IT6cQ36wXmC9ra2MdvnjCmQklpMSu6ParwGh0HTawLCQJSqpLZGrMap4+I8 5laf7f20fFA33mBKA1oHJV9aCN47pP+xGqHfNzkTc0r3PUsCB5/G7EdPTvg5cGNaKdkI Ew9dnSixl7WOyMCakdXM1VKzR4Nt/g/JNGzrHeeyKA5IjDHMruniEk060HrYkEJsgwqJ hTMknvxUE3ijv0xhGoPy+z6eq1Lgh2KvO0u6KGM1g7F80b17vpbUTKtw6TK4HISXyZL2 AV/g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id be25si797467oib.3.2021.11.21.19.16.26 for ; Sun, 21 Nov 2021 19:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id DBC4020D68 for ; Mon, 22 Nov 2021 12:16:24 +0900 (JST) Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by gw2.atmark-techno.com (Postfix) with ESMTPS id BA36320D41 for ; Mon, 22 Nov 2021 12:16:24 +0900 (JST) Received: by mail-pj1-f70.google.com with SMTP id x1-20020a17090a294100b001a6e7ba6b4eso8156310pjf.9 for ; Sun, 21 Nov 2021 19:16:24 -0800 (PST) X-Received: by 2002:a17:90a:8049:: with SMTP id e9mr26146892pjw.229.1637550983820; Sun, 21 Nov 2021 19:16:23 -0800 (PST) X-Received: by 2002:a17:90a:8049:: with SMTP id e9mr26146857pjw.229.1637550983593; Sun, 21 Nov 2021 19:16:23 -0800 (PST) Received: from pc-0115 (35.112.198.104.bc.googleusercontent.com. [104.198.112.35]) by smtp.gmail.com with ESMTPSA id y18sm4660701pgh.18.2021.11.21.19.16.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Nov 2021 19:16:23 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.94.2) (envelope-from ) id 1mozoc-009Eye-9t; Mon, 22 Nov 2021 12:16:22 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH 4/4] write_notify_msg: silence status client disappearing messages Date: Mon, 22 Nov 2021 12:16:19 +0900 Message-Id: <20211122031619.2202449-4-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122031619.2202449-1-dominique.martinet@atmark-techno.com> References: <20211122031619.2202449-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com 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: , There is currently no IPC message to signal we are going to quit, so there status disappearing messages will always appear and do not bring useful information. A better fix would be to add a new message type NOTIFY_STREAM_END or similar to unregister the stream before closing, but it does not add much value over what we currently do Signed-off-by: Dominique Martinet --- Since the previous patch registers a notify thread for swupdate-client, calling swupdate-client would always print this warning on main process. core/network_thread.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/network_thread.c b/core/network_thread.c index 27e8fd8d703f..c16775d37763 100644 --- a/core/network_thread.c +++ b/core/network_thread.c @@ -141,8 +141,6 @@ static int write_notify_msg(ipc_message *msg, int sockfd) */ if (n == 0) { fprintf(stderr, "Error: A status client is not responding, removing it.\n"); - } else { - fprintf(stderr, "A status client disappeared, removing it: %s\n", strerror(errno)); } ret = -1; break;