]> git.proxmox.com Git - lxcfs.git/blame - debian/patches/0004-uptime-fix-a-problem-with-subsequent-reads.patch
build: reformat debian/control
[lxcfs.git] / debian / patches / 0004-uptime-fix-a-problem-with-subsequent-reads.patch
CommitLineData
f4a06351
WB
1From b0e5eb8fd812da9307a40604b6dea8ab17b55785 Mon Sep 17 00:00:00 2001
2From: Bernhard Miklautz <bernhard.miklautz@shacknet.at>
3Date: Thu, 3 Aug 2017 13:37:37 +0200
4Subject: [PATCH lxcfs 4/4] uptime: fix a problem with subsequent reads.
5
6When doing subsequent reads of uptime on an open file handle
7in the form:
8
9read
10lseek 0L, SEEK_SET
11read
12
13the second (and later) reads cause that the error
14"failed to write to cache" was printed. This
15happens for example with "top". top would print the error:
16
17bad data in /proc/uptime
18
19To fix this problem use the whole size of the buffer instead of the d->size
20because this is set on the first read.
21
22This behavior was introduced with commit 0ecddf023a4caf8e8d2fe7e9125d777a06c5ec12.
23
24Signed-off-by: Bernhard Miklautz <bernhard.miklautz@shacknet.at>
25---
26 bindings.c | 8 ++++----
27 1 file changed, 4 insertions(+), 4 deletions(-)
28
29diff --git a/bindings.c b/bindings.c
30index 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--
582.11.0
59