static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
Spawn *spawn = userdata;
char buf[4096], *p;
+ bool full = false;
size_t size;
ssize_t l;
int r;
size = sizeof(buf);
}
- l = read(fd, p, size - 1);
+ l = read(fd, p, size - (p == buf));
if (l < 0) {
if (errno == EAGAIN)
goto reenable;
return 0;
}
+ if ((size_t) l == size) {
+ log_device_warning(spawn->device, "Truncating stdout of '%s' up to %zu byte.",
+ spawn->cmd, spawn->result_size);
+ l--;
+ full = true;
+ }
+
p[l] = '\0';
if (fd == spawn->fd_stdout && spawn->result)
spawn->result_len += l;
fd == spawn->fd_stdout ? "out" : "err", *q);
}
- if (l == 0)
+ if (l == 0 || full)
return 0;
reenable: