[lxc-devel] [lxcfs/master] {pam_cgfs, bindings}: bugfixes
brauner on Github
lxc-bot at linuxcontainers.org
Sat Mar 11 15:17:25 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 302 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170311/f87d095d/attachment.bin>
-------------- next part --------------
From e4992b3e567d8aefaaa3c9e24726b723d120bfe0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 11 Mar 2017 13:58:10 +0100
Subject: [PATCH 1/3] pam_cgfs: error out on failure in cgv2_init()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
pam/pam_cgfs.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/pam/pam_cgfs.c b/pam/pam_cgfs.c
index e5818f9..fc21c45 100644
--- a/pam/pam_cgfs.c
+++ b/pam/pam_cgfs.c
@@ -1322,10 +1322,12 @@ static bool cgv2_init(uid_t uid, gid_t gid)
char *current_cgroup = NULL, *init_cgroup = NULL;
char * line = NULL;
size_t len = 0;
+ int ret = false;
current_cgroup = cgv2_get_current_cgroup(getpid());
if (!current_cgroup) {
/* No v2 hierarchy present. We're done. */
+ ret = true;
goto cleanup;
}
@@ -1358,12 +1360,13 @@ static bool cgv2_init(uid_t uid, gid_t gid)
cgv2_add_controller(NULL, mountpoint, current_cgroup, init_cgroup, has_user_slice);
+ ret = true;
goto cleanup;
}
f = fopen("/proc/self/mountinfo", "r");
if (!f)
- return false;
+ goto cleanup;
/* we support simple cgroup mounts and lxcfs mounts */
while (getline(&line, &len, f) != -1) {
@@ -1398,7 +1401,7 @@ static bool cgv2_init(uid_t uid, gid_t gid)
fclose(f);
free(line);
- return true;
+ return ret;
}
/* Detect and store information about mounted cgroupfs v1 hierarchies and the
From 3acf9e941a368d8255c6740b8ef4a593a5b759cd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 11 Mar 2017 14:04:47 +0100
Subject: [PATCH 2/3] pam_cgfs: remove dead assignment
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
pam/pam_cgfs.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/pam/pam_cgfs.c b/pam/pam_cgfs.c
index fc21c45..4c163db 100644
--- a/pam/pam_cgfs.c
+++ b/pam/pam_cgfs.c
@@ -1659,7 +1659,7 @@ static char *string_join(const char *sep, const char **parts, bool use_as_prefix
for (p = (char **)parts; *p; p++)
result_len += (p > (char **)parts) * sep_len + strlen(*p);
- result = calloc(result_len + 1, 1);
+ result = calloc(result_len + 1, sizeof(char));
if (!result)
return NULL;
@@ -2101,8 +2101,6 @@ static bool cgv1_create_one(struct cgv1_hierarchy *h, const char *cgroup, uid_t
it = h;
for (controller = it->controllers; controller && *controller;
controller++) {
- created = false;
-
if (!cgv1_handle_cpuset_hierarchy(it, cgroup))
return false;
From 3ad9890021b24e76dc30099b3cc0642526484ae6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 11 Mar 2017 14:51:58 +0100
Subject: [PATCH 3/3] bindings: implement guest nice
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
bindings.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/bindings.c b/bindings.c
index 97a2164..ce7e70c 100644
--- a/bindings.c
+++ b/bindings.c
@@ -3485,7 +3485,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
char *line = NULL;
size_t linelen = 0, total_len = 0, rv = 0;
int curcpu = -1; /* cpu numbering starts at 0 */
- unsigned long user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0, softirq = 0, steal = 0, guest = 0;
+ unsigned long user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0, softirq = 0, steal = 0, guest = 0, guest_nice = 0;
unsigned long user_sum = 0, nice_sum = 0, system_sum = 0, idle_sum = 0, iowait_sum = 0,
irq_sum = 0, softirq_sum = 0, steal_sum = 0, guest_sum = 0;
#define CPUALL_MAX_SIZE BUF_RESERVE_SIZE
@@ -3584,8 +3584,17 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
cache_size -= l;
total_len += l;
- if (sscanf(line, "%*s %lu %lu %lu %lu %lu %lu %lu %lu %lu", &user, &nice, &system, &idle, &iowait, &irq,
- &softirq, &steal, &guest) != 9)
+ if (sscanf(line, "%*s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
+ &user,
+ &nice,
+ &system,
+ &idle,
+ &iowait,
+ &irq,
+ &softirq,
+ &steal,
+ &guest,
+ &guest_nice) != 10)
continue;
user_sum += user;
nice_sum += nice;
@@ -3596,16 +3605,26 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
softirq_sum += softirq;
steal_sum += steal;
guest_sum += guest;
+ guest_nice_sum += guest_nice;
}
cache = d->buf;
- int cpuall_len = snprintf(cpuall, CPUALL_MAX_SIZE, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
- "cpu ", user_sum, nice_sum, system_sum, idle_sum, iowait_sum, irq_sum, softirq_sum, steal_sum, guest_sum);
- if (cpuall_len > 0 && cpuall_len < CPUALL_MAX_SIZE){
+ int cpuall_len = snprintf(cpuall, CPUALL_MAX_SIZE, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
+ user_sum,
+ nice_sum,
+ system_sum,
+ idle_sum,
+ iowait_sum,
+ irq_sum,
+ softirq_sum,
+ steal_sum,
+ guest_sum,
+ guest_nice_sum);
+ if (cpuall_len > 0 && cpuall_len < CPUALL_MAX_SIZE) {
memcpy(cache, cpuall, cpuall_len);
cache += cpuall_len;
- } else{
+ } else {
/* shouldn't happen */
lxcfs_error("proc_stat_read copy cpuall failed, cpuall_len=%d.", cpuall_len);
cpuall_len = 0;
@@ -3615,7 +3634,8 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
total_len += cpuall_len;
d->cached = 1;
d->size = total_len;
- if (total_len > size ) total_len = size;
+ if (total_len > size)
+ total_len = size;
memcpy(buf, d->buf, total_len);
rv = total_len;
More information about the lxc-devel
mailing list