From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NoJcwQxB; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 567325A0271 for ; Tue, 18 Nov 2025 01:20:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763425200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kkhSB8/nNXePyMEGHX9T2dw+CBVFobUSVC4YHj9Il00=; b=NoJcwQxBHkYjNDj6HikmUcFL+VUf8qNR3B0zZUIQdH4n1+Chf4DM35uyQsl0QwtvajhvfJ R0mCy76HlPHH9fkfv2b0nSo8qWYXMozIqkPDUDpqswPNJ4m3sCV5kg4/G01Djj7FQHCiLW RzuxoXfUTqt/8DU0x1gpHjPB6+R46u0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-128-qFwO-K-MOsywTwwI-0pSGQ-1; Mon, 17 Nov 2025 19:19:59 -0500 X-MC-Unique: qFwO-K-MOsywTwwI-0pSGQ-1 X-Mimecast-MFC-AGG-ID: qFwO-K-MOsywTwwI-0pSGQ_1763425198 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4779981523fso20398335e9.2 for ; Mon, 17 Nov 2025 16:19:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763425198; x=1764029998; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kkhSB8/nNXePyMEGHX9T2dw+CBVFobUSVC4YHj9Il00=; b=RT5MyxgDoEMX/3DVTHjgvjliI6RmgvjAH5RiC62RbT7uKHtNaY8wvy2Q7D7Ieixhgf 77wskLYPt/IxXxdSh6Tn199ZLL+iDBhi2mWbg4k652nL1j+zFe81hJ4xcDjB8lk9T5HY QnTD+pqstVNLrHwAghG2uFHpgyEG+VrW0pVCvhOAMydpitpHAGGQUpKAoSYS/9kxdbgP /uVraJ8iMAtNfyfHJotViNoeItbg8WzYOZ2tIDpwCwI7sh3QGoPt3bJMpkK8SYAfuOBI bmoULlWljrO8X10fL2XSu7kTwho4XliOoVxoPlC6DaGuJ8ZmyOER8EztWDKGLoK0SLUD jD5A== X-Gm-Message-State: AOJu0YxfE/WE3vxVca38laENZNcyRxjoViSaVUXhbL8WCSwgt7bYr+yF zeFwZovgGDIJnAZY5Bm3SySkVEOpnfvhRmgJCR0NnDnbKi91JcyOQ4+iVS590NK523VIeMj1V9x dhKEaq1tsqLPvhC5l/9oulKrs9QpJdNVvm3LzNQBtr+YU6q4ji/u2rg== X-Gm-Gg: ASbGncuGm8fsOSpIEmYuL7dgnkPMvD1grXreJ5C4najWUrg4wTm5cJS+VSo9UdfA0O7 7cW0sItVt3W9sORA2sqSjw4s4q4uSQFTqRZjEvo0bvpHohpwbD+Q3oDs40xdFmgB4ixfn3KiUAk oz69WKcHfzyTG6ettUXJsxG/5X/ZWlpQG7DciipMS8fzPgsBNiohk1kFtyoV/OUtLOYkA4v3i2Z wPb6F6f9LgM7tNhMNRpaMuBxtbVYnNWTrr6DpBrfSj1wW9Bpy4FMfCyCbVVya5LXGUnmhE27GN7 zt+NvJSizAT8KFKB9Ogpi8Ib971WNq0BCLjUmtXQWPK4nJ4ssPyVRSEwThLQaYO4efZNi5s2Z59 1F1ArvwcgMo5P7+fubF7cNVQ0cXILbqDzU8hiCA== X-Received: by 2002:a05:600c:1d19:b0:45d:f83b:96aa with SMTP id 5b1f17b1804b1-4778fe51e63mr122582665e9.7.1763425197676; Mon, 17 Nov 2025 16:19:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwVXYJny+f8DWIimGxYm3F/iWzLbpUhLqVDL8jwzUg+sUDOxJXlo5HAlqDy+PAJ4uL1NfgkA== X-Received: by 2002:a05:600c:1d19:b0:45d:f83b:96aa with SMTP id 5b1f17b1804b1-4778fe51e63mr122582535e9.7.1763425197279; Mon, 17 Nov 2025 16:19:57 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477a9df8db3sm3138885e9.11.2025.11.17.16.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Nov 2025 16:19:56 -0800 (PST) Date: Tue, 18 Nov 2025 01:19:55 +0100 From: Stefano Brivio To: Yumei Huang Subject: Re: [PATCH v8 2/6] util: Introduce read_file() and read_file_integer() function Message-ID: <20251118011955.635ee70c@elisabeth> In-Reply-To: References: <20251110093137.87705-1-yuhuang@redhat.com> <20251110093137.87705-3-yuhuang@redhat.com> <20251114010134.6a79cb30@elisabeth> <20251114111212.21090538@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: rGlWwzVBaMfS4Z1LpV8B-QtTZGgsFvlPP1DwnGqxc04_1763425198 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CQHWI3NFSQWCKVYQNK42V2U3SP2VKWGB X-Message-ID-Hash: CQHWI3NFSQWCKVYQNK42V2U3SP2VKWGB X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, david@gibson.dropbear.id.au X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Mon, 17 Nov 2025 09:10:01 +0800 Yumei Huang wrote: > On Fri, Nov 14, 2025 at 6:12=E2=80=AFPM Stefano Brivio wrote: > > > > On Fri, 14 Nov 2025 09:58:57 +0800 > > Yumei Huang wrote: > > =20 > > > On Fri, Nov 14, 2025 at 8:01=E2=80=AFAM Stefano Brivio wrote: =20 > > > > > > > > On Mon, 10 Nov 2025 17:31:33 +0800 > > > > Yumei Huang wrote: > > > > =20 > > > > > Signed-off-by: Yumei Huang > > > > > Reviewed-by: David Gibson > > > > > --- > > > > > util.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > > > > > util.h | 2 ++ > > > > > 2 files changed, 88 insertions(+) > > > > > > > > > > diff --git a/util.c b/util.c > > > > > index 44c21a3..c4c849c 100644 > > > > > --- a/util.c > > > > > +++ b/util.c > > > > > @@ -590,6 +590,92 @@ int write_file(const char *path, const char = *buf) > > > > > return len =3D=3D 0 ? 0 : -1; > > > > > } > > > > > > > > > > +/** > > > > > + * read_file() - Read contents of file into a NULL-terminated bu= ffer > > > > > + * @path: Path to file to read > > > > > + * @buf: Buffer to store file contents > > > > > + * @buf_size: Size of buffer > > > > > + * > > > > > + * Return: number of bytes read on success, -1 on error, -ENOBUF= S on truncation > > > > > + */ > > > > > +ssize_t read_file(const char *path, char *buf, size_t buf_size) > > > > > +{ > > > > > + int fd =3D open(path, O_RDONLY | O_CLOEXEC); > > > > > + size_t total_read =3D 0; > > > > > + ssize_t rc; > > > > > + > > > > > + if (fd < 0) { > > > > > + warn_perror("Could not open %s", path); > > > > > + return -1; > > > > > + } > > > > > + > > > > > + while (total_read < buf_size) { > > > > > + rc =3D read(fd, buf + total_read, buf_size - total_= read); =20 > > > > > > > > cppcheck rightfully says that: > > > > > > > > util.c:604:10: style: The scope of the variable 'rc' can be reduced= . [variableScope] > > > > ssize_t rc; > > > > ^ =20 > > > > > > Right. > > > Seems it also says: > > > > > > tcp.c:2814:0: style: The function 'tcp_get_rto_params' should have > > > static linkage since it is not used outside of its translation unit. > > > [staticFunction] > > > void tcp_get_rto_params(struct ctx *c) > > > ^ > > > util.c:601:0: style: The function 'read_file' should have static > > > linkage since it is not used outside of its translation unit. > > > [staticFunction] > > > ssize_t read_file(const char *path, char *buf, size_t buf_size) =20 > > > > Oops, my current version (2.16.0) doesn't say that, I should upgrade it > > (but I typically try to remain a few versions behind as David usually > > upgrades right away, so that we catch also differences). > > =20 > > > I understand read_file() may be called from other places in the > > > future. But do we need to add static now? I guess we need it for > > > tcp_get_rto_params(). =20 > > > > On top of what David said, I'm not sure if we'll ever need it in > > tcp_get_rto_params(): I guess we'll always want to read integers there.= =20 >=20 > I meant we need to add static for tcp_get_rto_params(). Ah, yes, right, that one too, it's not used outside of tcp.c (its compilation unit). --=20 Stefano