tools: move lxc-info to API symbols only

Closes #2073. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 49ac7514
...@@ -21,21 +21,20 @@ ...@@ -21,21 +21,20 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 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 <stdbool.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#include <libgen.h>
#include <sys/types.h> #include <sys/types.h>
#include <lxc/lxccontainer.h> #include <lxc/lxccontainer.h>
#include "lxc.h"
#include "log.h"
#include "utils.h"
#include "commands.h"
#include "arguments.h" #include "arguments.h"
#include "tool_utils.h"
static bool ips; static bool ips;
static bool state; static bool state;
...@@ -205,7 +204,7 @@ static void print_stats(struct lxc_container *c) ...@@ -205,7 +204,7 @@ static void print_stats(struct lxc_container *c)
char buf[4096]; char buf[4096];
ret = c->get_cgroup_item(c, "cpuacct.usage", buf, sizeof(buf)); 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); str_chomp(buf);
if (humanize) { if (humanize) {
float seconds = strtof(buf, NULL) / 1000000000.0; float seconds = strtof(buf, NULL) / 1000000000.0;
...@@ -217,7 +216,7 @@ static void print_stats(struct lxc_container *c) ...@@ -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)); 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; char *ch;
/* put ch on last "Total" line */ /* put ch on last "Total" line */
...@@ -247,7 +246,7 @@ static void print_stats(struct lxc_container *c) ...@@ -247,7 +246,7 @@ static void print_stats(struct lxc_container *c)
for (i = 0; lxstat[i].name; i++) { for (i = 0; lxstat[i].name; i++) {
ret = c->get_cgroup_item(c, lxstat[i].file, buf, sizeof(buf)); 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_chomp(buf);
str_size_humanize(buf, sizeof(buf)); str_size_humanize(buf, sizeof(buf));
printf("%-15s %s\n", lxstat[i].name, buf); printf("%-15s %s\n", lxstat[i].name, buf);
...@@ -409,7 +408,6 @@ int main(int argc, char *argv[]) ...@@ -409,7 +408,6 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log)) if (lxc_log_init(&log))
exit(ret); exit(ret);
lxc_log_options_no_override();
/* REMOVE IN LXC 3.0 */ /* REMOVE IN LXC 3.0 */
setenv("LXC_UPDATE_CONFIG_FORMAT", "1", 0); setenv("LXC_UPDATE_CONFIG_FORMAT", "1", 0);
......
...@@ -823,3 +823,30 @@ void lxc_config_define_free(struct lxc_list *defines) ...@@ -823,3 +823,30 @@ void lxc_config_define_free(struct lxc_list *defines)
free(it); 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;
}
...@@ -143,6 +143,7 @@ extern char **lxc_string_split_quoted(char *string); ...@@ -143,6 +143,7 @@ extern char **lxc_string_split_quoted(char *string);
extern int mkdir_p(const char *dir, mode_t mode); extern int mkdir_p(const char *dir, mode_t mode);
extern bool file_exists(const char *f); extern bool file_exists(const char *f);
extern int is_dir(const char *path); 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); extern char *get_template_path(const char *t);
......
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