Commit 70f7755e by Daniel Lezcano Committed by Daniel Lezcano

Fix lxc-cgroup-get

Make lxc_cgroup_get returns the number of bytes read and use this value to "printf" it. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent b333f86e
...@@ -198,13 +198,10 @@ int lxc_cgroup_get(const char *name, const char *subsystem, ...@@ -198,13 +198,10 @@ int lxc_cgroup_get(const char *name, const char *subsystem,
return -1; return -1;
} }
if (read(fd, value, len) < 0) { ret = read(fd, value, len);
if (ret < 0)
ERROR("read %s : %s", path, strerror(errno)); ERROR("read %s : %s", path, strerror(errno));
goto out;
}
ret = 0;
out:
close(fd); close(fd);
return ret; return ret;
} }
...@@ -164,7 +164,7 @@ extern int lxc_cgroup_set(const char *name, const char *subsystem, const char *v ...@@ -164,7 +164,7 @@ extern int lxc_cgroup_set(const char *name, const char *subsystem, const char *v
* @subsystem : the subsystem * @subsystem : the subsystem
* @value : the value to be set * @value : the value to be set
* @len : the len of the value variable * @len : the len of the value variable
* Returns 0 on success, < 0 otherwise * Returns the number of bytes read, < 0 on error
*/ */
extern int lxc_cgroup_get(const char *name, const char *subsystem, extern int lxc_cgroup_get(const char *name, const char *subsystem,
char *value, size_t len); char *value, size_t len);
......
...@@ -83,14 +83,17 @@ int main(int argc, char *argv[]) ...@@ -83,14 +83,17 @@ int main(int argc, char *argv[])
} }
} else { } else {
const unsigned long len = 4096; const unsigned long len = 4096;
int ret;
char buffer[len]; char buffer[len];
if (lxc_cgroup_get(my_args.name, subsystem, buffer, len)) {
ret = lxc_cgroup_get(my_args.name, subsystem, buffer, len);
if (ret < 0) {
ERROR("failed to retrieve value of '%s' for '%s'", ERROR("failed to retrieve value of '%s' for '%s'",
subsystem, my_args.name); subsystem, my_args.name);
return -1; return -1;
} }
printf("%s", buffer); printf("%*s", ret, buffer);
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment