From patchwork Tue Mar 8 16:21:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1603077 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=T5RNWP9P; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::63d; helo=mail-ej1-x63d.google.com; envelope-from=swupdate+bncbcxploxj6ikrbaeft2iqmgqey5dgtqi@googlegroups.com; receiver=) Received: from mail-ej1-x63d.google.com (mail-ej1-x63d.google.com [IPv6:2a00:1450:4864:20::63d]) (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 4KCgYy0C5Fz9sG9 for ; Wed, 9 Mar 2022 03:21:25 +1100 (AEDT) Received: by mail-ej1-x63d.google.com with SMTP id q22-20020a1709064cd600b006db14922f93sf3029454ejt.7 for ; Tue, 08 Mar 2022 08:21:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1646756481; cv=pass; d=google.com; s=arc-20160816; b=Jy0P/DGAQcv1AfVjOdE426fmjcu4X5Sa5yz4xtIw2nsCZH9xJ2IGKTDuWBj7KBL+M6 RdqdvbNvbWKrkPccgCGNlBF0NEVUdtwK+LfYYyhYQkshjZczDpEQZeZ6iZf4AHzqLt5S O8fQ4HfG30mUrD/invHlbogifXWVUBJvOPd5Q3ZXVlKxedFkV5KGwVJi++r8/IUkNUJ3 9fujGYnx7oP5O7S8aqEI43X/rlhb5EaXX/8PfP0bnRDhFjHhzREUCLuZnVQv65Qko+W9 OZ4eIMEF5hzaPgR6Cl+YXkEmfvzQYYwYyHU8Yu38qh3BuvWXOBvLrZt28aJkEIzeoB9d LAjQ== 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=lfYVnZxQj7CElX/8lQgqCwCz8JM9xj3oh5CjpCYYCUQ=; b=LWt9i55pykAURtubso6PA7HVPTMnUfSJhHWNg7vHtLcCfA9V/F+wbN9nKbHGE1QP0y GHUddAq2+PoWVhuLCJSQK6IjojbqP15K8sggzYT4M64ztAf5FqujX5RcSp8I7PnHHcI+ jhPXEL9AXYUFEoOYFCMcundkY/GIE8hIOboQ9KLcOdf7x23/cogbvhzKI9Ewk3ZPVwXr SdlhDp2SvCGzVeV2qsglRuwsF8al3iOu4eJexlL9i9DqMTRq/tgsIM4sBb5rfkDAHPhU LAmL1tajV+sXEG6i82Vjz1kS7fCIZ5sjE4fcJLnDav21QeSxzFkD09kO2llRSqSYLn7N wwpw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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=lfYVnZxQj7CElX/8lQgqCwCz8JM9xj3oh5CjpCYYCUQ=; b=T5RNWP9PvemnQgROmiWYU4PoTNIYQzyw/WVdgX3VpcP2i72ugspdYC+l7H35+1rcs5 +j3CGTF4JHmLXadFsKpgS5hfqODEsQqNsGyoQMOdtcTdSHDlRkxeMhwn+3f1UkulzyLW gHgZ5jkCdVtyIeuca2CvjQ6B6EymegBHA2DbYn8tnJcffz9/AGInN41Yb9ofqHxtEIV7 vWwnWpXqdNeHSHYy7PI0cuy5KFyPxP3lOMawhsRa86VXJFkJaAZuUPftXRWMKgfLedPd FzSbvM9fvWS6lxzs+Zzy0X3YqVuFHk3MHAAUhqCOQF1LNSxYx5eHREbJctzc5UTjcvyO R5Mw== 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=lfYVnZxQj7CElX/8lQgqCwCz8JM9xj3oh5CjpCYYCUQ=; b=5i2MYEPr1zw4fsAf0VucHfGxam5khSdpNNBDMnu/KzXMZPVEGzxOjkMoksen5XFX80 MaVehgS05aqLLn08xLDfPwHnvz76LVkRyv7EhEQk9tDfqMsR2kZwFmBuseOsUtATLH68 rEfx8Ns4dWWTDkHjktpqR3zisSUKI5UgqSQQOlbtcEzLDVRX0BP017VYKtRNkWAeaaKR cN/cgp+DdxZ5c4h80p5bVIzpUYUabFpAp8XSMlZsb7ihi5PPpcTSC1Ge7evnB0M5mUaU nQBjZl9W8u5PuB6X2y2Ey4kNxXh+VBxSiqvxdFOOnfIXl+Z8w0DRA/JpphFqZIPLBgpg tgUg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM531d4BAQC0XZXvCIpn+Dk23opK2VMeslQr6oa1RKAZkEgu9zw7R3 Xf4ACm3AKGUOZsjJ2rKU3Tc= X-Google-Smtp-Source: ABdhPJydsFHMou9tXLzl9n5lx+ezFOiZe/6mzUgd5o+ey7PQzvbPLdFZM1ztMk8bzM1RWIoxdQ3iWA== X-Received: by 2002:a17:907:7f8d:b0:6da:b3d6:a427 with SMTP id qk13-20020a1709077f8d00b006dab3d6a427mr13877780ejc.509.1646756480740; Tue, 08 Mar 2022 08:21:20 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:aa7:c991:0:b0:416:3986:ee63 with SMTP id c17-20020aa7c991000000b004163986ee63ls77280edt.2.gmail; Tue, 08 Mar 2022 08:21:19 -0800 (PST) X-Received: by 2002:a05:6402:174a:b0:415:ce98:9feb with SMTP id v10-20020a056402174a00b00415ce989febmr17171682edx.109.1646756479742; Tue, 08 Mar 2022 08:21:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646756479; cv=none; d=google.com; s=arc-20160816; b=sjephzXCp6gMxmSqQJkY/kUZGzl+QrqibUMDwfkjaHq/HGpXPRzURst84Bzu4heWEF nq1l6SDAgC8w5Lvvnqb5KkDDSgaZSk69E4jlpkJ+s5/Yc+CmYEXyKQmltK7RnpmYZjZX X7ImY9zSqudbiEBSW5NRn4xysOFiiENnP3KGVne4CnZ4fKvwzcnajdGjwe+CFPeE8R61 98Rvb/sxPHn4CxE1bmozNsaLjg+5qsTYf9OYnpBVoN7+cGLdbyb5k8MC8wNZxjASfhQg rmaP9wO+Obn3oWqK/ttn0PAoyMd+z6Sg8k1MC9b3c4TXbY+IGWFqApLlcLNz8gfaQVvH 9DGQ== 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=yRYBxD/qcd987HA9xv09I14GYGeFiwKx0DfhQh1e8qQ=; b=Ry2fXLkqGFk7Gt/nSJwyG7P2dh7KBeDj7Gf5t7IaQQjiq3HypFO5/m9IZYMsBg5M/n h448mAWvfm/BWy5V5XXjef1NdNVgkpLg6/d+GlEO3Tz6p4d5+grIffF7FwvUL0lHwKfo 1azpCZ/X+28V72k25kr4QCg45l3eCIuG2vmoLEay30rza+lPRNApsFXV8HczspZqzWtK zRz6UushmmSondr5fjj9QYpXEOQx+1F58prE1xa7UbCYf5nWH1wWoaON51Lwo+jBx+eb rd3R1Pg6Y46EvTPpZn0B2XjwdKKn4m/xZztQd2Uwia2ia9L4chIhh2pq1HGlx+YwusiH 0HrA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id d3-20020a1709063ec300b006d9f7b78412si692890ejj.0.2022.03.08.08.21.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Mar 2022 08:21:19 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4KCgYq3yR7z1s7t4; Tue, 8 Mar 2022 17:21:19 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4KCgYq36lvz1qqkC; Tue, 8 Mar 2022 17:21:19 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 9TyHLKgq7NyF; Tue, 8 Mar 2022 17:21:18 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Tue, 8 Mar 2022 17:21:18 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 144294541C27; Tue, 8 Mar 2022 17:21:18 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([IPv6:::1]) by localhost (mail.babic.homelinux.org [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rJFQz6SlWR6a; Tue, 8 Mar 2022 17:21:14 +0100 (CET) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id 1E2114540972; Tue, 8 Mar 2022 17:21:14 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 1/4] Revert "ipc_notify_receive: add timeout_ms argument" Date: Tue, 8 Mar 2022 17:21:06 +0100 Message-Id: <20220308162109.383573-1-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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: , This reverts commit 85b28421eed60c13161ae58cc58d218d5df9ff8f. This will avoid the deadlock when a lot of notification are sent, and the client cannot read the notification in time, causing SWUpdate to block and to not read the IPC with SWU. Signed-off-by: Stefano Babic --- include/network_ipc.h | 4 +- ipc/network_ipc.c | 86 +++++++++++++++++++---------------- mongoose/mongoose_interface.c | 2 +- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/include/network_ipc.h b/include/network_ipc.h index 356931b..6dc2521 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, int timeout_ms); +int ipc_get_status_timeout(ipc_message *msg, unsigned int timeout_ms); int ipc_notify_connect(void); -int ipc_notify_receive(int *connfd, ipc_message *msg, int timeout_ms); +int ipc_notify_receive(int *connfd, ipc_message *msg); 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 886af0a..eb1082c 100644 --- a/ipc/network_ipc.c +++ b/ipc/network_ipc.c @@ -92,32 +92,11 @@ int ipc_postupdate(ipc_message *msg) { return -result; } -static int __ipc_select_timeout(int connfd, ipc_message *msg, int timeout_ms) { +static int __ipc_get_status(int connfd, ipc_message *msg, unsigned 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; @@ -125,8 +104,22 @@ static int __ipc_get_status(int connfd, ipc_message *msg, int timeout_ms) if (write(connfd, msg, sizeof(*msg)) != sizeof(*msg)) return -1; - if (__ipc_select_timeout(connfd, msg, timeout_ms)) - return -ETIMEDOUT; + 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; + } return -(read(connfd, msg, sizeof(*msg)) != sizeof(*msg)); } @@ -140,7 +133,7 @@ int ipc_get_status(ipc_message *msg) if (connfd < 0) return -1; - ret = __ipc_get_status(connfd, msg, -1); + ret = __ipc_get_status(connfd, msg, 0); close(connfd); return ret; @@ -151,7 +144,7 @@ int ipc_get_status(ipc_message *msg) * -1 : error * else data read */ -int ipc_get_status_timeout(ipc_message *msg, int timeout_ms) +int ipc_get_status_timeout(ipc_message *msg, unsigned int timeout_ms) { int ret; int connfd; @@ -170,8 +163,11 @@ int ipc_get_status_timeout(ipc_message *msg, int timeout_ms) return ret == 0 ? sizeof(*msg) : -1; } -static int __ipc_start_notify(int connfd, ipc_message *msg, int timeout_ms) +static int __ipc_start_notify(int connfd, ipc_message *msg, unsigned int timeout_ms) { + fd_set fds; + struct timeval tv; + memset(msg, 0, sizeof(*msg)); msg->magic = IPC_MAGIC; msg->type = NOTIFY_STREAM; @@ -179,8 +175,22 @@ static int __ipc_start_notify(int connfd, ipc_message *msg, int timeout_ms) if (write(connfd, msg, sizeof(*msg)) != sizeof(*msg)) return -1; - if (__ipc_select_timeout(connfd, msg, timeout_ms)) - return -ETIMEDOUT; + 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; + } return -(read(connfd, msg, sizeof(*msg)) != sizeof(*msg)); } @@ -198,7 +208,7 @@ int ipc_notify_connect(void) /* * Initialize the notify stream */ - ret = __ipc_start_notify(connfd, &msg, -1); + ret = __ipc_start_notify(connfd, &msg, 0); if (ret || msg.type != ACK) { fprintf(stdout, "Notify connection handshake failed..\n"); close(connfd); @@ -210,14 +220,10 @@ int ipc_notify_connect(void) return connfd; } -int ipc_notify_receive(int *connfd, ipc_message *msg, int timeout_ms) +int ipc_notify_receive(int *connfd, ipc_message *msg) { - int ret; + int ret = read(*connfd, msg, sizeof(*msg)); - 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; @@ -225,14 +231,14 @@ int ipc_notify_receive(int *connfd, ipc_message *msg, int timeout_ms) fprintf(stdout, "Connection closing..\n"); close(*connfd); *connfd = -1; - return -EIO; + return -1; } if (msg->magic != IPC_MAGIC) { fprintf(stdout, "Connection closing, invalid magic...\n"); close(*connfd); *connfd = -1; - return -EIO; + return -1; } return ret; @@ -326,7 +332,7 @@ int ipc_wait_for_complete(getstatus callback) fd = prepare_ipc(); if (fd < 0) break; - ret = __ipc_get_status(fd, &message, -1); + ret = __ipc_get_status(fd, &message, 0); close(fd); if (ret < 0) { diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index 930cbf3..851a17b 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, -1); + ret = ipc_notify_receive(&fd, &msg); if (ret != sizeof(msg)) return NULL;