diff options
author | Thomas Haller <thaller@redhat.com> | 2020-04-06 12:54:30 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-04-10 10:44:50 +0200 |
commit | 2384033b05b7944a776e41b4ebfdef082ab0e04d (patch) | |
tree | 709025f4a4fff6113285f82a37dcc21d13e5a873 | |
parent | 8c637e693aa81f0479ade7db7e5d412602a623ba (diff) | |
download | NetworkManager-2384033b05b7944a776e41b4ebfdef082ab0e04d.tar.gz |
shared: fix returning EAGAIN from nm_utils_fd_read()
We cannot just swallow EAGAIN and pretend that not bytes were read.
read() returning zero means end of file. The caller needs to distinguish
between end of file and EAGAIN.
-rw-r--r-- | shared/nm-glib-aux/nm-io-utils.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/shared/nm-glib-aux/nm-io-utils.c b/shared/nm-glib-aux/nm-io-utils.c index 7716cc39d0..9620c688df 100644 --- a/shared/nm-glib-aux/nm-io-utils.c +++ b/shared/nm-glib-aux/nm-io-utils.c @@ -434,13 +434,11 @@ nm_utils_fd_read (int fd, GString *out_string) g_string_set_size (out_string, start_len + 1024); n_read = read (fd, &out_string->str[start_len], 1024); - if (n_read < 0) { - if (errno != EAGAIN) { - return -NM_ERRNO_NATIVE (errno); - } - n_read = 0; - } else { - g_string_set_size (out_string, start_len + n_read); - } + if (n_read < 0) + return -NM_ERRNO_NATIVE (errno); + + if (n_read > 0) + g_string_set_size (out_string, start_len + (gsize) n_read); + return n_read; } |