From patchwork Thu Dec 9 01:06:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1565558 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=ZKsaP2w5; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::538; helo=mail-pg1-x538.google.com; envelope-from=swupdate+bncbcwivbv7sugrbpfnywgqmgqeuuudkea@googlegroups.com; receiver=) Received: from mail-pg1-x538.google.com (mail-pg1-x538.google.com [IPv6:2607:f8b0:4864:20::538]) (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 4J8bV84VjVz9t54 for ; Thu, 9 Dec 2021 12:07:11 +1100 (AEDT) Received: by mail-pg1-x538.google.com with SMTP id j3-20020a634a43000000b00325af3ab5f0sf2266384pgl.11 for ; Wed, 08 Dec 2021 17:07:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1639012029; cv=pass; d=google.com; s=arc-20160816; b=a73eVfjjx11029ddq5aP1cFs6/uh55HgWbYH9PfpYuNfXFnLHJ7wvxn4Rdf6PyW0Ha bkz7Yri612rLa7ffpoer+fPw8Qw/LH8LbvL7nsErvv2tYWXz5rdjThpAJeIVJ4OEoVZT 6QYFrgTOrknK/0ORXP4hrwKScY0e/gQlUia72peYVXHnboV+4746I56wvM0WSu/HoqVy QnPpyuD8dtdNLeW1kHngPY2cCOA6XWnNOceIbWbRV5RrWIde53BdHQRhOGj/aRYuPURZ blDxvzTjY/ivTO0GBSwKUkIXKxzvTAxGZngBQDzdE9g+Gai4T1/BKdFDAcN4b2pMzAsI NHdg== 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=1IIuqjwfP4FH9nQrHAdFVrsEKdR+BFhNFJMxTR5gc3U=; b=mMfspyAanCNbI9T/2/THNml8IkpGlrLVjpIG2BtbFveSvl5Wy1tNM3QjaA3sTLf8Mm kwpyaZloLqGTjwUX7Rx7B5uKKG2p0G4u9FTL7MQE+F2bPXkm+cTBUDMnEJ9lpZ+Bjh08 0q98mN3i6sRWMEOHtBqP6+6ZhgzXvCkvC21oTCp3GerBe4PhmpKOWqTq5Yek4ALktMob hrOZlPy7vOvHaQ9ARwj+w898SBwkr+nFOHi6EvfHXP5LT1A2NiKp3aS7txak+BbUwt3r ise83ghkms8otRyl6bznZ/ERGdmOJVZaxe10tLt+nRU25i5NeGuXMEn0h1U4n7anNfBS ZL1w== 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=1IIuqjwfP4FH9nQrHAdFVrsEKdR+BFhNFJMxTR5gc3U=; b=ZKsaP2w51WaIakV1yXOBW3Ba0ZAAwJv8KXNhyd0YZZjjfqg7E0BpdnqOfdOaKLLnQp 0rN3FxN5F/qTM+0v/17jepHcy0zLmSJO5L5p4o1fhTLM5i2RxRfyn92m8W3ppfErvD0C kgFVlkHdQKgLVofE6xaF4PhgYzkUyiMoqT8qjb09topoVfgPNzIRnfDPppCMRYd2SwzY FtGrt2MuA+DTPhMggm5R34VwjkPp7gFOB1Crd0GVpvLKLADwWpBy4BYfdjNfAEnj1dx+ NbCwXdRjUoLO/PWGQPxSaC72Jtsq6wR7l16752BYB0XxTntuKF+2rIrI/nFup3YYZPPQ P11g== 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=1IIuqjwfP4FH9nQrHAdFVrsEKdR+BFhNFJMxTR5gc3U=; b=iWTJNIOL6qFrikzVqa9RmVi1fyS0+rb6Nd+EPpKgP4Y0mQZF7PbQgZYBeXuUapFXET yrMtchjhOwtfwbdqKIe0Gzd1+7pEmEK5pDzHORrxV+34dYuaIKjwNvx9RYvO8IQKjiyX 0oFej0KHyD0I7ENv7I6pt2nOmfH9FFApqaEgSrbpeOdrhY2IuCwz8BPagwmAbWdje67u u9fmG0/1gHvSicGZoeECMnRBBHRpTrp8lEayNrIlpg3QWtW3Z6irNyayy4l22jeh+31I 9vKX75s++HZVe3qHbao1GRHoZXNscs+JVGMZHf0fKCs6kkxg8wPi/GoNuw1RZ2Mo7+RG 5siw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532bff5bu7MX/fO7GmtGbdA7WauP3Yy+eGvlquqINJwcaNpAkvES TvSNpUpcazOPmtVpCjq8T6Q= X-Google-Smtp-Source: ABdhPJzVYzpYGCyR3YtzPpUAtf3k5j9l6AQ+fmSCVOCaE/sGo8yetbl9W6ACcn9dDU00W1PDRUYFXw== X-Received: by 2002:a17:90b:1643:: with SMTP id il3mr11485182pjb.182.1639012029180; Wed, 08 Dec 2021 17:07:09 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:902:e749:: with SMTP id p9ls2089686plf.6.gmail; Wed, 08 Dec 2021 17:07:08 -0800 (PST) X-Received: by 2002:a17:903:1103:b0:143:a593:dc41 with SMTP id n3-20020a170903110300b00143a593dc41mr64653548plh.5.1639012028415; Wed, 08 Dec 2021 17:07:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639012028; cv=none; d=google.com; s=arc-20160816; b=v46XAbPRx+JG5rxhCJ4Ey4bS4Ekubfcl3+YJNVxGGFE2TR18HsDcs0RWmdvtU9eBcd asSarzFCgaOcKqTj/iqeWVUw/S3LSXp/NnGJqu2O2PJKCviv8zRLdv9zD6C6KmoNSfrk FGGQfk8sbh9eKn/Dqn6Fx6FV29ZFlYUsri06oWfzBW8ISITU58rmtE7y9bIjVzxqCgs7 /+3dV5Dhvroi7WMvAMiK9phiCD443eBnvjBxdPGn9IQKamXKSqHX19LYcaYmvLAbZiRY vt3k/t0Wh7Aodw32YUvaPvI5Rb92IRVodejpRayA9E8yWj+kvrxnd3M8O9gGuyMl7mCt SNcw== 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=rgX8DPnIovz5UGGJF0kh3oJnGtmiS3d0eegvtewqQhc=; b=1C4/VCe69/MkbfFpsE0FnfyW7nNVK9b4OvFsdvn5AMWxAjz4bQ5C1+0AY9HYvkz8qf 9u/zV5Ux9Pnsz0bxHNVSvFg1DGSiDxOYHRSCZMyc0Gz/EjVeaD9y2cLhyXBC+GbnSH3V JEqr0AObiiJjZkBsOhR3HzfwWfTNnv6Yf1Nj9RA9Zag/IAquQD0BZjOCm8nw9K2DgDAV kKruiojIHjdx8WbFKr4nWafziznZe4DA2OSejB0ySN60Ay8ZsY/UGi6U8tP6db7pOAOx LZyxaK1tHG1QlR6wiFAwJimIWJQNhFp/dzdzMMDBd19ORA1XW49TpqIZ83g5OXvWkFPi oiYQ== 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 w4si502607pjr.3.2021.12.08.17.07.08 for ; Wed, 08 Dec 2021 17:07:08 -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 45E3320D3E for ; Thu, 9 Dec 2021 10:07:07 +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 3113420D3E for ; Thu, 9 Dec 2021 10:07:07 +0900 (JST) Received: by mail-pf1-f198.google.com with SMTP id y5-20020a62b505000000b004a804839861so2578793pfe.7 for ; Wed, 08 Dec 2021 17:07:07 -0800 (PST) X-Received: by 2002:a17:903:41cb:b0:142:62a:4d86 with SMTP id u11-20020a17090341cb00b00142062a4d86mr63278234ple.43.1639012026115; Wed, 08 Dec 2021 17:07:06 -0800 (PST) X-Received: by 2002:a17:903:41cb:b0:142:62a:4d86 with SMTP id u11-20020a17090341cb00b00142062a4d86mr63278213ple.43.1639012025873; Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from pc-0115 (103.131.189.35.bc.googleusercontent.com. [35.189.131.103]) by smtp.gmail.com with ESMTPSA id o134sm4517701pfg.1.2021.12.08.17.07.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.95) (envelope-from ) id 1mv7tn-0032Uf-UL; Thu, 09 Dec 2021 10:07:03 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH v2 1/4] ipc_notify_receive: add timeout_ms argument Date: Thu, 9 Dec 2021 10:06:56 +0900 Message-Id: <20211209010659.724523-1-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.33.0 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 --- v2: trivial rebase on master 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 851a17bfbaf8..930cbf393a12 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 Thu Dec 9 01:06:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1565560 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=j6o+93fm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::738; helo=mail-qk1-x738.google.com; envelope-from=swupdate+bncbcwivbv7sugrbpnnywgqmgqej22arbi@googlegroups.com; receiver=) Received: from mail-qk1-x738.google.com (mail-qk1-x738.google.com [IPv6:2607:f8b0:4864:20::738]) (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 4J8bV84Lsbz9t4b for ; Thu, 9 Dec 2021 12:07:12 +1100 (AEDT) Received: by mail-qk1-x738.google.com with SMTP id x5-20020a05620a0b4500b004679442640asf5201278qkg.20 for ; Wed, 08 Dec 2021 17:07:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1639012029; cv=pass; d=google.com; s=arc-20160816; b=tck7FmWUK9QnCgw7ZXiz7L84+O/fwWwRHfZDq+Cysl9y0y0QvGTE9EDXoIS0nCI4Vk qpkFmf2Xe7SBLiA0MZRNnbXXxuhpqeLeZe38rhaTIJg3EryIcbBuLH7Vmd/2tmC1yLDZ 790d24SpPKvWHT2OaK+uVlG40eTx22Gjvu5gO6DZHj+cbcNe6fNV2Lt7inhKinvn94pX 0EfM8xpJ3nBaQ2phTjgHGUJvjI9BO6jCjCsvI1/by3UCJfX56bBqVnUNVNt2VJUqSBM0 +gXgKqTATPM3sFQi/vxvPYIvyoFVcZNpDcMyXSW7KVFmQQl+y+IAL3plGTcnmgXS6dd4 3qrA== 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=FuwrLaWQ92IPA8L0u+sYtWHJocOsAUybmts44edDsLI=; b=h5Zn4iQmPDlmAgciE1DekqiURm/BlM99GI7cdv9knMSduu8CW+OxeHMNCy4ofraRxe iOF/7PhKG/sj8PHcj4Y8/u20EkTuc2BUiw+99P55Q3ye58hTRgaWQYzGfTHCberuxx+O GBp+Ncid+K1ofAGp5mKt44J/dXspG9d1kTj513vTI3PjnWukYhKCfMrOQkOyMMVCNyTv kDo5lNxsQ4rQfeBCgvvBtaDCfUz/nQQ5/Ot2yXsgs69jGWlvKm3zHNXISfvC9z2PR6fB AsJWh+21M3uIsOJLwg1v60zsxjO/iX3c1c0PWcbPvZEir1G87KB2Tk2BUvYKyh0L1/9x /Cmg== 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=FuwrLaWQ92IPA8L0u+sYtWHJocOsAUybmts44edDsLI=; b=j6o+93fmPVCxI+il90CGvYVOmdR8TfjF9d/XgidkQwS2DlCMx63vaAAoLjhc3IVuup ZLxwgM3HDBQBsg9xMQ9HKE8XvQLC63j9GR37ZBsbSkbIpcEapnWXKyXfyJ2oL97BjqY2 nJ80AE9Qzi8BRJAqupxILfpDHwKkOIvBtJe2Devn9iQ8yFtyqraeCW75cfLuHQf7Y9FP lQa3pDP9gOYuD/MMHYFJ2guEktMhFDF0/i+e6uTNXPdBhJy6ENecG3fHqcvbBDuwuhRn 5awt9jSsCV0YZXUpC1VtRlswhq0t09yL8kBrFl8y8UuoCnhcOFVdI2ywSIsf240zM7pg zHEg== 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=FuwrLaWQ92IPA8L0u+sYtWHJocOsAUybmts44edDsLI=; b=4kE2RvbM3D/JOdzA1Z9tazgdWJdRO/kCFg7m5RiNfqiZlZEtDRMB6q0UDq6u0+0PBA AksGSAdZ1SBv4zLznoNP8tt3on+CEvioJ7buNCROz8+o4ILHmkNJcZuonWfjKf+EqTsb 1ktsXPa8c9pubvDMBQfgYLTIXUwlvx8vjRYcXqatZrzT+ZjFtl+x6LLvShaX0Gl4bbAZ seDqHDAYx29p1zdnB9g1DhCPSke8PCBiz+y/PbyHsTsErDtEdqdYTtpYiujj5nsKQkrO sz0e1HuddzyXhNce63LptuUzOYCvHfP6GXf1FOPOoZtsYYhhbUrWwld0NOm2xJ5Y/X3f CnWQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM5322BntcSFQEP0c4odNLkiCCrYzZ5S++1rYZq9B6EUCgsB/c5+nD QL4+ALGxl4gxbyGbE+9Lgho= X-Google-Smtp-Source: ABdhPJwDvpULPytS7EN7DI3CjvHlKWjMBRHHSi/5Y2ZW2NB4RZh9VXQwdQjmueLEUuB+TR3mIwXq8A== X-Received: by 2002:a05:620a:1468:: with SMTP id j8mr10558791qkl.170.1639012029540; Wed, 08 Dec 2021 17:07:09 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6214:1a10:: with SMTP id fh16ls2161228qvb.0.gmail; Wed, 08 Dec 2021 17:07:09 -0800 (PST) X-Received: by 2002:a05:6214:1231:: with SMTP id p17mr12486188qvv.106.1639012028959; Wed, 08 Dec 2021 17:07:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639012028; cv=none; d=google.com; s=arc-20160816; b=GJyW29eXsLHUapoVimJC9Q3MMCrVDLRIxvREmwpDWLQ8/e0ea+7/INSwhKD4j0tky1 Ad9DGsj65hqUCduFORYpjenCigzaC46vpHNfOORqjWlVh+eG+3sPasMVihJ1wwdKKtnx K6puRhNLMHd6XK6Bq85yR7WbmbfxRF7ihvuJ54IDaHMR9TTEFTNQ6TVPVQGeeWjrU9Ia zcjzwIA/meZm7ayh+cINAtv5IjNQpmQ+5QbKbH4yBTjVdtfIQrs7+p+xLOmG9A+Itu+c 4PZOiC/TalJlcvO3/vH7wF4g4OmOsLPb0xP4tsze4Ju8G1i50uqx6gYc7qNf5ZEJtDfn DadQ== 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=8KGB/1QKAhEzRuhwDL4lbEdRO6pie8LSO5bM+MR9rMg=; b=erlkUAQaxQyOUU5gHOlhN7JvZa/HDJEW9jiLATHkibIvRk2LWpisNb96JDfAjRsv+G nwkzyl7+BjFty55Zri/9DAjj+6D29n6Ebho5ulmfhbpOWImXGl3bNIe0mVwz/45EUu2n WlpqCmOT/kXM5NnhQWLqQQkqt7e2nM6UOhGeURJoikQlwh0H7lcI2gvfnfrrTww+koOW 2vncoE8NQunK3P2cwahyw4MEvop+kbH6Lvpw42DiVBpGtEQ43XDUtbcA23u4I6kKage9 fC4IBno6hc+BjI25APb/+lZXqWcfx2kG3AEpNd5REjF7V6KKgbeubdd9KkC19GbE2MAU 2+lA== 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 s4si997578qtc.4.2021.12.08.17.07.08 for ; Wed, 08 Dec 2021 17:07:08 -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 2855120D3C for ; Thu, 9 Dec 2021 10:07:07 +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 BB34320D3C for ; Thu, 9 Dec 2021 10:07:06 +0900 (JST) Received: by mail-pf1-f198.google.com with SMTP id w2-20020a627b02000000b0049fa951281fso2566309pfc.9 for ; Wed, 08 Dec 2021 17:07:06 -0800 (PST) X-Received: by 2002:a17:90b:3144:: with SMTP id ip4mr11731439pjb.153.1639012025825; Wed, 08 Dec 2021 17:07:05 -0800 (PST) X-Received: by 2002:a17:90b:3144:: with SMTP id ip4mr11731420pjb.153.1639012025633; Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from pc-0115 (35.112.198.104.bc.googleusercontent.com. [104.198.112.35]) by smtp.gmail.com with ESMTPSA id l186sm3406510pga.24.2021.12.08.17.07.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.95) (envelope-from ) id 1mv7tn-0032Ui-Vw; Thu, 09 Dec 2021 10:07:03 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH v2 2/4] ipc_notify_connect: fix return 0 when message was not acked Date: Thu, 9 Dec 2021 10:06:57 +0900 Message-Id: <20211209010659.724523-2-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211209010659.724523-1-dominique.martinet@atmark-techno.com> References: <20211209010659.724523-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 --- v2: trivial rebase on master 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 Thu Dec 9 01:06:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1565559 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=rzcTKBiZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::13e; helo=mail-il1-x13e.google.com; envelope-from=swupdate+bncbcwivbv7sugrbpfnywgqmgqeuuudkea@googlegroups.com; receiver=) Received: from mail-il1-x13e.google.com (mail-il1-x13e.google.com [IPv6:2607:f8b0:4864:20::13e]) (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 4J8bV84JyGz9sRK for ; Thu, 9 Dec 2021 12:07:11 +1100 (AEDT) Received: by mail-il1-x13e.google.com with SMTP id j15-20020a056e02218f00b0029e3db8d6dfsf5443016ila.13 for ; Wed, 08 Dec 2021 17:07:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1639012028; cv=pass; d=google.com; s=arc-20160816; b=GEADleJB1sxBcfWmWPUTla38K7zSKD2hTWcydGGA1IpB/4DyOle4q5fIT+//ZNsAYs zSs1F7x+UpQHp4YqKGXH63CnyrQ+UGXjbt0HISiZktJ+XhQwH96U4Vp+bJLuK54nn8ok mcvEa5tNqIkDwaKL5pHjn06TnLHm+kWFcA3xzbeUzjByy4zpxFtzdfzRak/wY5BU0bi4 g4s6V1qLK1ErG64MrTC/oXS6vHertlykqvMlY/frP9nMFKHBV19iFMVIGhtrds076qy7 2Rtr9MxJWY/wQdiPyNMBpMH+nZt2/LwpAwklDDK7u1GhuclyvQkYTYIe6YP7xODChC94 /2Ig== 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=FyDmoqzI1Hv21CGbdbZy1u99bQlWfdPQaqyCnq3Ft4Y=; b=DLGQMfbL8co3MKUC+eZu6ROxbunAT2TsRfLm2FmPHjUPs2vrGbHloqA91/VSNQ/Xmx x9fRosz/bfmuFGOeLDbpOgKdwO7xuPOe1z9trtHMVpq4oC8UYLhJqiuZt7KYzE9yOmgN QqyVTIC+q+XyFf3jJ3fjQBlwxoYqvVwYMe15qYSLH0jufEFaUTkLBPr1+tW08jVUdxf0 D1jhBHTZIKzMgAp0szXUfovUdELWH3RcQDG5ZHrzLEygaF5BGke2LhDGrvm5DmhBlsjf j+OUKn/SrKyYhEk0abVjE9FLjBctIpnUqxuvueZ1m4gtjtmelcfkZsMfBtu1jqrwsgRC 3wCQ== 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=FyDmoqzI1Hv21CGbdbZy1u99bQlWfdPQaqyCnq3Ft4Y=; b=rzcTKBiZTyMQkQIOPlCra+Ye2ITr0hfnhYEC5jtykqBkdoXEYzCa1HMOJvcOsfttOZ pFJ7G5fgC7wtjk923bKxi/iaMsnFl5lWEjiQnPO9JSkRObGjdrRuQ0iF+RjSajTdC7Ry MJZbgA0KLfIvjaWGXdhQbvXlG/pdeZhp5cDxBk8WgmB80dmkQ0WSAwjk8GtgVA8oXzDR wK9p3AFncm4JWpgcs4ZmoKxYDUoN3ahF8AMJ9fY6BDlzgkaU3urr9fLGphdy5nzXA47W mDuLliHRrXnQ5xPusU70r54dD/MDV2zjfxyElZoGhDB8FD0NVb0Hfr3tEJcHMJM6eX5a NU9w== 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=FyDmoqzI1Hv21CGbdbZy1u99bQlWfdPQaqyCnq3Ft4Y=; b=hjo0LifuvNmdNIRQBkpKJE+HNeYpIpUER2VCf17+z9UjQHyavnOXUP4qWt+clkhrvl zb6E3osR24OLEws6IuownQZz5PsoVkCbkt1Bk/sCt7FA9neyKuyoNinEfX6KQfwrsFPu K7NQnL+FaUEtD6N9jbYGvUYqIvYkE9oQyCY7Wycui8mQJivZf+u4bU0TGnAyhYuPnlo8 VRpSgyzsjdLyDtdKpliD4rKYuCBsx6mgfOf39Klh2jh3IHslaEkNcNhFeJHo/j1FVJ7J DEuEYN9eIYvF5iIzGf+qrCOztSYwmWlnhdEqFOknxipcTfOR1vsRUJaEDoU2IPiadBPu 1N2A== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM530I+t1SaJQnmSibHWwnvm4t02Fgq3QzigcxRypF/AOQ785lncT8 SDlFPUgfIpdj6l7OCoRQQTU= X-Google-Smtp-Source: ABdhPJwUWgETx4JYgjcjt28WCmj6mW2Bdbe7joOUeluazQn1on3RfVc1ELeGMA9oA/WB2+wxIMjhmg== X-Received: by 2002:a05:6638:2054:: with SMTP id t20mr5099171jaj.42.1639012028705; Wed, 08 Dec 2021 17:07:08 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6638:411b:: with SMTP id ay27ls355288jab.10.gmail; Wed, 08 Dec 2021 17:07:08 -0800 (PST) X-Received: by 2002:a05:6638:148b:: with SMTP id j11mr4474464jak.114.1639012028070; Wed, 08 Dec 2021 17:07:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639012028; cv=none; d=google.com; s=arc-20160816; b=altEUKeXG67PEfglOezPttA/qLQ6ZlYfop7jcZCjcSMn/R7pOor/xxJQGSHKmU4V2m PIdPTNeqbimHwW952HzYsSzIPzMoLO2vXSWBo23fst+SDSxhqOise3UkaiMwhIAcwxVq wrZgkAKAQfHX5ES8DbKLbVjC6YkD18aF6tibAgPmdkAAl0Ou00j2v0FgjqWcZIZ5eyHf vBp7P+X5RAzW4E42uFzHxiQ3DY7dyWEFyOXmMt2qyvdruFcF/9u3pb5qwl4Z4la2V0aV bAg4JLsFOxlVy7Dx9uG65RXythDvU4A0PF6IRdJ+HMY/gt6znMBJBpmdCzGiulXLSv1A RAJw== 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=T2O4NyS4PXphwx8F4nv9sC4eHHgwrRdzb/zQ7bjXztU=; b=deaYEEAUorBfzlUcmoifOgujsCKrceYcwvYHzdwybeYB6CUhi9kETS433aAlidhiiY o3uYgnjZIrGiw9QYw54sYgtwuv8O7uW/xG9XbFYCadJ5g/Y6TJEcII19BrazqgFdf0wu GSCzNxa7LK0mTvR2uvcKdpPr2w10x1g31YUqsTAXqu4mxUUh9T1LZ/Hu2BYDo0Pk4+a1 CbA1vTvg86BP693sUXEpTWX4w6j8E6hVwxJUGItvnFSQe0TOd2XS8BiyYTlkn1NxsoO4 sv+LmYVtNrCCMHNIeaa16JmXdwsGL+FqjAUFkYOPHAbsp3smvlRWOLq1h90m6Ihp3/YJ 1RnQ== 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 i17si647129ila.3.2021.12.08.17.07.07 for ; Wed, 08 Dec 2021 17:07:07 -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 0CD4520CAE for ; Thu, 9 Dec 2021 10:07:07 +0900 (JST) Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by gw2.atmark-techno.com (Postfix) with ESMTPS id A19F420D37 for ; Thu, 9 Dec 2021 10:07:06 +0900 (JST) Received: by mail-pg1-f198.google.com with SMTP id 14-20020a63144e000000b0032f07c8df95so2269325pgu.9 for ; Wed, 08 Dec 2021 17:07:06 -0800 (PST) X-Received: by 2002:aa7:96b7:0:b0:49f:df90:e4ae with SMTP id g23-20020aa796b7000000b0049fdf90e4aemr8944839pfk.24.1639012025647; Wed, 08 Dec 2021 17:07:05 -0800 (PST) X-Received: by 2002:aa7:96b7:0:b0:49f:df90:e4ae with SMTP id g23-20020aa796b7000000b0049fdf90e4aemr8944817pfk.24.1639012025397; Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from pc-0115 (117.209.187.35.bc.googleusercontent.com. [35.187.209.117]) by smtp.gmail.com with ESMTPSA id u3sm5218203pfk.32.2021.12.08.17.07.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.95) (envelope-from ) id 1mv7to-0032Ul-0G; Thu, 09 Dec 2021 10:07:04 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH v2 3/4] network_ipc: update swupdate_async_thread to use notify Date: Thu, 9 Dec 2021 10:06:58 +0900 Message-Id: <20211209010659.724523-3-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211209010659.724523-1-dominique.martinet@atmark-techno.com> References: <20211209010659.724523-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 --- v2: trivial rebase on master 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 c439cf911b6c..0b9b129edb36 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 Thu Dec 9 01:06:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1565561 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=Ey/aX/2g; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::53e; helo=mail-pg1-x53e.google.com; envelope-from=swupdate+bncbcwivbv7sugrbpfnywgqmgqeuuudkea@googlegroups.com; receiver=) Received: from mail-pg1-x53e.google.com (mail-pg1-x53e.google.com [IPv6:2607:f8b0:4864:20::53e]) (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 4J8bV84sMlz9t55 for ; Thu, 9 Dec 2021 12:07:11 +1100 (AEDT) Received: by mail-pg1-x53e.google.com with SMTP id i12-20020a63584c000000b00330ec6e2c37sf2275762pgm.7 for ; Wed, 08 Dec 2021 17:07:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1639012029; cv=pass; d=google.com; s=arc-20160816; b=XSD2eCZMPcJ/jInjlGDSywJCf9lbFyk3BTye6QlqC4J9n6gwtxAN+yeDL3n8bGKZf3 2A7L1H3CzumYXtqKEgbDbS02XYxXwZkLbSf4z6hzGXd8hPlgnSEmj97JuvVtSXhiOOkg rsBcuy3G1xAjGf/mGT40SHm6HfZOw8+wjC/1Xow7nE1gQ85C+J8HMBRZ8H5DyxJFkn1F Qc/Wykz2M4st5VUX499wzvV8BTdCD1b8xgzGta8P4UEsC3cHe9zio0wk46dhzEs3/3ml FxqyvSzAYutDhDowIoBQ6Ps79hgSyC7KVRe+DTTCLVdeho2kqBRrja+/qSTeM1qvD8IW 6Q0Q== 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=TPzVfQWVcJQuKjGO5nlL3Fc4lvwjNtzprcQgh8H69XQ=; b=kYKYLT/2Wmuqs0h9sv8RBNRrVBRLFj6Y9jc9Lql8jFiw9ZsqBr/OZf2XUACrs6bkn7 xoJz5WgoU0z8InOVJph5wBtQRBMVAxOoOYOq5VlZ6eIxNoRQ/07C3DN5DPCMKNF8mEJG K4DP6Jz15cKDyb41xv3IS/WhwTp4SbqHQBOswoIhM4JtVjKQUmx83TfrJKAnWNmnnCTV 7kC9iqvrw+KYCoXmX4vqUTxcfzb56yWpKDzRoQr6rO8bKCm0kq6Ry6o1+siEE39UAjvB GA5LTkKTbFwv2Q/xbxwvzs+PQu/NGYTQ1feD1REmzwL/Ju7UuFe4gjHH78YrUuXHciqh VSzA== 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=TPzVfQWVcJQuKjGO5nlL3Fc4lvwjNtzprcQgh8H69XQ=; b=Ey/aX/2gjuRG8Hf33GEY3WlI9601dAFEi4WHvovVb87qU2cxmsXYgb22zo8x5vzHIo CpBeWFUFs2DE1TW/VwWR9VRTI8OvWR3LtOwdmGroCXshxM8+gxIx7W+O8I1Q7JO4l/bN 7Xu3AOdK0JYyCVFXx16W3wyn9GBhX0Vn3vuFjtPxF/gDYSQ2E4NKtm7nXE5krPSpDdQS kacNbw+301wh5RAueqCbO2rTC43ldF6A0LZE+ByLI8++VL4UKA9ELppnDCGv4SoYMGXG 8umU2qeRNOrrkDpSQGYb3iGelf2H2fRgtPdCm9IysbJ5Q2F0mgpsyRe9jIm1QdOElDac 25fw== 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=TPzVfQWVcJQuKjGO5nlL3Fc4lvwjNtzprcQgh8H69XQ=; b=nfDzQD+Cey/YFesNFdPeAYD49xDFUx4fBPq/GxIPe4rmr1ANgCWXXIVjcoh5AIJ7n2 DpXDHn7fXg5Yu1xL1nhcwa9ZtAN2cdgOyeJQbFXufAQ/SA7GfcsVkPRYry20LTHwrbG4 vGf3BTsR0oYgtJ88eCWOtWKdELtgLGzI95z51ojE7dqIYCRjAcWiwPDI+j8Rs1TaXvly CeH+puj4YrxvuxxeqehhdkFMwYZ0A0tNgJ5Q7fbRLOamxwVoijg4ntWY1Br0II4L+TEH a4NKE8D3lvZl/Tzga72K4Tvl/vOPYrMTqBKjtPMtOUV37nOQ9K/xt7oL9jcAO/n/9hU8 zHwA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532rxiB8Uiq7GkMCBcceZ4IriBwKcMtLbDN5mPAcW/BmJ9/a2RFr XRTsyd6/3VXWKMRT8FfjJcg= X-Google-Smtp-Source: ABdhPJwgCh1qp3NqkYYRMQZh+H1Ke61pF7ibFzoTvQtmtryDoVJGxYtPE9S/kvftwSjI/gccTQ/CwQ== X-Received: by 2002:a17:902:ea09:b0:141:ec88:4410 with SMTP id s9-20020a170902ea0900b00141ec884410mr64703252plg.51.1639012029001; Wed, 08 Dec 2021 17:07:09 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:902:d50e:: with SMTP id b14ls2087410plg.7.gmail; Wed, 08 Dec 2021 17:07:08 -0800 (PST) X-Received: by 2002:a17:90a:7ac8:: with SMTP id b8mr11432053pjl.206.1639012028241; Wed, 08 Dec 2021 17:07:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639012028; cv=none; d=google.com; s=arc-20160816; b=YpohO80aeyaBxcy6wo8DDOB89cV4/iBUGaB3F1q52GcMn505VXlkLyU+jHP8A1ci2i 9nZDVJdlS6g1tWIZLz1IM8gB4X0jv9l9lJotIj344mZajS1IPfSADMbt7vSmJR8etYHz XNvciO/lLwjeKKyrmnklEjYkAN3n0s2O120cxq6lOKgouuaKhuoApyBYtwUZw4/mdMc+ xD6l1H18SW1sLlbuNFmyVGYWNuTR4PeZLDUKq1ZMPVjEjC63ve31Nap42xIIfJU4iZid ikpTlVVcleOfejkuYBzIsnz5iCWKZKYddVUzblCtiEwmP3IejxqSLP+1HRHtr3vT/xBb 1AwA== 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=vU/EkTXJ4VtgICjWp4bhVuVGVBsXJ4CUtw31WN/7RhM=; b=evyZOGeditjqdGV5Wtv5UqHwCdM3sg21YxWH71jKsK4s6sgpOwSoLAdBrjiiAWSRmu +mCU7cohsTPgDaQI6ufuGzyHXpEUqKRr6k9AE1RNlN3XOR6bxkcipv8xrgpK207qmHbV M2GRvOppDwh+7MoyBV+ueep7AQVog7ifmxg3Xo15i2iMm6CDbz3DZAOVw+HN3hn1NJ2c XPG55Nbs9dvWSEgxb03ZDNldwTkuS0Cw6fFNTSNjh2MLJms98r7psJjfyEwAJV7ig3oE a0bzpttnKE46pfrxtIMkQVAhH5GHjfxiTVpimjnqfoj2IiOq8jUT6J1QvtRxgGoQ9u8v 6yLA== 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 x31si401641pfh.5.2021.12.08.17.07.08 for ; Wed, 08 Dec 2021 17:07:08 -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 183DF20D39 for ; Thu, 9 Dec 2021 10:07:07 +0900 (JST) Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by gw2.atmark-techno.com (Postfix) with ESMTPS id A430C20D39 for ; Thu, 9 Dec 2021 10:07:06 +0900 (JST) Received: by mail-pj1-f71.google.com with SMTP id a16-20020a17090aa51000b001a78699acceso4767938pjq.8 for ; Wed, 08 Dec 2021 17:07:06 -0800 (PST) X-Received: by 2002:a63:1018:: with SMTP id f24mr19037482pgl.20.1639012025711; Wed, 08 Dec 2021 17:07:05 -0800 (PST) X-Received: by 2002:a63:1018:: with SMTP id f24mr19037467pgl.20.1639012025520; Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from pc-0115 (145.82.198.104.bc.googleusercontent.com. [104.198.82.145]) by smtp.gmail.com with ESMTPSA id d9sm5070697pfu.144.2021.12.08.17.07.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Dec 2021 17:07:05 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.95) (envelope-from ) id 1mv7to-0032Uq-0q; Thu, 09 Dec 2021 10:07:04 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH v2 4/4] write_notify_msg: silence status client disappearing messages Date: Thu, 9 Dec 2021 10:06:59 +0900 Message-Id: <20211209010659.724523-4-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211209010659.724523-1-dominique.martinet@atmark-techno.com> References: <20211209010659.724523-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 --- v2: trivial rebase on master core/network_thread.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/network_thread.c b/core/network_thread.c index 1b63690a2af5..4dd3ec27ae8f 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;