From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH v2 3/4] Use new lineread implementation for procfs_scan_listen() Date: Fri, 24 Jun 2022 12:17:31 +1000 Message-ID: <20220624021732.4062212-4-david@gibson.dropbear.id.au> In-Reply-To: <20220624021732.4062212-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1546240715330804483==" --===============1546240715330804483== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Use the new more solid implementation of line by line reading for procfs_scan_listen(). Signed-off-by: David Gibson --- util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util.c b/util.c index 7ffd9d1..83729d2 100644 --- a/util.c +++ b/util.c @@ -41,6 +41,7 @@ #include "util.h" #include "passt.h" #include "packet.h" +#include "lineread.h" =20 /* For __openlog() and __setlogmask() wrappers, and passt_vsyslog() */ static int log_mask; @@ -476,7 +477,8 @@ char *line_read(char *buf, size_t len, int fd) void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, int ns, uint8_t *map, uint8_t *exclude) { - char line[BUFSIZ], *path; + char *path, *line; + struct lineread lr; unsigned long port; unsigned int state; int *fd; @@ -500,9 +502,9 @@ void procfs_scan_listen(struct ctx *c, uint8_t proto, int= ip_version, int ns, else if ((*fd =3D open(path, O_RDONLY | O_CLOEXEC)) < 0) return; =20 - *line =3D 0; - line_read(line, sizeof(line), *fd); - while (line_read(line, sizeof(line), *fd)) { + lineread_init(&lr, *fd); + lineread_get(&lr, &line); /* throw away header */ + while (lineread_get(&lr, &line) > 0) { /* NOLINTNEXTLINE(cert-err34-c): !=3D 2 if conversion fails */ if (sscanf(line, "%*u: %*x:%lx %*x:%*x %x", &port, &state) !=3D 2) continue; --=20 2.36.1 --===============1546240715330804483==--