Skip to content

Commit

Permalink
Merge branch 'PR/libmount-fix-mesg' of github.com:karelzak/util-linux…
Browse files Browse the repository at this point in the history
…-work

* 'PR/libmount-fix-mesg' of github.com:karelzak/util-linux-work:
  libmount: improving robustness in reading kernel messages
  • Loading branch information
karelzak committed Jun 20, 2024
2 parents 2d965d5 + 0389a9e commit b8a1e1f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions libmount/src/hook_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ static void save_fd_messages(struct libmnt_context *cxt, int fd)

mnt_context_set_errmsg(cxt, NULL);

while ((rc = read(fd, buf, sizeof(buf))) != -1) {
if (rc > 0 && buf[rc - 1] == '\n')
buf[rc - 1] = '\0';
while ((rc = read(fd, buf, sizeof(buf) - 1)) != -1) {

if (rc == 0)
continue;
if (buf[rc - 1] == '\n')
buf[--rc] = '\0';
else
buf[rc] = '\0';

DBG(CXT, ul_debug("message from kernel: \"%*s\"", rc, buf));

if (rc < 3 || strncmp((char *) buf, "e ", 2) != 0)
Expand Down

0 comments on commit b8a1e1f

Please sign in to comment.