From patchwork Mon Nov 9 20:57:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1397140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::439; helo=mail-wr1-x439.google.com; envelope-from=swupdate+bncbcxploxj6ikrbmg2u36qkgqemz6dvui@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=oDsI2Z/A; dkim-atps=neutral Received: from mail-wr1-x439.google.com (mail-wr1-x439.google.com [IPv6:2a00:1450:4864:20::439]) (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 ozlabs.org (Postfix) with ESMTPS id 4CVNbn469jz9sPB for ; Tue, 10 Nov 2020 07:57:25 +1100 (AEDT) Received: by mail-wr1-x439.google.com with SMTP id t17sf4808655wrm.13 for ; Mon, 09 Nov 2020 12:57:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1604955441; cv=pass; d=google.com; s=arc-20160816; b=tpMxfrrEKSoxAslBiZscoMZIPbK/u28JBp10SOvLDUjotR4j6ZtH8kdKRJYl277cvM +YqDo1C1PJMrs1ifRqateTfe70a4tNVHfTONyaJldEjmBnqlvAURAYOvrKXU+C6PJMw+ VHh7BV91ejfWtjP6UW5/Py24Iv+1hGwiH0vCOqkIh+7uMyZOEZGLAAokoJKPGv+LNC4L 0PzTOZP5PDOqUq/bSmxm4TDPS29Dc5tri/qo1QYCEarXjM5V1TIkKwRfj0aItB52pp6C 067jQKa+dNXII1GBGnMmrjA80lPjTXpyZUFcaeUcSp5VHnJE8YCN0f2e3BfJRwnnM5fr SS6w== 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=MH2GoKv1d5RyswmzKfOxmMU6Q6ZU1rWz4xwxyp6HNoA=; b=L45sQXiExv2CjoxTjHyJGaBhdhly/fjsSYgVNPEthfHdFmYCwQJ5LhqokJDaZRn+lr PR6+74Ar8Ur91bv+bAx2Ckz1fwd9uUnql5EXA3wD6eY27t/KAIMBDjx8/qdwg0W1yJG6 dqqZ42Lo9ZabX37hqjeCT6cGYw4GET4CPJ8HTpAdgH2L6ndTX9XqasYDMojYPR2P8KDt 9clsWm6CDrcmJopaVmpyBy7qCma7u0nh2sC+kKgS+ZzZG2YZrsN57my6L3CTVKM6vuEn Dw9It0tCUxdkCdSyUQHmXJD/VP3zvC/xp5SE9u7+fM76PAx4VzyuJSXew2iq+ckASDKY bGPg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; 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=MH2GoKv1d5RyswmzKfOxmMU6Q6ZU1rWz4xwxyp6HNoA=; b=oDsI2Z/AGDQeTdIiqVEd+e2zQZ7VPgPKDIuBbdcIaDZnf4W8R+pZLwQwSIoTP5SvQZ S2Te4B/Qh51z8XNkg8t4Sih1fFlO8v/CuCtQ85lOk96PDw0hKhp4i/2Tmo2eo/eJpEqH Oo3YhGCMaReJp8AH/UxqrDztlfn8x116voc5isSfNZ/2tN6B+QisWRHbjxBrkpSLHVf9 QpI/1ZOxjPO4KB4TCTQYMlaxl7hVLA/nixSQNnfcvd73JyO/fx274D/s1Kx/KastlhYP XMyN3hxctZXxBHD83KibPdGm4U+oy2N3xwueQhWMXQUTjgiSk+51p7ZYnLGxHmMpyW2G WJ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=MH2GoKv1d5RyswmzKfOxmMU6Q6ZU1rWz4xwxyp6HNoA=; b=GlePGPmLhdmyUbuIVLhCiquF9dR8nChSBFbnvrJTuBinH2+vn1DyZdNzv/c61jTiPD X1/BhQeQwQ+ZY7CWNVb7I4r7d/lGXHwgGHx75RpITjOr9Au9d7j+NjE0LP6Lu6lo9GnZ pmNFGol+72RnIJHoEjFknkQg3X4AYrEOWN6LK2fJx6tPSXoMGrGLwSnW5lHdtFpZ4rr1 TRqdete5vBcPKyxF6cFmoY9FukpZ9hHScASL/oZP9BLgpsTonXdCD6X41PPBHw/m6GTe CoScp6kzqof8G1uCwDn3gL8J2DJo7Wlt5TcQLNAWZwJUNXSJdhdWQyfjtVWaUjEI9li5 hJCg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM530jvLShMnuKHraAAyKipYBZqIQuT8qdldkn2jaJw7vtPEhKe0kf HYS7eu9Bo0BKNo0e6nIMCOY= X-Google-Smtp-Source: ABdhPJxEa3k87jb7OfjI49I7VrxPQCsqei1jmLDAsGswcotbp3rXfMMFsvnzbsZjq48XBkf1kw2bCw== X-Received: by 2002:a5d:5105:: with SMTP id s5mr21028405wrt.255.1604955441190; Mon, 09 Nov 2020 12:57:21 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:adf:aa87:: with SMTP id h7ls198255wrc.2.gmail; Mon, 09 Nov 2020 12:57:19 -0800 (PST) X-Received: by 2002:adf:e950:: with SMTP id m16mr20867811wrn.0.1604955439801; Mon, 09 Nov 2020 12:57:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604955439; cv=none; d=google.com; s=arc-20160816; b=CqwpBt3hOmy3itT2WIvFWyrv2JV80LMzqfLg7e0CaBE5yt2xoaCyd8k4UjWrbzPMHY hffk52tZWg3Dteq+D8xuDlGpK0Phfwyps6CdObZz1yxosqSG0fNIUTUEcTFhNSMbQfYU xwsP3q31BX/XYewMumL89PJLKCyaN4c0odJtL7gMzvAU6VX777/VwrhMZsqAeNbXkK5L 2oEHLkvIKDC57SWbnzXiLyDo4s2vn2sI5g1eBB9OutSsbSxCvQECCO33G0x5XxdjdEq6 Hl5rrcWQhDSQJ18HlnwaTJOeJy7SFOXes+Ltaz9TskaCC+9DzHKRWFcsGfXAVq4WEtXy JQ5g== 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=gNsA6+zt4A+l/6fRBGvQMTEpE9H6yGDFmiLcsj9UojE=; b=Bdhar6/Lu9T6MrbK3FZ4SNtBDjzzIJrMcTry9X+CMm5bc1WeTRz58wA+ZhpASvRym2 q0oyfKZ5xX4nB4NIlvd0KYCf26eT7Vi29XvelqmWoAmBliWS31Qp6bgmQX4H4/WC62/l pcuT6wQdosqBJWRgech6AvU/fAYKsFXWthU4RoNfRWSDdx+LNmhY7Ye/699pX7z7En6e luf1cTS9Y8rYtWSj7oYlhrOKVtCnvHoMDj5KJ0Ht0t0IsRTac3BeJNLB4tT8jvPMaMqF YaRblAaZh8m7h5rk6o5/DRX/oHG/8PwVVS4cVgGVMXhn9xl/DUdt0TTrkS+0nMuCECy1 iJOg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id h1si117946wrp.1.2020.11.09.12.57.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2020 12:57:19 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4CVNbg45rLz1qs0n; Mon, 9 Nov 2020 21:57:19 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4CVNbg3tP8z1qyX3; Mon, 9 Nov 2020 21:57: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 M6YSW6cOOX0P; Mon, 9 Nov 2020 21:57: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; Mon, 9 Nov 2020 21:57:18 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 3A61B4540496; Mon, 9 Nov 2020 21:57:18 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xzPwrSwNdlH5; Mon, 9 Nov 2020 21:57:15 +0100 (CET) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.64]) by babic.homelinux.org (Postfix) with ESMTP id 7750145403CB; Mon, 9 Nov 2020 21:57:15 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] Fix handle of total downloaded bytes in progress Date: Mon, 9 Nov 2020 21:57:13 +0100 Message-Id: <20201109205713.380179-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: 212.18.0.9 is neither permitted nor denied by best guess record for 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: , commit 5738732 disables the number of downloaded bytes because buggy, this fix the behavior and ensures that the value is correctly forwareded to the listeners. Signed-off-by: Stefano Babic --- core/notifier.c | 7 ++++--- core/progress_thread.c | 11 ++++++++--- include/progress.h | 9 --------- include/progress_ipc.h | 1 + tools/swupdate-progress.c | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/core/notifier.c b/core/notifier.c index 276e155..e4ca3c6 100644 --- a/core/notifier.c +++ b/core/notifier.c @@ -339,15 +339,16 @@ static void process_notifier (RECOVERY_STATUS status, int event, int level, cons */ static void progress_notifier (RECOVERY_STATUS status, int event, int level, const char *msg) { + int dwl_percent = 0; + unsigned long long dwl_bytes = 0; (void)level; /* Check just in case a process want to send an info outside */ if (status != PROGRESS) return; - if (event == RECOVERY_DWL) { - struct progress_dwl_data *pdwl = (struct progress_dwl_data *)msg; - swupdate_download_update(pdwl->dwl_percent, pdwl->dwl_bytes); + if (event == RECOVERY_DWL && (sscanf(msg, "%d-%llu", &dwl_percent, &dwl_bytes) == 2)) { + swupdate_download_update(dwl_percent, dwl_bytes); return; } diff --git a/core/progress_thread.c b/core/progress_thread.c index cc556c1..7c424fc 100644 --- a/core/progress_thread.c +++ b/core/progress_thread.c @@ -97,7 +97,7 @@ static void _swupdate_download_update(unsigned int perc, unsigned long long tota pthread_mutex_lock(&pprog->lock); if (perc != pprog->msg.dwl_percent) { pprog->msg.dwl_percent = perc; - totalbytes = totalbytes; + pprog->msg.dwl_bytes = totalbytes; send_progress_msg(); } pthread_mutex_unlock(&pprog->lock); @@ -138,8 +138,13 @@ void swupdate_download_update(unsigned int perc, unsigned long long totalbytes) * Not called by main process, for example by suricatta or Webserver */ if (pid == getpid()) { - struct progress_dwl_data *pdwl = (struct progress_dwl_data *)info; - pdwl->dwl_percent = perc; + /* + * Notify can just receive a string as message + * so it is necessary to encode further information as string + * and decode them in the notifier, in this case + * the progress_notifier + */ + snprintf(info, sizeof(info) - 1, "%d-%llu", perc, totalbytes); notify(PROGRESS, RECOVERY_DWL, TRACELEVEL, info); return; } diff --git a/include/progress.h b/include/progress.h index 738e59f..9297cf9 100644 --- a/include/progress.h +++ b/include/progress.h @@ -11,15 +11,6 @@ #include #include -/* - * Internal structures to be used to forward progress data - */ - -struct progress_dwl_data { - unsigned int dwl_percent; /* % downloaded data */ - unsigned long long dwl_bytes; /* total of bytes to be downloaded */ -}; - /* * Internal SWUpdate functions to drive the progress * interface. Common progress definitions for internal diff --git a/include/progress_ipc.h b/include/progress_ipc.h index f508eda..2efa61d 100644 --- a/include/progress_ipc.h +++ b/include/progress_ipc.h @@ -27,6 +27,7 @@ struct progress_msg { unsigned int magic; /* Magic Number */ RECOVERY_STATUS status; /* Update Status (Running, Failure) */ unsigned int dwl_percent; /* % downloaded data */ + unsigned long long dwl_bytes; /* total of bytes to be downloaded */ unsigned int nsteps; /* No. total of steps */ unsigned int cur_step; /* Current step index */ unsigned int cur_percent; /* % in current step */ diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c index ecc0b40..754d56f 100644 --- a/tools/swupdate-progress.c +++ b/tools/swupdate-progress.c @@ -327,11 +327,11 @@ int main(int argc, char **argv) fill_progress_bar(bar, sizeof(bar), msg.cur_percent); if (!silent) { - fprintf(stdout, "[ %.*s ] %d of %d %d%% (%s) dwl %d%%\r", + fprintf(stdout, "[ %.*s ] %d of %d %d%% (%s), dwl %d%% of %llu bytes\r", bar_len, bar, msg.cur_step, msg.nsteps, msg.cur_percent, - msg.cur_image, msg.dwl_percent); + msg.cur_image, msg.dwl_percent, msg.dwl_bytes); fflush(stdout); }