From a6dcc7e5924f9c27d3e9c6560a448b02ec28b65f Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mon, 9 Mar 2015 21:23:53 -0400 Subject: Introduce loop_read_exact helper Usually when using loop_read(), we want to read the full buffer. Add a helper that mirrors loop_write(), and returns 0 when full buffer was read, and an error otherwise. Use -ENODATA for the short read, to distinguish it from a read error. --- src/core/automount.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/core/automount.c') diff --git a/src/core/automount.c b/src/core/automount.c index 0539fbbc41..cec90cbb31 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -725,7 +725,6 @@ static bool automount_check_gc(Unit *u) { static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, void *userdata) { union autofs_v5_packet_union packet; Automount *a = AUTOMOUNT(userdata); - ssize_t l; int r; assert(a); @@ -736,12 +735,9 @@ static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, vo goto fail; } - l = loop_read(a->pipe_fd, &packet, sizeof(packet), true); - if (l != sizeof(packet)) { - if (l < 0) - log_unit_error_errno(UNIT(a)->id, l, "Invalid read from pipe: %m"); - else - log_unit_error(UNIT(a)->id, "Invalid read from pipe: short read"); + r = loop_read_exact(a->pipe_fd, &packet, sizeof(packet), true); + if (r < 0) { + log_unit_error_errno(UNIT(a)->id, r, "Invalid read from pipe: %m"); goto fail; } -- cgit v1.2.3-54-g00ecf