]>
Commit | Line | Data |
---|---|---|
f4a06351 WB |
1 | From b0e5eb8fd812da9307a40604b6dea8ab17b55785 Mon Sep 17 00:00:00 2001 |
2 | From: Bernhard Miklautz <bernhard.miklautz@shacknet.at> | |
3 | Date: Thu, 3 Aug 2017 13:37:37 +0200 | |
4 | Subject: [PATCH lxcfs 4/4] uptime: fix a problem with subsequent reads. | |
5 | ||
6 | When doing subsequent reads of uptime on an open file handle | |
7 | in the form: | |
8 | ||
9 | read | |
10 | lseek 0L, SEEK_SET | |
11 | read | |
12 | ||
13 | the second (and later) reads cause that the error | |
14 | "failed to write to cache" was printed. This | |
15 | happens for example with "top". top would print the error: | |
16 | ||
17 | bad data in /proc/uptime | |
18 | ||
19 | To fix this problem use the whole size of the buffer instead of the d->size | |
20 | because this is set on the first read. | |
21 | ||
22 | This behavior was introduced with commit 0ecddf023a4caf8e8d2fe7e9125d777a06c5ec12. | |
23 | ||
24 | Signed-off-by: Bernhard Miklautz <bernhard.miklautz@shacknet.at> | |
25 | --- | |
26 | bindings.c | 8 ++++---- | |
27 | 1 file changed, 4 insertions(+), 4 deletions(-) | |
28 | ||
29 | diff --git a/bindings.c b/bindings.c | |
30 | index 9aa884a..114e694 100644 | |
31 | --- a/bindings.c | |
32 | +++ b/bindings.c | |
33 | @@ -3842,10 +3842,10 @@ static int proc_uptime_read(char *buf, size_t size, off_t offset, | |
34 | #endif | |
35 | ||
36 | if (offset){ | |
37 | - if (offset > d->size) | |
38 | - return -EINVAL; | |
39 | if (!d->cached) | |
40 | return 0; | |
41 | + if (offset > d->size) | |
42 | + return -EINVAL; | |
43 | int left = d->size - offset; | |
44 | total_len = left > size ? size: left; | |
45 | memcpy(buf, cache + offset, total_len); | |
46 | @@ -3860,8 +3860,8 @@ static int proc_uptime_read(char *buf, size_t size, off_t offset, | |
47 | if (reaperage >= busytime) | |
48 | idletime = reaperage - busytime; | |
49 | ||
50 | - total_len = snprintf(d->buf, d->size, "%"PRIu64".00 %"PRIu64".00\n", reaperage, idletime); | |
51 | - if (total_len < 0 || total_len >= d->size){ | |
52 | + total_len = snprintf(d->buf, d->buflen, "%"PRIu64".00 %"PRIu64".00\n", reaperage, idletime); | |
53 | + if (total_len < 0 || total_len >= d->buflen){ | |
54 | lxcfs_error("%s\n", "failed to write to cache"); | |
55 | return 0; | |
56 | } | |
57 | -- | |
58 | 2.11.0 | |
59 |