From patchwork Wed Mar 13 16:48:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu MEGE X-Patchwork-Id: 1911795 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=pwcDKe/o; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=I/NFwy2N; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13e; helo=mail-lf1-x13e.google.com; envelope-from=swupdate+bncbdmlf7xf6mjbbafsy6xqmgqew2ahhma@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lf1-x13e.google.com (mail-lf1-x13e.google.com [IPv6:2a00:1450:4864:20::13e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvxLK6smqz1ydl for ; Thu, 14 Mar 2024 03:49:12 +1100 (AEDT) Received: by mail-lf1-x13e.google.com with SMTP id 2adb3069b0e04-513b13915e7sf74725e87.1 for ; Wed, 13 Mar 2024 09:49:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710348545; cv=pass; d=google.com; s=arc-20160816; b=Qy/YDZAR55tffvk1cR4i1+wt3s7VcjPAnReCAK24qAvYo6N3bNRURCr/R5xHHETOPZ EcqHeotVYlEz2sWS7fNpwZGH5kK/f4Z9Xg5b3j89izKkXAMi1g1/CjK0ycJ5DI+/xqbp IAWsWHOph77z2EppoVGLCs1+FU6OqtYxpNoPW7CLu+SArcCRSKojRKZSoVRFMyahCCn9 wVyxXwmQ2waskB1N8fKrJaSKP6nBhDKoMOswbcEQmZr5BBLpSqPTxaCF6n5dVz86OA5S Rhn+5hIFv+gg2iVFXh4k37YMfzhW09fFVBYQgxm1Jtz1S8Ac07kjZvrLVcJhktA2AmkP 1l1A== 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:dkim-signature; bh=jsY8tGd/jgq5tz0aOyeI8gkcCI6BXj6Fz1ApZJaMZg8=; fh=H6OiRSb1p3pE/3aVy7Xum0q2Smwr16mEd1hwa7zhFvc=; b=jQHzNfIQM90ye3O0XrBIv4d07+SdNmL1JS8CCmTFHbVVJl/IPgzFrihhI3FjeapHYl FGMpEPLLN/RwGDl2gZaZY3grY98C4QHkXXuaZMKxYVVbk4pedHYQx7RwRzT9pGbrmgcp jIOmAvIPv2Pgmkz9QviP6JzEVDN87EIrbXs8Kz4v9MAfu2mm3r3k6t3yZ+AuQk3BoLfe BGph13ZMMtzp/WM8q25q3xU3aRhJu9TMC2Jh/ARMIYNrgoAKy+LBWiatH4Oaa4tM31dA 7s5BB5c6zKsYLkY8b/sr0JFaOm0OvWL64KT+0nYGqwnOV6Jm4jahr8GTr4fXKUMpspQD z/KA==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=de+NExAD; spf=pass (google.com: domain of mege.mathieu@gmail.com designates 2a00:1450:4864:20::32c as permitted sender) smtp.mailfrom=mege.mathieu@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1710348545; x=1710953345; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=jsY8tGd/jgq5tz0aOyeI8gkcCI6BXj6Fz1ApZJaMZg8=; b=pwcDKe/oxcP6OQ9khouz8AVlsAzhcFlhQyPrhJnZ7ZoqQ9hlro9DNbrnYnOsBIGPKY VPYicH1jvZJQPFL+VcQKK5MORr7pqxOqK4v1iY/dEEAZUUF9NOiKZjOHjemeBnWfqcv0 zXKT4kcvz41ZLrrvZhjmxFFjANam+1AER9d3rcD+WS9P9LFXRE84+SiEnTcrPYwmMVHI /k7kE3kUWL6cZKiIphOVERIbpypQN0JK+/K52lF1jkXuO8BP7hXOoH5gDGsSHF3q/Q4b HzBiCLwlXm7CaHIf00FCzuRFEkVbwwwzsJKeoSmTuMw1yxrf5tiYfY2dcnQgro3MXSRk yeJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710348545; x=1710953345; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=jsY8tGd/jgq5tz0aOyeI8gkcCI6BXj6Fz1ApZJaMZg8=; b=I/NFwy2NsbyyqTsGHecseXuO8qy6GvH4qmKZXF0RY3NOazmwkJp242LkAbbeR/nMQX H31DQPbQxUzyRmmxHDhkkGSg69NVYKmYad6xd7SK8PUDVbrqoNEAJmKFkCvNtzhVKXQY 8ZVqeB/4rdQuDAPndMgjRnLzrk5GFlqE9SE/xCLVzRjxNJt9IZELu3S2IxfbJ6Oz1dBo u1wmWiOKTA83IwBRGLp+PXuGyLXsYd7nn9aMIVWQPVRevPmx66oGTUNRWdNerTe4WIAL qxcyoNc/TjTbVhoXOfrYTBlN80BFMncATD8epzlMY4+lw1QgmbES8LbYc4v7FkRuSS/H 7AVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710348545; x=1710953345; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=jsY8tGd/jgq5tz0aOyeI8gkcCI6BXj6Fz1ApZJaMZg8=; b=scjJeG4T/TcG4gWH1JPg0VXF/Vifot2tBY/T2uKEBob0QNYYTsRk27HXYz9CC1Hyxk FTFstJBcEugjUshOIcl2jPmeDFvy9sWUAf4MohT+N/Z5QqxBp7JWGQLE1Sq9sVt0Uj+W RLp0iCpib4qlPZf0PS7/S4GDKO5GeYeMdMo1Kn8J+LAuZHQ7+ARmAB7QKtfi2OdrdN/u 91k5t0iJA55OdBt4OeNAUdZZwzeBL8M6+kwakiTp4TGYSPnCIlsgdghJfk9Ik73ueqOE 5GR4jA91LnMalr7cLFP5e0aD0SdtnwL3CCOgC1c4R6VaA7h2V9ZIBN7/kGdcxLlb43YS ifkg== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCU0IY8PkWaC7DDd3msusKEP2pRoyoVc3tdp4wLSvrOvQVIhj27mf8guu4M4Iwqs9aDxPwwwxx2xtQhx8MCO3PUTWmY34qEXrVEarDOUUg== X-Gm-Message-State: AOJu0YzK1uvGFqbfe2al9hp9hLNvnhX8PkHm8Cj6G0Na0N0hALqxxbZ6 DSIKVBDeMdZ04FuMuXSR4p72sJ3wuTYKTtU6DLRyAlyS//cwzO4m X-Google-Smtp-Source: AGHT+IGG6oiXxRdRhcGuoYF0/BY0/WQ6xtApkObhyMZd41xq1bbDA4mpLTuC1uqIsgDaY/gTuVVPqg== X-Received: by 2002:a05:6512:6b:b0:513:1804:9359 with SMTP id i11-20020a056512006b00b0051318049359mr2576512lfo.17.1710348544856; Wed, 13 Mar 2024 09:49:04 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:4016:b0:513:1cf6:5526 with SMTP id br22-20020a056512401600b005131cf65526ls837300lfb.0.-pod-prod-03-eu; Wed, 13 Mar 2024 09:49:02 -0700 (PDT) X-Received: by 2002:ac2:5f66:0:b0:511:49a0:200e with SMTP id c6-20020ac25f66000000b0051149a0200emr2212330lfc.37.1710348541599; Wed, 13 Mar 2024 09:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710348541; cv=none; d=google.com; s=arc-20160816; b=AGTBCZ4MWRyFQRTkWAqmIwuVJGKnh7t4UVLS8qevaIyoRS96nHRBGbcFzsAKNrEr82 jn5HkTxsAxVFimmNDtOqn60PRFS0ggi3bb2Zbk0pBZSQjcJpAIljpIJwp5wkuM7TnwSN GeT7JlFKiGhHnZ1H4Q8CXXD8HxYo2HMEmPlpczB+Ukd4ONSHDzc+Aav6yfhxzdooPcRu XE8GkN8lWjK7nYSC3YihkFnCddkeaYo7bsOgAOe01Tro2JSL6XtotpQioMXmeIn6PV1U bNNspxQaoWAmc4xJiIKBmX2dExglWkTnwYkjGllvwnqJFxiHrFtReh4Y9quUlliMTPRZ WwQA== 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:dkim-signature; bh=h50PpIlcnhtKZEZIRold9XrTOUDunsblsUtgONQoF/A=; fh=CUI1j9PdY7oRLX/gDEOzWjbkGCTMuSAa+g2jIhX+VOY=; b=IiyK3OkXWor6pGBPaIkNRPcMVlKBtURWeis8n8PTJEYFRr1V2mh3VejeXq90tXU/HE XgwxhZOqwuOSVU8/HjzauNalVcn+O2YvSgfYK8g+vL8yaicl4FqXOEe7Mhn9ND/2FULt m7LvayQPsXLsC+b44J0TFviaKI4Z+wW6IDLED3Xk8VBXItbrGd0AAjXjlWa4KayO9TM6 lNY5isAydoQTuO1fcXUSFvAHTAuxQ9izxg97FSc4E5KCwmcjbe++wTALRG4nHfYZkiRD rAJixvWzxxI/yPEtASxpOYim1q3kL+DtEvr4tttka3zJzTkGhu/r3yvgAGzMIe+/pRMV 5lYg==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=de+NExAD; spf=pass (google.com: domain of mege.mathieu@gmail.com designates 2a00:1450:4864:20::32c as permitted sender) smtp.mailfrom=mege.mathieu@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com. [2a00:1450:4864:20::32c]) by gmr-mx.google.com with ESMTPS id bi17-20020a0565120e9100b00512ee654c1csi665227lfb.10.2024.03.13.09.49.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Mar 2024 09:49:01 -0700 (PDT) Received-SPF: pass (google.com: domain of mege.mathieu@gmail.com designates 2a00:1450:4864:20::32c as permitted sender) client-ip=2a00:1450:4864:20::32c; Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-413ef6a4f4bso393715e9.0 for ; Wed, 13 Mar 2024 09:49:01 -0700 (PDT) X-Received: by 2002:a05:600c:c1b:b0:413:3761:b1b7 with SMTP id fm27-20020a05600c0c1b00b004133761b1b7mr388100wmb.20.1710348540710; Wed, 13 Mar 2024 09:49:00 -0700 (PDT) Received: from LSTA-2404.. (2a01cb09d053699a5406826d76285675.ipv6.abo.wanadoo.fr. [2a01:cb09:d053:699a:5406:826d:7628:5675]) by smtp.googlemail.com with ESMTPSA id l19-20020a05600c4f1300b004130378fb77sm2824046wmq.6.2024.03.13.09.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:49:00 -0700 (PDT) From: Mathieu Mege To: swupdate@googlegroups.com Cc: Mathieu Mege Subject: [swupdate] [PATCH] [delta_handler] Fix new zckindex read source loop Date: Wed, 13 Mar 2024 17:48:56 +0100 Message-Id: <20240313164856.171600-1-mege.mathieu@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Original-Sender: mege.mathieu@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=de+NExAD; spf=pass (google.com: domain of mege.mathieu@gmail.com designates 2a00:1450:4864:20::32c as permitted sender) smtp.mailfrom=mege.mathieu@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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: , - deal with read() return error code - add missing total bytes increment Signed-off-by: Mathieu Mege --- handlers/delta_handler.c | 53 ++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/handlers/delta_handler.c b/handlers/delta_handler.c index 295cd5f..be47244 100644 --- a/handlers/delta_handler.c +++ b/handlers/delta_handler.c @@ -45,6 +45,7 @@ #include "swupdate_image.h" #define DEFAULT_MAX_RANGES 150 /* Apache has default = 200 */ +#define BUFF_SIZE 16384 const char *handlername = "delta"; void delta_handler(void); @@ -470,34 +471,56 @@ static void zck_log_toswupdate(const char *function, zck_log_type lt, /* * Create a zck Index from a file + * + * If maxbytes has been set, it acts as a limit for the input data. + * If not (i.e. maxbytes==0), all the file/dev available data is used. */ static bool create_zckindex(zckCtx *zck, int fd, size_t maxbytes) { - const size_t bufsize = 16384; - char *buf = malloc(bufsize); - ssize_t n; - int ret; + ssize_t n = 0; + size_t count = 0; + size_t buffsize = BUFF_SIZE; + bool rstatus = true; + char *buff = NULL; - if (!buf) { + if (!(buff = (char *)malloc(BUFF_SIZE))) { ERROR("OOM creating temporary buffer"); return false; } - while ((n = read(fd, buf, bufsize)) > 0) { - ret = zck_write(zck, buf, n); - if (ret < 0) { - ERROR("ZCK returns %s", zck_get_error(zck)); - free(buf); - return false; + + do { + if((n = read(fd, buff, buffsize)) < 0) { + ERROR("Error occurred while reading data : %s", strerror(zck)); + rstatus = false; + break; } - if (maxbytes && n > maxbytes) + /* If !n following has no effect and loop will break */ + + if (zck_write(zck, buff, n) < 0) { + ERROR("ZCK returns %s", zck_get_error(zck)); + rstatus = false; break; - } + } - free(buf); + if(maxbytes) { + /* Keep count only if maxbytes has been set and it's significant*/ + count += n; - return true; + /* Stop if limit is reached*/ + if (count >= maxbytes) + break; + + /* Be sure read up to maxbytes limit next time */ + if (BUFF_SIZE > (maxbytes - count)) + buffsize = maxbytes - count; + } + } while (n); /* Keep reading until the end of file */ + + free(buff); + return rstatus; } + /* * Chunks must be retrieved from network, prepare an send * a request for the downloader