Skip to content

Commit

Permalink
tools: move lxc-info to API symbols only
Browse files Browse the repository at this point in the history
Closes #2073.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 6, 2018
1 parent 49ac751 commit 8765242
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/lxc/tools/lxc_info.c
Expand Up @@ -21,21 +21,20 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <stdio.h>
#define _GNU_SOURCE
#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <libgen.h>
#include <sys/types.h>

#include <lxc/lxccontainer.h>

#include "lxc.h"
#include "log.h"
#include "utils.h"
#include "commands.h"
#include "arguments.h"
#include "tool_utils.h"

static bool ips;
static bool state;
Expand Down Expand Up @@ -205,7 +204,7 @@ static void print_stats(struct lxc_container *c)
char buf[4096];

ret = c->get_cgroup_item(c, "cpuacct.usage", buf, sizeof(buf));
if (ret > 0 && ret < sizeof(buf)) {
if (ret > 0 && (size_t)ret < sizeof(buf)) {
str_chomp(buf);
if (humanize) {
float seconds = strtof(buf, NULL) / 1000000000.0;
Expand All @@ -217,7 +216,7 @@ static void print_stats(struct lxc_container *c)
}

ret = c->get_cgroup_item(c, "blkio.throttle.io_service_bytes", buf, sizeof(buf));
if (ret > 0 && ret < sizeof(buf)) {
if (ret > 0 && (size_t)ret < sizeof(buf)) {
char *ch;

/* put ch on last "Total" line */
Expand Down Expand Up @@ -247,7 +246,7 @@ static void print_stats(struct lxc_container *c)

for (i = 0; lxstat[i].name; i++) {
ret = c->get_cgroup_item(c, lxstat[i].file, buf, sizeof(buf));
if (ret > 0 && ret < sizeof(buf)) {
if (ret > 0 && (size_t)ret < sizeof(buf)) {
str_chomp(buf);
str_size_humanize(buf, sizeof(buf));
printf("%-15s %s\n", lxstat[i].name, buf);
Expand Down Expand Up @@ -409,7 +408,6 @@ int main(int argc, char *argv[])

if (lxc_log_init(&log))
exit(ret);
lxc_log_options_no_override();

/* REMOVE IN LXC 3.0 */
setenv("LXC_UPDATE_CONFIG_FORMAT", "1", 0);
Expand Down
27 changes: 27 additions & 0 deletions src/lxc/tools/tool_utils.c
Expand Up @@ -823,3 +823,30 @@ void lxc_config_define_free(struct lxc_list *defines)
free(it);
}
}

int lxc_read_from_file(const char *filename, void* buf, size_t count)
{
int fd = -1, saved_errno;
ssize_t ret;

fd = open(filename, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;

if (!buf || !count) {
char buf2[100];
size_t count2 = 0;
while ((ret = read(fd, buf2, 100)) > 0)
count2 += ret;
if (ret >= 0)
ret = count2;
} else {
memset(buf, 0, count);
ret = read(fd, buf, count);
}

saved_errno = errno;
close(fd);
errno = saved_errno;
return ret;
}
1 change: 1 addition & 0 deletions src/lxc/tools/tool_utils.h
Expand Up @@ -143,6 +143,7 @@ extern char **lxc_string_split_quoted(char *string);
extern int mkdir_p(const char *dir, mode_t mode);
extern bool file_exists(const char *f);
extern int is_dir(const char *path);
extern int lxc_read_from_file(const char *filename, void* buf, size_t count);

extern char *get_template_path(const char *t);

Expand Down

0 comments on commit 8765242

Please sign in to comment.