aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-06-24 12:17:31 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-07-06 08:10:55 +0200
commitcf83df45744763e2802db73002b9031fa9b5e235 (patch)
tree031a34dd1c13f5268f0136e6a063d3a7d0d8ce1b /util.c
parentc589917e7152dd2ed6eb4e63bfdd5c98ee94e00b (diff)
downloadpasst-cf83df45744763e2802db73002b9031fa9b5e235.tar
passt-cf83df45744763e2802db73002b9031fa9b5e235.tar.gz
passt-cf83df45744763e2802db73002b9031fa9b5e235.tar.bz2
passt-cf83df45744763e2802db73002b9031fa9b5e235.tar.lz
passt-cf83df45744763e2802db73002b9031fa9b5e235.tar.xz
passt-cf83df45744763e2802db73002b9031fa9b5e235.tar.zst
passt-cf83df45744763e2802db73002b9031fa9b5e235.zip
Use new lineread implementation for procfs_scan_listen()
Use the new more solid implementation of line by line reading for procfs_scan_listen(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files 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"
/* 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 = open(path, O_RDONLY | O_CLOEXEC)) < 0)
return;
- *line = 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): != 2 if conversion fails */
if (sscanf(line, "%*u: %*x:%lx %*x:%*x %x", &port, &state) != 2)
continue;