[lxc-devel] [lxcfs/master] bugfixes
brauner on Github
lxc-bot at linuxcontainers.org
Mon Apr 25 11:46:09 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 605 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160425/bb8beff5/attachment.bin>
-------------- next part --------------
From 352980a760536c0b59ae225991739cfb5cf83e64 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at mailbox.org>
Date: Mon, 25 Apr 2016 13:42:45 +0200
Subject: [PATCH] bugfixes
- fix do_mount_cgroups(): it previously returned ret uninitialized on failure
- snprintf() returns -1 on error so let's use ssize_t whenever possible
- use additional ssize_t variable to catch snprintf() error for swap
calculation
Signed-off-by: Christian Brauner <christian.brauner at mailbox.org>
---
bindings.c | 26 ++++++++++++++------------
lxcfs.c | 2 +-
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/bindings.c b/bindings.c
index 5393cdc..a90d808 100644
--- a/bindings.c
+++ b/bindings.c
@@ -2865,7 +2865,7 @@ static int read_file(const char *path, char *buf, size_t size,
return 0;
while (getline(&line, &linelen, f) != -1) {
- size_t l = snprintf(cache, cache_size, "%s", line);
+ ssize_t l = snprintf(cache, cache_size, "%s", line);
if (l < 0) {
perror("Error writing to cache");
rv = 0;
@@ -3003,7 +3003,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
goto err;
while (getline(&line, &linelen, f) != -1) {
- size_t l;
+ ssize_t l;
char *printme, lbuf[100];
memset(lbuf, 0, 100);
@@ -3158,7 +3158,7 @@ static int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
goto err;
while (getline(&line, &linelen, f) != -1) {
- size_t l;
+ ssize_t l;
if (firstline) {
firstline = false;
if (strstr(line, "IBM/S390") != NULL) {
@@ -3235,7 +3235,7 @@ static int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
if (is_s390x) {
char *origcache = d->buf;
- size_t l;
+ ssize_t l;
do {
d->buf = malloc(d->buflen);
} while (!d->buf);
@@ -3335,7 +3335,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
}
while (getline(&line, &linelen, f) != -1) {
- size_t l;
+ ssize_t l;
int cpu;
char cpu_char[10]; /* That's a lot of cores */
char *c;
@@ -3507,7 +3507,7 @@ static int proc_uptime_read(char *buf, size_t size, off_t offset,
long int reaperage = getreaperage(fc->pid);
unsigned long int busytime = get_reaper_busy(fc->pid), idletime;
char *cache = d->buf;
- size_t total_len = 0;
+ ssize_t total_len = 0;
#if RELOADTEST
iwashere();
@@ -3602,7 +3602,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
goto err;
while (getline(&line, &linelen, f) != -1) {
- size_t l;
+ ssize_t l;
char lbuf[256];
i = sscanf(line, "%u %u %71s", &major, &minor, dev_name);
@@ -3685,7 +3685,8 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
char *memswlimit_str = NULL, *memlimit_str = NULL, *memusage_str = NULL, *memswusage_str = NULL,
*memswlimit_default_str = NULL, *memswusage_default_str = NULL;
unsigned long memswlimit = 0, memlimit = 0, memusage = 0, memswusage = 0, swap_total = 0, swap_free = 0;
- size_t total_len = 0, rv = 0;
+ ssize_t total_len = 0, rv = 0;
+ ssize_t l = 0;
char *cache = d->buf;
if (offset) {
@@ -3761,12 +3762,13 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset,
}
if (swap_total > 0) {
- total_len += snprintf(d->buf + total_len, d->size - total_len,
- "none%*svirtual\t\t%lu\t%lu\t0\n", 36, " ",
- swap_total, swap_free);
+ l = snprintf(d->buf + total_len, d->size - total_len,
+ "none%*svirtual\t\t%lu\t%lu\t0\n", 36, " ",
+ swap_total, swap_free);
+ total_len += l;
}
- if (total_len < 0) {
+ if (total_len < 0 || l < 0) {
perror("Error writing to cache");
rv = 0;
goto err;
diff --git a/lxcfs.c b/lxcfs.c
index 6f37052..7455267 100644
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -836,7 +836,7 @@ static bool do_mount_cgroup(char *controller)
static bool do_mount_cgroups(void)
{
- bool ret;
+ bool ret = false;
FILE *f;
char *line = NULL;
size_t len = 0;
More information about the lxc-devel
mailing list