summaryrefslogtreecommitdiff
path: root/src/random-seed
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/random-seed
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/random-seed')
-rw-r--r--src/random-seed/random-seed.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c
index 40eaaf46d9..06c1239601 100644
--- a/src/random-seed/random-seed.c
+++ b/src/random-seed/random-seed.c
@@ -113,12 +113,9 @@ int main(int argc, char *argv[]) {
} else {
lseek(seed_fd, 0, SEEK_SET);
- k = loop_write(random_fd, buf, (size_t) k, false);
- if (k <= 0) {
- log_error("Failed to write seed to /dev/urandom: %s", r < 0 ? strerror(-r) : "short write");
-
- r = k == 0 ? -EIO : (int) k;
- }
+ r = loop_write(random_fd, buf, (size_t) k, false);
+ if (r < 0)
+ log_error_errno(r, "Failed to write seed to /dev/urandom: %m");
}
} else if (streq(argv[1], "save")) {
@@ -155,10 +152,8 @@ int main(int argc, char *argv[]) {
r = k == 0 ? -EIO : (int) k;
} else {
r = loop_write(seed_fd, buf, (size_t) k, false);
- if (r <= 0) {
- log_error("Failed to write new random seed file: %s", r < 0 ? strerror(-r) : "short write");
- r = r == 0 ? -EIO : r;
- }
+ if (r < 0)
+ log_error_errno(r, "Failed to write new random seed file: %m");
}
finish: