summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-12-01 20:43:19 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-12-09 21:36:08 -0500
commit553acb7b6b8d4f16a4747b1f978e8b7888fbfb2c (patch)
treeb9a473c853c616b256ed3ea1dc5f8e9c7838b289 /src/journal
parentcb01aedc3b4ba70859267159fe716253e3551ec6 (diff)
treewide: sanitize loop_write
loop_write() didn't follow the usual systemd rules and returned status partially in errno and required extensive checks from callers. Some of the callers dealt with this properly, but many did not, treating partial writes as successful. Simplify things by conforming to usual rules.
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/compress.c11
-rw-r--r--src/journal/journal-send.c5
-rw-r--r--src/journal/journalctl.c14
3 files changed, 7 insertions, 23 deletions
diff --git a/src/journal/compress.c b/src/journal/compress.c
index c4c715be2f..9440fcd60e 100644
--- a/src/journal/compress.c
+++ b/src/journal/compress.c
@@ -400,12 +400,9 @@ int compress_stream_xz(int fdf, int fdt, off_t max_bytes) {
n = sizeof(out) - s.avail_out;
- errno = 0;
k = loop_write(fdt, out, n, false);
if (k < 0)
return k;
- if (k != n)
- return errno ? -errno : -EIO;
if (ret == LZMA_STREAM_END) {
log_debug("XZ compression finished (%"PRIu64" -> %"PRIu64" bytes, %.1f%%)",
@@ -478,8 +475,6 @@ int compress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
n = loop_write(fdt, out, r, false);
if (n < 0)
return n;
- if (n != r)
- return errno ? -errno : -EIO;
total_out += sizeof(header) + r;
@@ -559,12 +554,9 @@ int decompress_stream_xz(int fdf, int fdt, off_t max_bytes) {
max_bytes -= n;
}
- errno = 0;
k = loop_write(fdt, out, n, false);
if (k < 0)
return k;
- if (k != n)
- return errno ? -errno : -EIO;
if (ret == LZMA_STREAM_END) {
log_debug("XZ decompression finished (%"PRIu64" -> %"PRIu64" bytes, %.1f%%)",
@@ -645,12 +637,9 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
return -EFBIG;
}
- errno = 0;
n = loop_write(fdt, out, r, false);
if (n < 0)
return n;
- if (n != r)
- return errno ? -errno : -EIO;
}
log_debug("LZ4 decompression finished (%zu -> %zu bytes, %.1f%%)",
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index 887b957c4d..56a96c55dd 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -453,13 +453,10 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve
header[l++] = '0';
header[l++] = '\n';
- r = (int) loop_write(fd, header, l, false);
+ r = loop_write(fd, header, l, false);
if (r < 0)
return r;
- if ((size_t) r != l)
- return -errno;
-
r = fd;
fd = -1;
return r;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 3cec9a0c84..b2f6966fca 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1406,17 +1406,15 @@ static int setup_keys(void) {
h.fsprg_secpar = htole16(FSPRG_RECOMMENDED_SECPAR);
h.fsprg_state_size = htole64(state_size);
- l = loop_write(fd, &h, sizeof(h), false);
- if (l < 0 || (size_t) l != sizeof(h)) {
- log_error_errno(EIO, "Failed to write header: %m");
- r = -EIO;
+ r = loop_write(fd, &h, sizeof(h), false);
+ if (r < 0) {
+ log_error_errno(r, "Failed to write header: %m");
goto finish;
}
- l = loop_write(fd, state, state_size, false);
- if (l < 0 || (size_t) l != state_size) {
- log_error_errno(EIO, "Failed to write state: %m");
- r = -EIO;
+ r = loop_write(fd, state, state_size, false);
+ if (r < 0) {
+ log_error_errno(r, "Failed to write state: %m");
goto finish;
}