[systemd-commits] fixme src/random-seed.c
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Aug 18 08:40:53 PDT 2010
fixme | 10 ++++++++++
src/random-seed.c | 30 +++++++++++++++++++++++++-----
2 files changed, 35 insertions(+), 5 deletions(-)
New commits:
commit 26192dfc21a9020564e6db5c1dd9d49ecc70c0d7
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Aug 18 19:38:45 2010 +0200
random-seed: honour kernel pool size when saving/restoring seed
diff --git a/fixme b/fixme
index 404ed0f..c016e94 100644
--- a/fixme
+++ b/fixme
@@ -61,8 +61,18 @@
* decode exit codes in systemctl status
+* systemctl: ln -s output muss abschaltbar sein, und warning wenn [Install] leer ist.
+
+* /etc/modules.d/*.modules in systemd-modules-load
+
+* X-Interactive is kaputt
+
+* universal fallback for hostname
+
External:
+* procps, psmisc, sysvinit-tools, hostname â util-linux-ng
+
* nologin nach /var/run https://bugzilla.redhat.com/show_bug.cgi?id=624489
* make sysinit honour forcefsck/fastboot from the kernel command line fsck.mode=auto|force|skip
diff --git a/src/random-seed.c b/src/random-seed.c
index b9cafb7..586c698 100644
--- a/src/random-seed.c
+++ b/src/random-seed.c
@@ -28,11 +28,15 @@
#include "log.h"
#include "util.h"
+#define POOL_SIZE_MIN 512
+
int main(int argc, char *argv[]) {
int seed_fd = -1, random_fd = -1;
int ret = 1;
- uint8_t buf[512];
+ void* buf;
+ size_t buf_size = 0;
ssize_t r;
+ FILE *f;
if (argc != 2) {
log_error("This program requires one argument.");
@@ -43,6 +47,20 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
+ /* Read pool size, if possible */
+ if ((f = fopen("/proc/sys/kernel/random/poolsize", "re"))) {
+ fscanf(f, "%zu", &buf_size);
+ fclose(f);
+ }
+
+ if (buf_size <= POOL_SIZE_MIN)
+ buf_size = POOL_SIZE_MIN;
+
+ if (!(buf = malloc(buf_size))) {
+ log_error("Failed to allocate buffer.");
+ goto finish;
+ }
+
/* When we load the seed we read it and write it to the device
* and then immediately update the saved seed with new data,
* to make sure the next boot gets seeded differently. */
@@ -63,12 +81,12 @@ int main(int argc, char *argv[]) {
}
}
- if ((r = loop_read(seed_fd, buf, sizeof(buf), false)) != sizeof(buf))
+ if ((r = loop_read(seed_fd, buf, buf_size, false)) <= 0)
log_error("Failed to read seed file: %s", r < 0 ? strerror(errno) : "EOF");
else {
lseek(seed_fd, 0, SEEK_SET);
- if ((r = loop_write(random_fd, buf, sizeof(buf), false)) != sizeof(buf))
+ if ((r = loop_write(random_fd, buf, (size_t) r, false)) <= 0)
log_error("Failed to write seed to /dev/random: %s", r < 0 ? strerror(errno) : "short write");
}
@@ -94,10 +112,10 @@ int main(int argc, char *argv[]) {
fchmod(seed_fd, 0600);
fchown(seed_fd, 0, 0);
- if ((r = loop_read(random_fd, buf, sizeof(buf), false)) != sizeof(buf))
+ if ((r = loop_read(random_fd, buf, buf_size, false)) <= 0)
log_error("Failed to read new seed from /dev/urandom: %s", r < 0 ? strerror(errno) : "EOF");
else {
- if ((r = loop_write(seed_fd, buf, sizeof(buf), false)) != sizeof(buf))
+ if ((r = loop_write(seed_fd, buf, (size_t) r, false)) <= 0)
log_error("Failed to write new random seed file: %s", r < 0 ? strerror(errno) : "short write");
}
@@ -110,5 +128,7 @@ finish:
if (seed_fd >= 0)
close_nointr_nofail(seed_fd);
+ free(buf);
+
return ret;
}
More information about the systemd-commits
mailing list