]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: move lxc-info to API symbols only
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 12 Jan 2018 14:36:15 +0000 (15:36 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 6 Feb 2018 20:10:48 +0000 (21:10 +0100)
Closes #2073.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/tools/lxc_info.c
src/lxc/tools/tool_utils.c
src/lxc/tools/tool_utils.h

index 3c7f6b39881877a1654ec11365df4653d88a6975..de8f57463479386d3277bb9ad2edade5abed73f7 100644 (file)
  * 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;
@@ -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;
@@ -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 */
@@ -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);
@@ -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);
index b1557a18e56aacc3fa7397ee0837dfb6a17ec22d..462a07a2232e221e3bf935bbb204458ee851bc7a 100644 (file)
@@ -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;
+}
index 5d1e8d3e3bcac94a86a85303888e5194fecad3ff..2816376801f82fa5b5cece2ffbbd1dc0a11fcf39 100644 (file)
@@ -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);