diff options
author | Alexander Sverdlin <alexander.sverdlin@gmail.com> | 2015-03-29 20:46:42 +0200 |
---|---|---|
committer | Daniel Mack <daniel@zonque.org> | 2015-03-30 09:38:17 +0200 |
commit | c87664fef45fc1dadc2303675ed357e0dde61db9 (patch) | |
tree | 4a6f538c9a52225eac70d899a9d09eb34f554042 /src/bootchart | |
parent | 58ec01b35c046f5f167763343514c20170bfd2eb (diff) |
systemd-bootchart: Repair Entropy Graph
Entropy Graph code doesn't handle the error condition if open() of /proc entry
fails. Moreover, the file is only opened once and only first sample will contain
the correct value because the return value of pread() is also not handled
properly and file is not re-opened. Fix both problems.
Diffstat (limited to 'src/bootchart')
-rw-r--r-- | src/bootchart/store.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/bootchart/store.c b/src/bootchart/store.c index 8e9a62f91d..fb3dc9ad6e 100644 --- a/src/bootchart/store.c +++ b/src/bootchart/store.c @@ -119,7 +119,7 @@ void log_sample(int sample, struct list_sample_data **ptr) { int c; int p; int mod; - static int e_fd; + static int e_fd = -1; ssize_t s; ssize_t n; struct dirent *ent; @@ -215,16 +215,21 @@ schedstat_next: } if (arg_entropy) { - if (!e_fd) { + if (e_fd < 0) { e_fd = openat(procfd, "sys/kernel/random/entropy_avail", O_RDONLY); + if (e_fd == -1) { + log_error_errno(errno, "Failed to open /proc/sys/kernel/random/entropy_avail: %m"); + exit(EXIT_FAILURE); + } } - if (e_fd) { - n = pread(e_fd, buf, sizeof(buf) - 1, 0); - if (n > 0) { - buf[n] = '\0'; - sampledata->entropy_avail = atoi(buf); - } + n = pread(e_fd, buf, sizeof(buf) - 1, 0); + if (n <= 0) { + close(e_fd); + e_fd = -1; + } else { + buf[n] = '\0'; + sampledata->entropy_avail = atoi(buf); } } |