[lxc-devel] [lxc/master] tools: share internal API symbols
2xsec on Github
lxc-bot at linuxcontainers.org
Thu Jun 28 14:26:55 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 505 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180628/e2f2af2d/attachment.bin>
-------------- next part --------------
From eb0c9382b47e774a76235252cd6f3e834c778a33 Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Thu, 28 Jun 2018 22:49:38 +0900
Subject: [PATCH 1/7] tools: lxc-start: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/Makefile.am | 2 +-
src/lxc/confile.c | 77 ++++++++++++++++++++++++++++++++++++-----------
src/lxc/confile.h | 13 ++++++--
src/lxc/tools/arguments.h | 22 +-------------
src/lxc/tools/lxc_start.c | 41 +++++++++++++------------
5 files changed, 95 insertions(+), 60 deletions(-)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 313475824..852db6ee1 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -278,7 +278,7 @@ lxc_info_SOURCES = tools/lxc_info.c tools/arguments.c tools/tool_utils.c
lxc_monitor_SOURCES = tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
lxc_ls_SOURCES = tools/lxc_ls.c tools/arguments.c tools/tool_utils.c
lxc_copy_SOURCES = tools/lxc_copy.c tools/arguments.c tools/tool_utils.c
-lxc_start_SOURCES = tools/lxc_start.c tools/arguments.c tools/tool_utils.c
+lxc_start_SOURCES = tools/lxc_start.c tools/arguments.c
lxc_stop_SOURCES = tools/lxc_stop.c tools/arguments.c tools/tool_utils.c
lxc_top_SOURCES = tools/lxc_top.c tools/arguments.c tools/tool_utils.c
lxc_unfreeze_SOURCES = tools/lxc_unfreeze.c tools/arguments.c tools/tool_utils.c
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index f0041770a..65409aa88 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2388,16 +2388,6 @@ static int parse_line(char *buffer, void *data)
return ret;
}
-static int lxc_config_readline(char *buffer, struct lxc_conf *conf)
-{
- struct parse_line_conf c;
-
- c.conf = conf;
- c.from_include = false;
-
- return parse_line(buffer, &c);
-}
-
int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include)
{
int ret;
@@ -2430,23 +2420,33 @@ int lxc_config_define_add(struct lxc_list *defines, char *arg)
return 0;
}
-int lxc_config_define_load(struct lxc_list *defines, struct lxc_conf *conf)
+bool lxc_config_define_load(struct lxc_list *defines, struct lxc_container *c)
{
- struct lxc_list *it, *next;
- int ret = 0;
+ struct lxc_list *it;
+ bool bret = true;
lxc_list_for_each(it, defines) {
- ret = lxc_config_readline(it->elem, conf);
- if (ret)
+ struct new_config_item *new_item = it->elem;
+ bret = c->set_config_item(c, new_item->key, new_item->val);
+ if (!bret)
break;
}
+ lxc_config_define_free(defines);
+ return bret;
+}
+
+void lxc_config_define_free(struct lxc_list *defines)
+{
+ struct lxc_list *it, *next;
+
lxc_list_for_each_safe(it, defines, next) {
+ struct new_config_item *new_item = it->elem;
+ free(new_item->key);
+ free(new_item->val);
lxc_list_del(it);
free(it);
}
-
- return ret;
}
signed long lxc_config_parse_arch(const char *arch)
@@ -2494,6 +2494,49 @@ signed long lxc_config_parse_arch(const char *arch)
return -1;
}
+int lxc_fill_elevated_privileges(char *flaglist, int *flags)
+{
+ char *token, *saveptr = NULL;
+ int i, aflag;
+ struct {
+ const char *token;
+ int flag;
+ } all_privs[] = {
+ { "CGROUP", LXC_ATTACH_MOVE_TO_CGROUP },
+ { "CAP", LXC_ATTACH_DROP_CAPABILITIES },
+ { "LSM", LXC_ATTACH_LSM_EXEC },
+ { NULL, 0 }
+ };
+
+ if (!flaglist) {
+ /* For the sake of backward compatibility, drop all privileges
+ * if none is specified.
+ */
+ for (i = 0; all_privs[i].token; i++)
+ *flags |= all_privs[i].flag;
+
+ return 0;
+ }
+
+ token = strtok_r(flaglist, "|", &saveptr);
+ while (token) {
+ aflag = -1;
+
+ for (i = 0; all_privs[i].token; i++)
+ if (!strcmp(all_privs[i].token, token))
+ aflag = all_privs[i].flag;
+
+ if (aflag < 0)
+ return -1;
+
+ *flags |= aflag;
+
+ token = strtok_r(NULL, "|", &saveptr);
+ }
+
+ return 0;
+}
+
/* Write out a configuration file. */
int write_config(int fd, const struct lxc_conf *conf)
{
diff --git a/src/lxc/confile.h b/src/lxc/confile.h
index 0d877c898..4e05db16e 100644
--- a/src/lxc/confile.h
+++ b/src/lxc/confile.h
@@ -58,6 +58,11 @@ struct lxc_config_t {
config_clr_cb clr;
};
+struct new_config_item {
+ char *key;
+ char *val;
+};
+
/* Get the jump table entry for the given configuration key. */
extern struct lxc_config_t *lxc_get_config(const char *key);
@@ -85,12 +90,16 @@ extern int append_unexp_config_line(const char *line, struct lxc_conf *conf);
extern int lxc_config_define_add(struct lxc_list *defines, char* arg);
-extern int lxc_config_define_load(struct lxc_list *defines,
- struct lxc_conf *conf);
+extern bool lxc_config_define_load(struct lxc_list *defines,
+ struct lxc_container *c);
+
+extern void lxc_config_define_free(struct lxc_list *defines);
/* needed for lxc-attach */
extern signed long lxc_config_parse_arch(const char *arch);
+extern int lxc_fill_elevated_privileges(char *flaglist, int *flags);
+
extern int lxc_clear_config_item(struct lxc_conf *c, const char *key);
extern int write_config(int fd, const struct lxc_conf *conf);
diff --git a/src/lxc/tools/arguments.h b/src/lxc/tools/arguments.h
index 04cf3278b..8acebc55c 100644
--- a/src/lxc/tools/arguments.h
+++ b/src/lxc/tools/arguments.h
@@ -174,25 +174,6 @@ extern int lxc_arguments_str_to_int(struct lxc_arguments *args,
extern bool lxc_setup_shared_ns(struct lxc_arguments *args, struct lxc_container *c);
-/* Helper macro to define errno string. */
-#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE) || IS_BIONIC
-#define lxc_log_strerror_r \
- char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \
- char *ptr = errno_buf; \
- { \
- (void)strerror_r(errno, errno_buf, sizeof(errno_buf)); \
- }
-#else
-#define lxc_log_strerror_r \
- char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \
- char *ptr; \
- { \
- ptr = strerror_r(errno, errno_buf, sizeof(errno_buf)); \
- if (!ptr) \
- ptr = errno_buf; \
- }
-#endif
-
#define lxc_info(arg, fmt, args...) \
do { \
if (!(arg)->quiet) { \
@@ -210,8 +191,7 @@ extern bool lxc_setup_shared_ns(struct lxc_arguments *args, struct lxc_container
#define lxc_sys_error(arg, fmt, args...) \
do { \
if (!(arg)->quiet) { \
- lxc_log_strerror_r \
- fprintf(stderr, "%s: %s - " fmt "\n", (arg)->progname, ptr, ##args); \
+ fprintf(stderr, "%s: " fmt "\n", (arg)->progname, ##args); \
} \
} while (0)
diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c
index 57af91bb5..95e287775 100644
--- a/src/lxc/tools/lxc_start.c
+++ b/src/lxc/tools/lxc_start.c
@@ -42,11 +42,14 @@
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "tool_list.h"
-#include "tool_utils.h"
+#include "caps.h"
+#include "confile.h"
+#include "log.h"
static struct lxc_list defines;
+lxc_log_define(lxc_start, lxc);
+
static int ensure_path(struct lxc_arguments *args, char **confpath, const char *path)
{
int err = -1, fd;
@@ -56,7 +59,7 @@ static int ensure_path(struct lxc_arguments *args, char **confpath, const char *
if (access(path, W_OK)) {
fd = creat(path, 0600);
if (fd < 0 && errno != EEXIST) {
- lxc_error(args, "Failed to create '%s'", path);
+ ERROR("Failed to create '%s'", path);
goto err;
}
@@ -66,7 +69,7 @@ static int ensure_path(struct lxc_arguments *args, char **confpath, const char *
fullpath = realpath(path, NULL);
if (!fullpath) {
- lxc_error(args, "Failed to get the real path of '%s'", path);
+ ERROR("Failed to get the real path of '%s'", path);
goto err;
}
@@ -206,7 +209,7 @@ int main(int argc, char *argv[])
lxcpath = my_args.lxcpath[0];
if (access(lxcpath, O_RDONLY) < 0) {
- lxc_error(&my_args, "You lack access to %s", lxcpath);
+ ERROR("You lack access to %s", lxcpath);
exit(err);
}
@@ -222,21 +225,21 @@ int main(int argc, char *argv[])
c = lxc_container_new(my_args.name, lxcpath);
if (!c) {
- lxc_error(&my_args, "Failed to create lxc_container");
+ ERROR("Failed to create lxc_container");
exit(err);
}
c->clear_config(c);
if (!c->load_config(c, rcfile)) {
- lxc_error(&my_args, "Failed to load rcfile");
+ ERROR("Failed to load rcfile");
lxc_container_put(c);
exit(err);
}
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- lxc_error(&my_args, "Out of memory setting new config filename");
+ ERROR("Out of memory setting new config filename");
goto out;
}
} else {
@@ -244,7 +247,7 @@ int main(int argc, char *argv[])
rc = asprintf(&rcfile, "%s/%s/config", lxcpath, my_args.name);
if (rc == -1) {
- lxc_error(&my_args, "Failed to allocate memory");
+ ERROR("Failed to allocate memory");
exit(err);
}
@@ -256,7 +259,7 @@ int main(int argc, char *argv[])
c = lxc_container_new(my_args.name, lxcpath);
if (!c) {
- lxc_error(&my_args, "Failed to create lxc_container");
+ ERROR("Failed to create lxc_container");
exit(err);
}
}
@@ -267,12 +270,12 @@ int main(int argc, char *argv[])
* file as argument and start the container right away.
*/
if (!c->may_control(c)) {
- lxc_error(&my_args, "Insufficent privileges to control %s", c->name);
+ ERROR("Insufficent privileges to control %s", c->name);
goto out;
}
if (c->is_running(c)) {
- lxc_error(&my_args, "Container is already running.");
+ ERROR("Container is already running.");
err = EXIT_SUCCESS;
goto out;
}
@@ -282,7 +285,7 @@ int main(int argc, char *argv[])
* unset c->lxc_conf for us and let us not use lxc_config_define_load()
*/
if (!c->lxc_conf) {
- lxc_error(&my_args, "No container config specified");
+ ERROR("No container config specified");
goto out;
}
@@ -290,13 +293,13 @@ int main(int argc, char *argv[])
goto out;
if (!rcfile && !strcmp("/sbin/init", args[0])) {
- lxc_error(&my_args, "Executing '/sbin/init' with no configuration file may crash the host");
+ ERROR("Executing '/sbin/init' with no configuration file may crash the host");
goto out;
}
if (my_args.pidfile != NULL) {
if (ensure_path(&my_args, &c->pidfile, my_args.pidfile) < 0) {
- lxc_error(&my_args, "Failed to ensure pidfile '%s'", my_args.pidfile);
+ ERROR("Failed to ensure pidfile '%s'", my_args.pidfile);
goto out;
}
}
@@ -324,13 +327,13 @@ int main(int argc, char *argv[])
else
err = c->start(c, 0, args) ? EXIT_SUCCESS : EXIT_FAILURE;
if (err) {
- lxc_error(&my_args, "The container failed to start.");
+ ERROR("The container failed to start.");
if (my_args.daemonize)
- lxc_error(&my_args, "To get more details, run the container in foreground mode.");
+ ERROR("To get more details, run the container in foreground mode.");
- lxc_error(&my_args, "Additional information can be obtained by setting the "
- "--logfile and --logpriority options.\n");
+ ERROR("Additional information can be obtained by setting the "
+ "--logfile and --logpriority options.");
err = c->error_num;
lxc_container_put(c);
From 19eacdc057f0a7937447fccce1e5ed49a1b6f16b Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Thu, 28 Jun 2018 22:54:27 +0900
Subject: [PATCH 2/7] tools: lxc-stop: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/Makefile.am | 2 +-
src/lxc/tools/lxc_stop.c | 25 ++++++++++++++-----------
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 852db6ee1..acdb29dc4 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -279,7 +279,7 @@ lxc_monitor_SOURCES = tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
lxc_ls_SOURCES = tools/lxc_ls.c tools/arguments.c tools/tool_utils.c
lxc_copy_SOURCES = tools/lxc_copy.c tools/arguments.c tools/tool_utils.c
lxc_start_SOURCES = tools/lxc_start.c tools/arguments.c
-lxc_stop_SOURCES = tools/lxc_stop.c tools/arguments.c tools/tool_utils.c
+lxc_stop_SOURCES = tools/lxc_stop.c tools/arguments.c
lxc_top_SOURCES = tools/lxc_top.c tools/arguments.c tools/tool_utils.c
lxc_unfreeze_SOURCES = tools/lxc_unfreeze.c tools/arguments.c tools/tool_utils.c
lxc_unshare_SOURCES = tools/lxc_unshare.c tools/arguments.c tools/tool_utils.c
diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c
index 7416116d6..c1b6a4763 100644
--- a/src/lxc/tools/lxc_stop.c
+++ b/src/lxc/tools/lxc_stop.c
@@ -31,11 +31,14 @@
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "tool_utils.h"
+#include "log.h"
+#include "utils.h"
#define OPT_NO_LOCK OPT_USAGE + 1
#define OPT_NO_KILL OPT_USAGE + 2
+lxc_log_define(lxc_stop, lxc);
+
static int my_parser(struct lxc_arguments *args, int c, char *arg)
{
switch (c) {
@@ -130,33 +133,33 @@ int main(int argc, char *argv[])
/* some checks */
if (!my_args.hardstop && my_args.timeout < -1) {
- lxc_error(&my_args, "Invalid timeout");
+ ERROR("Invalid timeout");
exit(ret);
}
if (my_args.hardstop && my_args.nokill) {
- lxc_error(&my_args, "-k can't be used with --nokill");
+ ERROR("-k can't be used with --nokill");
exit(ret);
}
if (my_args.hardstop && my_args.reboot) {
- lxc_error(&my_args, "-k can't be used with -r");
+ ERROR("-k can't be used with -r");
exit(ret);
}
if (my_args.hardstop && my_args.timeout) {
- lxc_error(&my_args, "-k doesn't allow timeouts");
+ ERROR("-k doesn't allow timeouts");
exit(ret);
}
if (my_args.nolock && !my_args.hardstop) {
- lxc_error(&my_args, "--nolock may only be used with -k");
+ ERROR("--nolock may only be used with -k");
exit(ret);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
- lxc_error(&my_args, "Error opening container");
+ ERROR("Error opening container");
goto out;
}
@@ -164,24 +167,24 @@ int main(int argc, char *argv[])
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
- lxc_error(&my_args, "Failed to load rcfile");
+ ERROR("Failed to load rcfile");
goto out;
}
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- lxc_error(&my_args, "Out of memory setting new config filename");
+ ERROR("Out of memory setting new config filename");
goto out;
}
}
if (!c->may_control(c)) {
- lxc_error(&my_args, "Insufficent privileges to control %s", c->name);
+ ERROR("Insufficent privileges to control %s", c->name);
goto out;
}
if (!c->is_running(c)) {
- lxc_error(&my_args, "%s is not running", c->name);
+ ERROR("%s is not running", c->name);
/* Per our manpage we need to exit with exit code:
* 2: The specified container exists but was not running.
From a599e9c04357b8d3c1bc06c65e026a383183932d Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Thu, 28 Jun 2018 23:00:03 +0900
Subject: [PATCH 3/7] tools: lxc-freeze: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/Makefile.am | 2 +-
src/lxc/tools/lxc_freeze.c | 15 ++++++++++-----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index acdb29dc4..4afb3f0c7 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -273,7 +273,7 @@ lxc_console_SOURCES = tools/lxc_console.c tools/arguments.c tools/tool_utils.c
lxc_destroy_SOURCES = tools/lxc_destroy.c tools/arguments.c tools/tool_utils.c
lxc_device_SOURCES = tools/lxc_device.c tools/arguments.c tools/tool_utils.c
lxc_execute_SOURCES = tools/lxc_execute.c tools/arguments.c tools/tool_utils.c
-lxc_freeze_SOURCES = tools/lxc_freeze.c tools/arguments.c tools/tool_utils.c
+lxc_freeze_SOURCES = tools/lxc_freeze.c tools/arguments.c
lxc_info_SOURCES = tools/lxc_info.c tools/arguments.c tools/tool_utils.c
lxc_monitor_SOURCES = tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
lxc_ls_SOURCES = tools/lxc_ls.c tools/arguments.c tools/tool_utils.c
diff --git a/src/lxc/tools/lxc_freeze.c b/src/lxc/tools/lxc_freeze.c
index 19e758c6f..88e1f38b8 100644
--- a/src/lxc/tools/lxc_freeze.c
+++ b/src/lxc/tools/lxc_freeze.c
@@ -32,6 +32,9 @@
#include <lxc/lxccontainer.h>
#include "arguments.h"
+#include "log.h"
+
+lxc_log_define(lxc_freeze, lxc);
static const struct option my_longopts[] = {
LXC_COMMON_OPTIONS
@@ -75,33 +78,35 @@ int main(int argc, char *argv[])
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
- lxc_error(&my_args, "No such container: %s:%s", my_args.lxcpath[0], my_args.name);
+ ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
exit(EXIT_FAILURE);
}
if (my_args.rcfile) {
c->clear_config(c);
+
if (!c->load_config(c, my_args.rcfile)) {
- lxc_error(&my_args, "Failed to load rcfile");
+ ERROR("Failed to load rcfile");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
+
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- lxc_error(&my_args, "Out of memory setting new config filename");
+ ERROR("Out of memory setting new config filename");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->may_control(c)) {
- lxc_error(&my_args, "Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
+ ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
if (!c->freeze(c)) {
- lxc_error(&my_args, "Failed to freeze %s:%s", my_args.lxcpath[0], my_args.name);
+ ERROR("Failed to freeze %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
From 7d6ee132a55b541d68e6b993f0afcf7d42a08cb1 Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Thu, 28 Jun 2018 23:03:55 +0900
Subject: [PATCH 4/7] tools: lxc-unfreeze: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/Makefile.am | 2 +-
src/lxc/tools/lxc_unfreeze.c | 14 ++++++++------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 4afb3f0c7..8324eb1fe 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -281,7 +281,7 @@ lxc_copy_SOURCES = tools/lxc_copy.c tools/arguments.c tools/tool_utils.c
lxc_start_SOURCES = tools/lxc_start.c tools/arguments.c
lxc_stop_SOURCES = tools/lxc_stop.c tools/arguments.c
lxc_top_SOURCES = tools/lxc_top.c tools/arguments.c tools/tool_utils.c
-lxc_unfreeze_SOURCES = tools/lxc_unfreeze.c tools/arguments.c tools/tool_utils.c
+lxc_unfreeze_SOURCES = tools/lxc_unfreeze.c tools/arguments.c
lxc_unshare_SOURCES = tools/lxc_unshare.c tools/arguments.c tools/tool_utils.c
lxc_wait_SOURCES = tools/lxc_wait.c tools/arguments.c tools/tool_utils.c
lxc_create_SOURCES = tools/lxc_create.c tools/arguments.c tools/tool_utils.c
diff --git a/src/lxc/tools/lxc_unfreeze.c b/src/lxc/tools/lxc_unfreeze.c
index 81aa05c19..a0b56900f 100644
--- a/src/lxc/tools/lxc_unfreeze.c
+++ b/src/lxc/tools/lxc_unfreeze.c
@@ -31,7 +31,9 @@
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "tool_utils.h"
+#include "log.h"
+
+lxc_log_define(lxc_unfreeze, lxc);
static const struct option my_longopts[] = {
LXC_COMMON_OPTIONS
@@ -75,12 +77,12 @@ int main(int argc, char *argv[])
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
- lxc_error(&my_args, "No such container: %s:%s", my_args.lxcpath[0], my_args.name);
+ ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
exit(EXIT_FAILURE);
}
if (!c->may_control(c)) {
- lxc_error(&my_args, "Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
+ ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
@@ -89,21 +91,21 @@ int main(int argc, char *argv[])
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
- lxc_error(&my_args, "Failed to load rcfile");
+ ERROR("Failed to load rcfile");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- lxc_error(&my_args, "Out of memory setting new config filename");
+ ERROR("Out of memory setting new config filename");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->unfreeze(c)) {
- lxc_error(&my_args, "Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name);
+ ERROR("Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
From df3ab009952f365d993e1febbbb1e910d7bb77e6 Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Thu, 28 Jun 2018 23:07:01 +0900
Subject: [PATCH 5/7] tools: lxc-wait: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/Makefile.am | 2 +-
src/lxc/tools/lxc_wait.c | 12 +++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 8324eb1fe..81c0d17ba 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -283,7 +283,7 @@ lxc_stop_SOURCES = tools/lxc_stop.c tools/arguments.c
lxc_top_SOURCES = tools/lxc_top.c tools/arguments.c tools/tool_utils.c
lxc_unfreeze_SOURCES = tools/lxc_unfreeze.c tools/arguments.c
lxc_unshare_SOURCES = tools/lxc_unshare.c tools/arguments.c tools/tool_utils.c
-lxc_wait_SOURCES = tools/lxc_wait.c tools/arguments.c tools/tool_utils.c
+lxc_wait_SOURCES = tools/lxc_wait.c tools/arguments.c
lxc_create_SOURCES = tools/lxc_create.c tools/arguments.c tools/tool_utils.c
lxc_snapshot_SOURCES = tools/lxc_snapshot.c tools/arguments.c tools/tool_utils.c
lxc_checkpoint_SOURCES = tools/lxc_checkpoint.c tools/arguments.c tools/tool_utils.c
diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c
index 346c546ee..01ea3fa51 100644
--- a/src/lxc/tools/lxc_wait.c
+++ b/src/lxc/tools/lxc_wait.c
@@ -33,12 +33,14 @@
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "tool_utils.h"
+#include "log.h"
+
+lxc_log_define(lxc_wait, lxc);
static int my_checker(const struct lxc_arguments *args)
{
if (!args->states) {
- lxc_error(args, "missing state option to wait for.");
+ ERROR("Missing state option to wait for.");
return -1;
}
@@ -107,7 +109,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
if (!c->may_control(c)) {
- lxc_error(&my_args, "Insufficent privileges to control %s", c->name);
+ ERROR("Insufficent privileges to control %s", c->name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
@@ -116,14 +118,14 @@ int main(int argc, char *argv[])
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
- lxc_error(&my_args, "Failed to load rcfile");
+ ERROR("Failed to load rcfile");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- lxc_error(&my_args, "Out of memory setting new config filename");
+ ERROR("Out of memory setting new config filename");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
From 93f81bc78d34c0aa66ab7e519a7ba45a5d67da6e Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Thu, 28 Jun 2018 23:13:01 +0900
Subject: [PATCH 6/7] tools: lxc-cgroup: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/Makefile.am | 2 +-
src/lxc/tools/lxc_cgroup.c | 30 +++++++++++++++++-------------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 81c0d17ba..f4a76fdb7 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -267,7 +267,7 @@ LDADD=liblxc.la @CAP_LIBS@ @GNUTLS_LIBS@ @SELINUX_LIBS@ @SECCOMP_LIBS@
if ENABLE_TOOLS
lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c tools/tool_utils.c
lxc_autostart_SOURCES = tools/lxc_autostart.c tools/arguments.c tools/tool_utils.c
-lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c tools/tool_utils.c
+lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c
lxc_config_SOURCES = tools/lxc_config.c tools/arguments.c tools/tool_utils.c
lxc_console_SOURCES = tools/lxc_console.c tools/arguments.c tools/tool_utils.c
lxc_destroy_SOURCES = tools/lxc_destroy.c tools/arguments.c tools/tool_utils.c
diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c
index 16a10a11a..06706c84e 100644
--- a/src/lxc/tools/lxc_cgroup.c
+++ b/src/lxc/tools/lxc_cgroup.c
@@ -32,12 +32,14 @@
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "tool_utils.h"
+#include "log.h"
+
+lxc_log_define(lxc_cgroup, lxc);
static int my_checker(const struct lxc_arguments* args)
{
if (!args->argc) {
- lxc_error(args, "Missing state object");
+ ERROR("Missing state object");
return -1;
}
@@ -94,28 +96,29 @@ int main(int argc, char *argv[])
if (my_args.rcfile) {
c->clear_config(c);
+
if (!c->load_config(c, my_args.rcfile)) {
- lxc_error(&my_args, "Failed to load rcfile");
+ ERROR("Failed to load rcfile");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- lxc_error(&my_args, "Out of memory setting new config filename");
+ ERROR("Out of memory setting new config filename");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->may_control(c)) {
- lxc_error(&my_args, "Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
+ ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
if (!c->is_running(c)) {
- lxc_error(&my_args, "'%s:%s' is not running", my_args.lxcpath[0], my_args.name);
+ ERROR("'%s:%s' is not running", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
@@ -124,25 +127,26 @@ int main(int argc, char *argv[])
value = my_args.argv[1];
if (!c->set_cgroup_item(c, state_object, value)) {
- lxc_error(&my_args, "Failed to assign '%s' value to '%s' for '%s'",
- value, state_object, my_args.name);
+ ERROR("Failed to assign '%s' value to '%s' for '%s'",
+ value, state_object, my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
} else {
- char buffer[TOOL_MAXPATHLEN];
+ char buffer[MAXPATHLEN];
int ret;
- ret = c->get_cgroup_item(c, state_object, buffer, TOOL_MAXPATHLEN);
+ ret = c->get_cgroup_item(c, state_object, buffer, MAXPATHLEN);
if (ret < 0) {
- lxc_error(&my_args, "Failed to retrieve value of '%s' for '%s:%s'",
- state_object, my_args.lxcpath[0], my_args.name);
+ ERROR("Failed to retrieve value of '%s' for '%s:%s'",
+ state_object, my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
- printf("%*s", ret, buffer);
+ INFO("%*s", ret, buffer);
}
lxc_container_put(c);
+
exit(EXIT_SUCCESS);
}
From 1b36d9e9dda868a8070bb37c0ee870d05722302e Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Thu, 28 Jun 2018 23:19:50 +0900
Subject: [PATCH 7/7] tools: lxc-attach: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
src/lxc/Makefile.am | 2 +-
src/lxc/tools/lxc_attach.c | 25 ++++++++++++++++---------
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index f4a76fdb7..d5fae71bf 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -265,7 +265,7 @@ endif
LDADD=liblxc.la @CAP_LIBS@ @GNUTLS_LIBS@ @SELINUX_LIBS@ @SECCOMP_LIBS@
if ENABLE_TOOLS
-lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c tools/tool_utils.c
+lxc_attach_SOURCES = tools/lxc_attach.c tools/arguments.c
lxc_autostart_SOURCES = tools/lxc_autostart.c tools/arguments.c tools/tool_utils.c
lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c
lxc_config_SOURCES = tools/lxc_config.c tools/arguments.c tools/tool_utils.c
diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index 56c225d80..6729a1e1e 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -37,7 +37,13 @@
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "tool_utils.h"
+#include "attach.h"
+#include "caps.h"
+#include "confile.h"
+#include "log.h"
+#include "utils.h"
+
+lxc_log_define(lxc_attach, lxc);
static const struct option my_longopts[] = {
{"elevated-privileges", optional_argument, 0, 'e'},
@@ -108,7 +114,7 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
case 'a':
new_personality = lxc_config_parse_arch(arg);
if (new_personality < 0) {
- lxc_error(args, "invalid architecture specified: %s", arg);
+ ERROR("Invalid architecture specified: %s", arg);
return -1;
}
break;
@@ -153,14 +159,14 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
case 502: /* keep-var */
ret = add_to_simple_array(&extra_keep, &extra_keep_size, arg);
if (ret < 0) {
- lxc_error(args, "memory allocation error");
+ ERROR("Failed to alloc memory");
return -1;
}
break;
case 'v':
ret = add_to_simple_array(&extra_env, &extra_env_size, arg);
if (ret < 0) {
- lxc_error(args, "memory allocation error");
+ ERROR("Failed to alloc memory");
return -1;
}
break;
@@ -246,7 +252,7 @@ static int lxc_attach_create_log_file(const char *log_file)
fd = open(log_file, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600);
if (fd < 0) {
- lxc_error(&my_args, "Failed to open log file \"%s\"", log_file);
+ ERROR("Failed to open log file \"%s\"", log_file);
return -1;
}
@@ -285,7 +291,7 @@ int main(int argc, char *argv[])
if (geteuid()) {
if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
- lxc_error(&my_args, "You lack access to %s", my_args.lxcpath[0]);
+ ERROR("You lack access to %s", my_args.lxcpath[0]);
exit(EXIT_FAILURE);
}
}
@@ -297,21 +303,21 @@ int main(int argc, char *argv[])
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
- lxc_error(&my_args, "Failed to load rcfile");
+ ERROR("Failed to load rcfile");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- lxc_error(&my_args, "Out of memory setting new config filename");
+ ERROR("Out of memory setting new config filename");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->may_control(c)) {
- lxc_error(&my_args, "Insufficent privileges to control %s", c->name);
+ ERROR("Insufficent privileges to control %s", c->name);
lxc_container_put(c);
exit(EXIT_FAILURE);
}
@@ -355,6 +361,7 @@ int main(int argc, char *argv[])
if (WIFEXITED(ret))
wexit = WEXITSTATUS(ret);
+
out:
lxc_container_put(c);
if (ret >= 0)
More information about the lxc-devel
mailing list