]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Revert (by hand) "logs: introduce a thread-local 'current' lxc_config"
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 14 Apr 2015 20:47:02 +0000 (15:47 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 14 Apr 2015 20:58:58 +0000 (15:58 -0500)
This is hopefully temporary - it works great for lxc itself, but seems
to be upsetting golang.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Tested-by: Tycho Andersen <tycho.andersen@canonical.com>
src/lxc/Makefile.am
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/log.c
src/lxc/log.h
src/lxc/lxccontainer.c

index 8b79c40001b0210b6539e5e062bb7268a32f1272..b1e56b939994e1753bc730a58bcc5dc37696ac94 100644 (file)
@@ -248,7 +248,6 @@ endif
 
 init_lxc_static_LDFLAGS = -static
 init_lxc_static_LDADD = @CAP_LIBS@
-init_lxc_static_CFLAGS = $(AM_CFLAGS) -DNO_LXC_CONF
 endif
 
 install-exec-local: install-soPROGRAMS
index f1e89d80ab1da9cf6b4ed78abb97be591145557d..d4855fd184befe9f5581cff73f3bf4cbb5603481 100644 (file)
@@ -178,17 +178,6 @@ struct caps_opt {
        int value;
 };
 
-/*
- * The lxc_conf of the container currently being worked on in an
- * API call
- * This is used in the error calls
- */
-#ifdef HAVE_TLS
-__thread struct lxc_conf *current_config;
-#else
-struct lxc_conf *current_config;
-#endif
-
 /* Declare this here, since we don't want to reshuffle the whole file. */
 static int in_caplist(int cap, struct lxc_list *caps);
 
@@ -2584,7 +2573,6 @@ struct lxc_conf *lxc_conf_init(void)
                return NULL;
        }
        new->kmsg = 0;
-       new->logfd = -1;
        lxc_list_init(&new->cgroup);
        lxc_list_init(&new->network);
        lxc_list_init(&new->mount_list);
@@ -4258,8 +4246,6 @@ void lxc_conf_free(struct lxc_conf *conf)
        free(conf->rootfs.path);
        free(conf->rootfs.pivot);
        free(conf->logfile);
-       if (conf->logfd != -1)
-               close(conf->logfd);
        free(conf->utsname);
        free(conf->ttydir);
        free(conf->fstab);
index 0c0475e029b56dd0946ca9f38b72e7c8051e268a..4b660456fdce9d37db899b411d8dd50c519336d2 100644 (file)
@@ -336,7 +336,6 @@ struct lxc_conf {
        // store the config file specified values here.
        char *logfile;  // the logfile as specifed in config
        int loglevel;   // loglevel as specifed in config (if any)
-       int logfd;
 
        int inherit_ns_fd[LXC_NS_MAX];
 
@@ -366,12 +365,6 @@ struct lxc_conf {
        char *init_cmd;
 };
 
-#ifdef HAVE_TLS
-extern __thread struct lxc_conf *current_config;
-#else
-extern struct lxc_conf *current_config;
-#endif
-
 int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
                  const char *lxcpath, char *argv[]);
 
index 7e8b6a2d7984908acf89f1d2b75724b3d2904899..e3be6a6ea533ae4c4d4bf88ae994bc5c90df2945 100644 (file)
@@ -1171,15 +1171,15 @@ static int config_lsm_se_context(const char *key, const char *value,
 }
 
 static int config_logfile(const char *key, const char *value,
-                            struct lxc_conf *c)
+                            struct lxc_conf *lxc_conf)
 {
        int ret;
 
        // store these values in the lxc_conf, and then try to set for
        // actual current logging.
-       ret = config_path_item(&c->logfile, value);
+       ret = config_path_item(&lxc_conf->logfile, value);
        if (ret == 0)
-               ret = lxc_log_set_file(&c->logfd, c->logfile);
+               ret = lxc_log_set_file(lxc_conf->logfile);
        return ret;
 }
 
@@ -1198,7 +1198,7 @@ static int config_loglevel(const char *key, const char *value,
        // store these values in the lxc_conf, and then try to set for
        // actual current logging.
        lxc_conf->loglevel = newlevel;
-       return lxc_log_set_level(&lxc_conf->loglevel, newlevel);
+       return lxc_log_set_level(newlevel);
 }
 
 static int config_autodev(const char *key, const char *value,
@@ -2381,9 +2381,9 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
        else if (strcmp(key, "lxc.se_context") == 0)
                v = c->lsm_se_context;
        else if (strcmp(key, "lxc.logfile") == 0)
-               v = c->logfile;
+               v = lxc_log_get_file();
        else if (strcmp(key, "lxc.loglevel") == 0)
-               v = lxc_log_priority_to_string(c->loglevel);
+               v = lxc_log_priority_to_string(lxc_log_get_level());
        else if (strcmp(key, "lxc.cgroup") == 0) // all cgroup info
                return lxc_get_cgroup_entry(c, retv, inlen, "all");
        else if (strncmp(key, "lxc.cgroup.", 11) == 0) // specific cgroup info
index 04ba2ccae871ea16872fef9d12fc50f4bfce72b0..6633e625a6f059a08d36bf03635f075762900543 100644 (file)
@@ -27,7 +27,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <string.h>
-#include <pthread.h>
 
 #define __USE_GNU /* for *_CLOEXEC */
 
 #define LXC_LOG_PREFIX_SIZE    32
 #define LXC_LOG_BUFFER_SIZE    512
 
-static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
-static void lock_mutex(pthread_mutex_t *l)
-{
-       int ret;
-
-       if ((ret = pthread_mutex_lock(l)) != 0) {
-               fprintf(stderr, "pthread_mutex_lock returned:%d %s\n", ret, strerror(ret));
-               exit(1);
-       }
-}
-
-static void unlock_mutex(pthread_mutex_t *l)
-{
-       int ret;
-
-       if ((ret = pthread_mutex_unlock(l)) != 0) {
-               fprintf(stderr, "pthread_mutex_unlock returned:%d %s\n", ret, strerror(ret));
-               exit(1);
-       }
-}
-
-void log_lock(void)
-{
-       lock_mutex(&log_mutex);
-}
-
-void log_unlock(void)
-{
-       unlock_mutex(&log_mutex);
-}
-
+#ifdef HAVE_TLS
+__thread int lxc_log_fd = -1;
+static __thread char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
+static __thread char *log_fname = NULL;
+/* command line values for logfile or logpriority should always override
+ * values from the configuration file or defaults
+ */
+static __thread int lxc_logfile_specified = 0;
+static __thread int lxc_loglevel_specified = 0;
+static __thread int lxc_quiet_specified = 0;
+#else
 int lxc_log_fd = -1;
-int lxc_quiet_specified;
-int lxc_log_use_global_fd;
-static int lxc_loglevel_specified;
-
 static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
 static char *log_fname = NULL;
+static int lxc_quiet_specified = 0;
+/* command line values for logfile or logpriority should always override
+ * values from the configuration file or defaults
+ */
+static int lxc_logfile_specified = 0;
+static int lxc_loglevel_specified = 0;
+#endif
 
 lxc_log_define(lxc_log, lxc);
 
@@ -103,17 +85,8 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
        char buffer[LXC_LOG_BUFFER_SIZE];
        int n;
        int ms;
-       int fd_to_use = -1;
-
-#ifndef NO_LXC_CONF
-       if (!lxc_log_use_global_fd && current_config)
-               fd_to_use = current_config->logfd;
-#endif
 
-       if (fd_to_use == -1)
-               fd_to_use = lxc_log_fd;
-
-       if (fd_to_use == -1)
+       if (lxc_log_fd == -1)
                return 0;
 
        ms = event->timestamp.tv_usec / 1000;
@@ -138,7 +111,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
 
        buffer[n] = '\n';
 
-       return write(fd_to_use, buffer, n + 1);
+       return write(lxc_log_fd, buffer, n + 1);
 }
 
 static struct lxc_log_appender log_appender_stderr = {
@@ -163,7 +136,7 @@ static struct lxc_log_category log_root = {
 struct lxc_log_category lxc_log_category_lxc = {
        .name           = "lxc",
        .priority       = LXC_LOG_PRIORITY_ERROR,
-       .appender       = &log_appender_logfile,
+       .appender       = &log_appender_stderr,
        .parent         = &log_root
 };
 
@@ -332,11 +305,6 @@ static int _lxc_log_set_file(const char *name, const char *lxcpath, int create_d
        return ret;
 }
 
-/*
- * lxc_log_init:
- * Called from lxc front-end programs (like lxc-create, lxc-start) to
- * initalize the log defaults.
- */
 extern int lxc_log_init(const char *name, const char *file,
                        const char *priority, const char *prefix, int quiet,
                        const char *lxcpath)
@@ -352,12 +320,10 @@ extern int lxc_log_init(const char *name, const char *file,
        if (priority)
                lxc_priority = lxc_log_priority_to_int(priority);
 
-       if (!lxc_loglevel_specified) {
-               lxc_log_category_lxc.priority = lxc_priority;
-               lxc_loglevel_specified = 1;
-       }
+       lxc_log_category_lxc.priority = lxc_priority;
 
        if (!lxc_quiet_specified) {
+               lxc_log_category_lxc.appender = &log_appender_logfile;
                if (!quiet)
                        lxc_log_category_lxc.appender->next = &log_appender_stderr;
        }
@@ -369,7 +335,6 @@ extern int lxc_log_init(const char *name, const char *file,
                if (strcmp(file, "none") == 0)
                        return 0;
                ret = __lxc_log_set_file(file, 1);
-               lxc_log_use_global_fd = 1;
        } else {
                /* if no name was specified, there nothing to do */
                if (!name)
@@ -420,13 +385,15 @@ extern void lxc_log_close(void)
  * happens after processing command line arguments, which override the .conf
  * settings.  So only set the level if previously unset.
  */
-extern int lxc_log_set_level(int *dest, int level)
+extern int lxc_log_set_level(int level)
 {
+       if (lxc_loglevel_specified)
+               return 0;
        if (level < 0 || level >= LXC_LOG_PRIORITY_NOTSET) {
                ERROR("invalid log priority %d", level);
                return -1;
        }
-       *dest = level;
+       lxc_log_category_lxc.priority = level;
        return 0;
 }
 
@@ -448,23 +415,11 @@ extern bool lxc_log_has_valid_level(void)
  * happens after processing command line arguments, which override the .conf
  * settings.  So only set the file if previously unset.
  */
-extern int lxc_log_set_file(int *fd, const char *fname)
+extern int lxc_log_set_file(const char *fname)
 {
-       if (*fd != -1) {
-               close(*fd);
-               *fd = -1;
-       }
-
-       if (build_dir(fname)) {
-               ERROR("failed to create dir for log file \"%s\" : %s", fname,
-                               strerror(errno));
-               return -1;
-       }
-
-       *fd = log_open(fname);
-       if (*fd == -1)
-               return -errno;
-       return 0;
+       if (lxc_logfile_specified)
+               return 0;
+       return __lxc_log_set_file(fname, 0);
 }
 
 extern const char *lxc_log_get_file(void)
@@ -485,6 +440,11 @@ extern const char *lxc_log_get_prefix(void)
 
 extern void lxc_log_options_no_override()
 {
+       if (lxc_log_get_file())
+               lxc_logfile_specified = 1;
+
+       if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET)
+               lxc_loglevel_specified = 1;
+
        lxc_quiet_specified = 1;
-       lxc_loglevel_specified = 1;
 }
index 76bd4df3d16e8ed62f8cb087231980a4868252d8..b47f1209f97b25ac01f1bc257555aebed147b009 100644 (file)
@@ -33,8 +33,6 @@
 #include <strings.h>
 #include <stdbool.h>
 
-#include "conf.h"
-
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 02000000
 #endif
@@ -106,10 +104,6 @@ struct lxc_log_category {
        const struct lxc_log_category   *parent;
 };
 
-#ifndef NO_LXC_CONF
-extern int lxc_log_use_global_fd;
-#endif
-
 /*
  * Returns true if the chained priority is equal to or higher than
  * given priority.
@@ -122,14 +116,7 @@ lxc_log_priority_is_enabled(const struct lxc_log_category* category,
               category->parent)
                category = category->parent;
 
-       int cmp_prio = category->priority;
-#ifndef NO_LXC_CONF
-       if (!lxc_log_use_global_fd && current_config &&
-                       current_config->loglevel != LXC_LOG_PRIORITY_NOTSET)
-               cmp_prio = current_config->loglevel;
-#endif
-
-       return priority >= cmp_prio;
+       return priority >= category->priority;
 }
 
 /*
@@ -307,14 +294,18 @@ ATTR_UNUSED static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo,    \
        ERROR("%s - " format, strerror(errno), ##__VA_ARGS__);          \
 } while (0)
 
+#ifdef HAVE_TLS
+extern __thread int lxc_log_fd;
+#else
 extern int lxc_log_fd;
+#endif
 
 extern int lxc_log_init(const char *name, const char *file,
                        const char *priority, const char *prefix, int quiet,
                        const char *lxcpath);
 
-extern int lxc_log_set_file(int *fd, const char *fname);
-extern int lxc_log_set_level(int *dest, int level);
+extern int lxc_log_set_file(const char *fname);
+extern int lxc_log_set_level(int level);
 extern void lxc_log_set_prefix(const char *prefix);
 extern const char *lxc_log_get_file(void);
 extern int lxc_log_get_level(void);
index 5b96b8c50c189c57813274a69ad50a19fc568b30..e2586deb98a133c91769fd27924b71fb0e331049 100644 (file)
@@ -91,15 +91,6 @@ return -1;
 
 lxc_log_define(lxc_container, lxc);
 
-static bool do_lxcapi_destroy(struct lxc_container *c);
-static const char *lxcapi_get_config_path(struct lxc_container *c);
-#define do_lxcapi_get_config_path(c) lxcapi_get_config_path(c)
-static bool do_lxcapi_set_config_item(struct lxc_container *c, const char *key, const char *v);
-static bool container_destroy(struct lxc_container *c);
-static bool get_snappath_dir(struct lxc_container *c, char *snappath);
-static bool lxcapi_snapshot_destroy_all(struct lxc_container *c);
-static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file);
-
 static bool config_file_exists(const char *lxcpath, const char *cname)
 {
        /* $lxcpath + '/' + $cname + '/config' + \0 */
@@ -316,7 +307,7 @@ int lxc_container_put(struct lxc_container *c)
        return 0;
 }
 
-static bool do_lxcapi_is_defined(struct lxc_container *c)
+static bool lxcapi_is_defined(struct lxc_container *c)
 {
        struct stat statbuf;
        bool ret = false;
@@ -339,53 +330,7 @@ out:
        return ret;
 }
 
-#define WRAP_API(rettype, fnname)                                      \
-static rettype fnname(struct lxc_container *c)                         \
-{                                                                      \
-       rettype ret;                                                    \
-       struct lxc_conf *old = current_config;                          \
-       current_config = c ? c->lxc_conf : NULL;                        \
-       ret = do_##fnname(c);                                           \
-       current_config = old;                                           \
-       return ret;                                                     \
-}
-
-#define WRAP_API_1(rettype, fnname, t1)                                        \
-static rettype fnname(struct lxc_container *c, t1 a1)                  \
-{                                                                      \
-       rettype ret;                                                    \
-       struct lxc_conf *old = current_config;                          \
-       current_config = c ? c->lxc_conf : NULL;                        \
-       ret = do_##fnname(c, a1);                                       \
-       current_config = old;                                           \
-       return ret;                                                     \
-}
-
-#define WRAP_API_2(rettype, fnname, t1, t2)                            \
-static rettype fnname(struct lxc_container *c, t1 a1, t2 a2)           \
-{                                                                      \
-       rettype ret;                                                    \
-       struct lxc_conf *old = current_config;                          \
-       current_config = c ? c->lxc_conf : NULL;                        \
-       ret = do_##fnname(c, a1, a2);                                   \
-       current_config = old;                                           \
-       return ret;                                                     \
-}
-
-#define WRAP_API_3(rettype, fnname, t1, t2, t3)                                \
-static rettype fnname(struct lxc_container *c, t1 a1, t2 a2, t3 a3)    \
-{                                                                      \
-       rettype ret;                                                    \
-       struct lxc_conf *old = current_config;                          \
-       current_config = c ? c->lxc_conf : NULL;                        \
-       ret = do_##fnname(c, a1, a2, a3);                               \
-       current_config = old;                                           \
-       return ret;                                                     \
-}
-
-WRAP_API(bool, lxcapi_is_defined)
-
-static const char *do_lxcapi_state(struct lxc_container *c)
+static const char *lxcapi_state(struct lxc_container *c)
 {
        lxc_state_t s;
 
@@ -395,8 +340,6 @@ static const char *do_lxcapi_state(struct lxc_container *c)
        return lxc_state2str(s);
 }
 
-WRAP_API(const char *, lxcapi_state)
-
 static bool is_stopped(struct lxc_container *c)
 {
        lxc_state_t s;
@@ -404,21 +347,19 @@ static bool is_stopped(struct lxc_container *c)
        return (s == STOPPED);
 }
 
-static bool do_lxcapi_is_running(struct lxc_container *c)
+static bool lxcapi_is_running(struct lxc_container *c)
 {
        const char *s;
 
        if (!c)
                return false;
-       s = do_lxcapi_state(c);
+       s = lxcapi_state(c);
        if (!s || strcmp(s, "STOPPED") == 0)
                return false;
        return true;
 }
 
-WRAP_API(bool, lxcapi_is_running)
-
-static bool do_lxcapi_freeze(struct lxc_container *c)
+static bool lxcapi_freeze(struct lxc_container *c)
 {
        int ret;
        if (!c)
@@ -430,9 +371,7 @@ static bool do_lxcapi_freeze(struct lxc_container *c)
        return true;
 }
 
-WRAP_API(bool, lxcapi_freeze)
-
-static bool do_lxcapi_unfreeze(struct lxc_container *c)
+static bool lxcapi_unfreeze(struct lxc_container *c)
 {
        int ret;
        if (!c)
@@ -444,9 +383,7 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c)
        return true;
 }
 
-WRAP_API(bool, lxcapi_unfreeze)
-
-static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd)
+static int lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd)
 {
        int ttyfd;
        if (!c)
@@ -456,24 +393,13 @@ static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *ma
        return ttyfd;
 }
 
-WRAP_API_2(int, lxcapi_console_getfd, int *, int *)
-
 static int lxcapi_console(struct lxc_container *c, int ttynum, int stdinfd,
                          int stdoutfd, int stderrfd, int escape)
 {
-       int ret;
-       struct lxc_conf *old = current_config;
-
-       if (!c)
-               return -1;
-
-       current_config = c->lxc_conf;
-       ret = lxc_console(c, ttynum, stdinfd, stdoutfd, stderrfd, escape);
-       current_config = old;
-       return ret;
+       return lxc_console(c, ttynum, stdinfd, stdoutfd, stderrfd, escape);
 }
 
-static pid_t do_lxcapi_init_pid(struct lxc_container *c)
+static pid_t lxcapi_init_pid(struct lxc_container *c)
 {
        if (!c)
                return -1;
@@ -481,8 +407,6 @@ static pid_t do_lxcapi_init_pid(struct lxc_container *c)
        return lxc_cmd_get_init_pid(c->name, c->config_path);
 }
 
-WRAP_API(pid_t, lxcapi_init_pid)
-
 static bool load_config_locked(struct lxc_container *c, const char *fname)
 {
        if (!c->lxc_conf)
@@ -494,7 +418,7 @@ static bool load_config_locked(struct lxc_container *c, const char *fname)
        return true;
 }
 
-static bool do_lxcapi_load_config(struct lxc_container *c, const char *alt_file)
+static bool lxcapi_load_config(struct lxc_container *c, const char *alt_file)
 {
        bool ret = false, need_disklock = false;
        int lret;
@@ -531,9 +455,7 @@ static bool do_lxcapi_load_config(struct lxc_container *c, const char *alt_file)
        return ret;
 }
 
-WRAP_API_1(bool, lxcapi_load_config, const char *)
-
-static bool do_lxcapi_want_daemonize(struct lxc_container *c, bool state)
+static bool lxcapi_want_daemonize(struct lxc_container *c, bool state)
 {
        if (!c || !c->lxc_conf)
                return false;
@@ -546,9 +468,7 @@ static bool do_lxcapi_want_daemonize(struct lxc_container *c, bool state)
        return true;
 }
 
-WRAP_API_1(bool, lxcapi_want_daemonize, bool)
-
-static bool do_lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
+static bool lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
 {
        if (!c || !c->lxc_conf)
                return false;
@@ -561,9 +481,7 @@ static bool do_lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
        return true;
 }
 
-WRAP_API_1(bool, lxcapi_want_close_all_fds, bool)
-
-static bool do_lxcapi_wait(struct lxc_container *c, const char *state, int timeout)
+static bool lxcapi_wait(struct lxc_container *c, const char *state, int timeout)
 {
        int ret;
 
@@ -574,9 +492,8 @@ static bool do_lxcapi_wait(struct lxc_container *c, const char *state, int timeo
        return ret == 0;
 }
 
-WRAP_API_2(bool, lxcapi_wait, const char *, int)
 
-static bool do_wait_on_daemonized_start(struct lxc_container *c, int pid)
+static bool wait_on_daemonized_start(struct lxc_container *c, int pid)
 {
        /* we'll probably want to make this timeout configurable? */
        int timeout = 5, ret, status;
@@ -588,11 +505,9 @@ static bool do_wait_on_daemonized_start(struct lxc_container *c, int pid)
        ret = waitpid(pid, &status, 0);
        if (ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
                DEBUG("failed waiting for first dual-fork child");
-       return do_lxcapi_wait(c, "RUNNING", timeout);
+       return lxcapi_wait(c, "RUNNING", timeout);
 }
 
-WRAP_API_1(bool, wait_on_daemonized_start, int)
-
 static bool am_single_threaded(void)
 {
        struct dirent dirent, *direntp;
@@ -625,7 +540,7 @@ static bool am_single_threaded(void)
  * I can't decide if it'd be more convenient for callers if we accept '...',
  * or a null-terminated array (i.e. execl vs execv)
  */
-static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const argv[])
+static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv[])
 {
        int ret;
        struct lxc_conf *conf;
@@ -650,7 +565,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
        }
        if (ret == 2) {
                ERROR("Error: %s creation was not completed", c->name);
-               do_lxcapi_destroy(c);
+               c->destroy(c);
                return false;
        } else if (ret == 1) {
                ERROR("Error: creation of %s is ongoing", c->name);
@@ -793,16 +708,6 @@ out:
                return (ret == 0 ? true : false);
 }
 
-static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv[])
-{
-       bool ret;
-       struct lxc_conf *old = current_config;
-       current_config = c ? c->lxc_conf : NULL;
-       ret = do_lxcapi_start(c, useinit, argv);
-       current_config = old;
-       return ret;
-}
-
 /*
  * note there MUST be an ending NULL
  */
@@ -816,9 +721,6 @@ static bool lxcapi_startl(struct lxc_container *c, int useinit, ...)
        if (!c)
                return false;
 
-       struct lxc_conf *old = current_config;
-       current_config = c->lxc_conf;
-
        va_start(ap, useinit);
        inargs = lxc_va_arg_list_to_argv(ap, 0, 1);
        va_end(ap);
@@ -829,7 +731,7 @@ static bool lxcapi_startl(struct lxc_container *c, int useinit, ...)
        }
 
        /* pass NULL if no arguments were supplied */
-       bret = do_lxcapi_start(c, useinit, *inargs ? inargs : NULL);
+       bret = lxcapi_start(c, useinit, *inargs ? inargs : NULL);
 
 out:
        if (inargs) {
@@ -839,11 +741,10 @@ out:
                free(inargs);
        }
 
-       current_config = old;
        return bret;
 }
 
-static bool do_lxcapi_stop(struct lxc_container *c)
+static bool lxcapi_stop(struct lxc_container *c)
 {
        int ret;
 
@@ -855,8 +756,6 @@ static bool do_lxcapi_stop(struct lxc_container *c)
        return ret == 0;
 }
 
-WRAP_API(bool, lxcapi_stop)
-
 static int do_create_container_dir(const char *path, struct lxc_conf *conf)
 {
        int ret = -1, lasterr;
@@ -904,6 +803,9 @@ static bool create_container_dir(struct lxc_container *c)
        return ret == 0;
 }
 
+static const char *lxcapi_get_config_path(struct lxc_container *c);
+static bool lxcapi_set_config_item(struct lxc_container *c, const char *key, const char *v);
+
 /*
  * do_bdev_create: thin wrapper around bdev_create().  Like bdev_create(),
  * it returns a mounted bdev on success, NULL on error.
@@ -923,7 +825,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
                dest = alloca(len);
                ret = snprintf(dest, len, "%s", rpath);
        } else {
-               const char *lxcpath = do_lxcapi_get_config_path(c);
+               const char *lxcpath = lxcapi_get_config_path(c);
                len = strlen(c->name) + strlen(lxcpath) + 9;
                dest = alloca(len);
                ret = snprintf(dest, len, "%s/%s/rootfs", lxcpath, c->name);
@@ -937,7 +839,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
                return NULL;
        }
 
-       do_lxcapi_set_config_item(c, "lxc.rootfs", bdev->src);
+       lxcapi_set_config_item(c, "lxc.rootfs", bdev->src);
 
        /* if we are not root, chown the rootfs dir to root in the
         * target uidmap */
@@ -1314,8 +1216,9 @@ static void lxcapi_clear_config(struct lxc_container *c)
        }
 }
 
-#define do_lxcapi_clear_config(c) lxcapi_clear_config(c)
-
+static bool lxcapi_destroy(struct lxc_container *c);
+static bool container_destroy(struct lxc_container *c);
+static bool get_snappath_dir(struct lxc_container *c, char *snappath);
 /*
  * lxcapi_create:
  * create a container with the given parameters.
@@ -1330,7 +1233,7 @@ static void lxcapi_clear_config(struct lxc_container *c)
  * @argv: the arguments to pass to the template, terminated by NULL.  If no
  * arguments, you can just pass NULL.
  */
-static bool do_lxcapi_create(struct lxc_container *c, const char *t,
+static bool lxcapi_create(struct lxc_container *c, const char *t,
                const char *bdevtype, struct bdev_specs *specs, int flags,
                char *const argv[])
 {
@@ -1356,14 +1259,14 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
         * an existing container.  Return an error, but do NOT delete the
         * container.
         */
-       if (do_lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path &&
+       if (lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path &&
                        access(c->lxc_conf->rootfs.path, F_OK) == 0 && tpath) {
                ERROR("Container %s:%s already exists", c->config_path, c->name);
                goto free_tpath;
        }
 
        if (!c->lxc_conf) {
-               if (!do_lxcapi_load_config(c, lxc_global_config_value("lxc.default_config"))) {
+               if (!c->load_config(c, lxc_global_config_value("lxc.default_config"))) {
                        ERROR("Error loading default configuration file %s", lxc_global_config_value("lxc.default_config"));
                        goto free_tpath;
                }
@@ -1383,7 +1286,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
        if (c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) != 0)
                /* rootfs passed into configuration, but does not exist: error */
                goto out;
-       if (do_lxcapi_is_defined(c) && c->lxc_conf->rootfs.path && !tpath) {
+       if (lxcapi_is_defined(c) && c->lxc_conf->rootfs.path && !tpath) {
                /* Rootfs already existed, user just wanted to save the
                 * loaded configuration */
                ret = true;
@@ -1419,7 +1322,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
                }
 
                /* save config file again to store the new rootfs location */
-               if (!do_lxcapi_save_config(c, NULL)) {
+               if (!c->save_config(c, NULL)) {
                        ERROR("failed to save starting configuration for %s", c->name);
                        // parent task won't see bdev in config so we delete it
                        bdev->ops->umount(bdev);
@@ -1442,7 +1345,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
 
        // now clear out the lxc_conf we have, reload from the created
        // container
-       do_lxcapi_clear_config(c);
+       lxcapi_clear_config(c);
 
        if (t) {
                if (!prepend_lxc_header(c->configfile, tpath, argv)) {
@@ -1463,28 +1366,16 @@ free_tpath:
        return ret;
 }
 
-static bool lxcapi_create(struct lxc_container *c, const char *t,
-               const char *bdevtype, struct bdev_specs *specs, int flags,
-               char *const argv[])
-{
-       bool ret;
-       struct lxc_conf *old = current_config;
-       current_config = c ? c->lxc_conf : NULL;
-       ret = do_lxcapi_create(c, t, bdevtype, specs, flags, argv);
-       current_config = old;
-       return ret;
-}
-
-static bool do_lxcapi_reboot(struct lxc_container *c)
+static bool lxcapi_reboot(struct lxc_container *c)
 {
        pid_t pid;
        int rebootsignal = SIGINT;
 
        if (!c)
                return false;
-       if (!do_lxcapi_is_running(c))
+       if (!c->is_running(c))
                return false;
-       pid = do_lxcapi_init_pid(c);
+       pid = c->init_pid(c);
        if (pid <= 0)
                return false;
        if (c->lxc_conf && c->lxc_conf->rebootsignal)
@@ -1495,9 +1386,7 @@ static bool do_lxcapi_reboot(struct lxc_container *c)
 
 }
 
-WRAP_API(bool, lxcapi_reboot)
-
-static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
+static bool lxcapi_shutdown(struct lxc_container *c, int timeout)
 {
        bool retv;
        pid_t pid;
@@ -1506,20 +1395,18 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
        if (!c)
                return false;
 
-       if (!do_lxcapi_is_running(c))
+       if (!c->is_running(c))
                return true;
-       pid = do_lxcapi_init_pid(c);
+       pid = c->init_pid(c);
        if (pid <= 0)
                return true;
        if (c->lxc_conf && c->lxc_conf->haltsignal)
                haltsignal = c->lxc_conf->haltsignal;
        kill(pid, haltsignal);
-       retv = do_lxcapi_wait(c, "STOPPED", timeout);
+       retv = c->wait(c, "STOPPED", timeout);
        return retv;
 }
 
-WRAP_API_1(bool, lxcapi_shutdown, int)
-
 static bool lxcapi_createl(struct lxc_container *c, const char *t,
                const char *bdevtype, struct bdev_specs *specs, int flags, ...)
 {
@@ -1530,9 +1417,6 @@ static bool lxcapi_createl(struct lxc_container *c, const char *t,
        if (!c)
                return false;
 
-       struct lxc_conf *old = current_config;
-       current_config = c->lxc_conf;
-
        /*
         * since we're going to wait for create to finish, I don't think we
         * need to get a copy of the arguments.
@@ -1545,11 +1429,10 @@ static bool lxcapi_createl(struct lxc_container *c, const char *t,
                goto out;
        }
 
-       bret = do_lxcapi_create(c, t, bdevtype, specs, flags, args);
+       bret = c->create(c, t, bdevtype, specs, flags, args);
 
 out:
        free(args);
-       current_config = old;
        return bret;
 }
 
@@ -1567,7 +1450,7 @@ static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key)
                WARN("Error clearing configuration for %s", key);
 }
 
-static bool do_lxcapi_clear_config_item(struct lxc_container *c, const char *key)
+static bool lxcapi_clear_config_item(struct lxc_container *c, const char *key)
 {
        int ret;
 
@@ -1582,11 +1465,9 @@ static bool do_lxcapi_clear_config_item(struct lxc_container *c, const char *key
        return ret == 0;
 }
 
-WRAP_API_1(bool, lxcapi_clear_config_item, const char *)
-
 static inline bool enter_net_ns(struct lxc_container *c)
 {
-       pid_t pid = do_lxcapi_init_pid(c);
+       pid_t pid = c->init_pid(c);
 
        if ((geteuid() != 0 || (c->lxc_conf && !lxc_list_empty(&c->lxc_conf->id_map))) && access("/proc/self/ns/user", F_OK) == 0) {
                if (!switch_to_ns(pid, "user"))
@@ -1666,7 +1547,7 @@ static bool remove_from_array(char ***names, char *cname, int size)
        return false;
 }
 
-static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
+static char** lxcapi_get_interfaces(struct lxc_container *c)
 {
        pid_t pid;
        int i, count = 0, pipefd[2];
@@ -1753,9 +1634,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
        return interfaces;
 }
 
-WRAP_API(char **, lxcapi_get_interfaces)
-
-static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface, const char* family, int scope)
+static char** lxcapi_get_ips(struct lxc_container *c, const char* interface, const char* family, int scope)
 {
        pid_t pid;
        int i, count = 0, pipefd[2];
@@ -1872,9 +1751,7 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
        return addresses;
 }
 
-WRAP_API_3(char **, lxcapi_get_ips, const char *, const char *, int)
-
-static int do_lxcapi_get_config_item(struct lxc_container *c, const char *key, char *retv, int inlen)
+static int lxcapi_get_config_item(struct lxc_container *c, const char *key, char *retv, int inlen)
 {
        int ret;
 
@@ -1887,9 +1764,7 @@ static int do_lxcapi_get_config_item(struct lxc_container *c, const char *key, c
        return ret;
 }
 
-WRAP_API_3(int, lxcapi_get_config_item, const char *, char *, int)
-
-static char* do_lxcapi_get_running_config_item(struct lxc_container *c, const char *key)
+static char* lxcapi_get_running_config_item(struct lxc_container *c, const char *key)
 {
        char *ret;
 
@@ -1897,14 +1772,12 @@ static char* do_lxcapi_get_running_config_item(struct lxc_container *c, const ch
                return NULL;
        if (container_mem_lock(c))
                return NULL;
-       ret = lxc_cmd_get_config_item(c->name, key, do_lxcapi_get_config_path(c));
+       ret = lxc_cmd_get_config_item(c->name, key, c->get_config_path(c));
        container_mem_unlock(c);
        return ret;
 }
 
-WRAP_API_1(char *, lxcapi_get_running_config_item, const char *)
-
-static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
+static int lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
 {
        if (!key)
                return lxc_listconfigs(retv, inlen);
@@ -1924,9 +1797,7 @@ static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *re
        return ret;
 }
 
-WRAP_API_3(int, lxcapi_get_keys, const char *, char *, int)
-
-static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file)
+static bool lxcapi_save_config(struct lxc_container *c, const char *alt_file)
 {
        FILE *fout;
        bool ret = false, need_disklock = false;
@@ -1939,7 +1810,7 @@ static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file)
 
        // If we haven't yet loaded a config, load the stock config
        if (!c->lxc_conf) {
-               if (!do_lxcapi_load_config(c, lxc_global_config_value("lxc.default_config"))) {
+               if (!c->load_config(c, lxc_global_config_value("lxc.default_config"))) {
                        ERROR("Error loading default configuration file %s while saving %s", lxc_global_config_value("lxc.default_config"), c->name);
                        return false;
                }
@@ -1979,8 +1850,6 @@ out:
        return ret;
 }
 
-WRAP_API_1(bool, lxcapi_save_config, const char *)
-
 static bool mod_rdep(struct lxc_container *c, bool inc)
 {
        char path[MAXPATHLEN];
@@ -2169,7 +2038,7 @@ static bool container_destroy(struct lxc_container *c)
        bool bret = false;
        int ret;
 
-       if (!c || !do_lxcapi_is_defined(c))
+       if (!c || !lxcapi_is_defined(c))
                return false;
 
        if (container_disk_lock(c))
@@ -2194,7 +2063,7 @@ static bool container_destroy(struct lxc_container *c)
 
        mod_all_rdeps(c, false);
 
-       const char *p1 = do_lxcapi_get_config_path(c);
+       const char *p1 = lxcapi_get_config_path(c);
        char *path = alloca(strlen(p1) + strlen(c->name) + 2);
        sprintf(path, "%s/%s", p1, c->name);
        if (am_unpriv())
@@ -2212,7 +2081,7 @@ out:
        return bret;
 }
 
-static bool do_lxcapi_destroy(struct lxc_container *c)
+static bool lxcapi_destroy(struct lxc_container *c)
 {
        if (!c || !lxcapi_is_defined(c))
                return false;
@@ -2229,9 +2098,9 @@ static bool do_lxcapi_destroy(struct lxc_container *c)
        return container_destroy(c);
 }
 
-WRAP_API(bool, lxcapi_destroy)
+static bool lxcapi_snapshot_destroy_all(struct lxc_container *c);
 
-static bool do_lxcapi_destroy_with_snapshots(struct lxc_container *c)
+static bool lxcapi_destroy_with_snapshots(struct lxc_container *c)
 {
        if (!c || !lxcapi_is_defined(c))
                return false;
@@ -2242,8 +2111,6 @@ static bool do_lxcapi_destroy_with_snapshots(struct lxc_container *c)
        return lxcapi_destroy(c);
 }
 
-WRAP_API(bool, lxcapi_destroy_with_snapshots)
-
 static bool set_config_item_locked(struct lxc_container *c, const char *key, const char *v)
 {
        struct lxc_config_t *config;
@@ -2260,7 +2127,7 @@ static bool set_config_item_locked(struct lxc_container *c, const char *key, con
        return do_append_unexp_config_line(c->lxc_conf, key, v);
 }
 
-static bool do_lxcapi_set_config_item(struct lxc_container *c, const char *key, const char *v)
+static bool lxcapi_set_config_item(struct lxc_container *c, const char *key, const char *v)
 {
        bool b = false;
 
@@ -2276,8 +2143,6 @@ static bool do_lxcapi_set_config_item(struct lxc_container *c, const char *key,
        return b;
 }
 
-WRAP_API_2(bool, lxcapi_set_config_item, const char *, const char *)
-
 static char *lxcapi_config_file_name(struct lxc_container *c)
 {
        if (!c || !c->configfile)
@@ -2325,7 +2190,7 @@ static bool set_config_filename(struct lxc_container *c)
        return true;
 }
 
-static bool do_lxcapi_set_config_path(struct lxc_container *c, const char *path)
+static bool lxcapi_set_config_path(struct lxc_container *c, const char *path)
 {
        char *p;
        bool b = false;
@@ -2363,9 +2228,8 @@ err:
        return b;
 }
 
-WRAP_API_1(bool, lxcapi_set_config_path, const char *)
 
-static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsys, const char *value)
+static bool lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsys, const char *value)
 {
        int ret;
 
@@ -2384,9 +2248,7 @@ static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsy
        return ret == 0;
 }
 
-WRAP_API_2(bool, lxcapi_set_cgroup_item, const char *, const char *)
-
-static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, char *retv, int inlen)
+static int lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, char *retv, int inlen)
 {
        int ret;
 
@@ -2405,8 +2267,6 @@ static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys
        return ret;
 }
 
-WRAP_API_3(int, lxcapi_get_cgroup_item, const char *, char *, int)
-
 const char *lxc_get_global_config_item(const char *key)
 {
        return lxc_global_config_value(key);
@@ -2523,7 +2383,7 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
                ERROR("Error saving new hooks in clone");
                return -1;
        }
-       do_lxcapi_save_config(c, NULL);
+       c->save_config(c, NULL);
        return 0;
 }
 
@@ -2795,7 +2655,7 @@ static int create_file_dirname(char *path, struct lxc_conf *conf)
        return ret;
 }
 
-static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char *newname,
+static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
                const char *lxcpath, int flags,
                const char *bdevtype, const char *bdevdata, uint64_t newsize,
                char **hookargs)
@@ -2808,7 +2668,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
        FILE *fout;
        pid_t pid;
 
-       if (!c || !do_lxcapi_is_defined(c))
+       if (!c || !c->is_defined(c))
                return NULL;
 
        if (container_mem_lock(c))
@@ -2823,7 +2683,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
        if (!newname)
                newname = c->name;
        if (!lxcpath)
-               lxcpath = do_lxcapi_get_config_path(c);
+               lxcpath = c->get_config_path(c);
        ret = snprintf(newpath, MAXPATHLEN, "%s/%s/config", lxcpath, newname);
        if (ret < 0 || ret >= MAXPATHLEN) {
                SYSERROR("clone: failed making config pathname");
@@ -2952,20 +2812,7 @@ out:
        return NULL;
 }
 
-static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
-               const char *lxcpath, int flags,
-               const char *bdevtype, const char *bdevdata, uint64_t newsize,
-               char **hookargs)
-{
-       struct lxc_container * ret;
-       struct lxc_conf *old = current_config;
-       current_config = c ? c->lxc_conf : NULL;
-       ret = do_lxcapi_clone(c, newname, lxcpath, flags, bdevtype, bdevdata, newsize, hookargs);
-       current_config = old;
-       return ret;
-}
-
-static bool do_lxcapi_rename(struct lxc_container *c, const char *newname)
+static bool lxcapi_rename(struct lxc_container *c, const char *newname)
 {
        struct bdev *bdev;
        struct lxc_container *newc;
@@ -3000,24 +2847,15 @@ static bool do_lxcapi_rename(struct lxc_container *c, const char *newname)
        return true;
 }
 
-WRAP_API_1(bool, lxcapi_rename, const char *)
-
 static int lxcapi_attach(struct lxc_container *c, lxc_attach_exec_t exec_function, void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process)
 {
-       struct lxc_conf *old = current_config;
-       int ret;
-
        if (!c)
                return -1;
 
-       current_config = c->lxc_conf;
-
-       ret = lxc_attach(c->name, c->config_path, exec_function, exec_payload, options, attached_process);
-       current_config = old;
-       return ret;
+       return lxc_attach(c->name, c->config_path, exec_function, exec_payload, options, attached_process);
 }
 
-static int do_lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[])
+static int lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[])
 {
        lxc_attach_command_t command;
        pid_t pid;
@@ -3036,16 +2874,6 @@ static int do_lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options
        return lxc_wait_for_pid_status(pid);
 }
 
-static int lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[])
-{
-       int ret;
-       struct lxc_conf *old = current_config;
-       current_config = c ? c->lxc_conf : NULL;
-       ret = do_lxcapi_attach_run_wait(c, options, program, argv);
-       current_config = old;
-       return ret;
-}
-
 static int get_next_index(const char *lxcpath, char *cname)
 {
        char *fname;
@@ -3089,7 +2917,7 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
        return true;
 }
 
-static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
+static int lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
 {
        int i, flags, ret;
        struct lxc_container *c2;
@@ -3131,7 +2959,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
                ERROR("and keep the original container pristine.");
                flags &= ~LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
        }
-       c2 = do_lxcapi_clone(c, newname, snappath, flags, NULL, NULL, 0, NULL);
+       c2 = c->clone(c, newname, snappath, flags, NULL, NULL, 0, NULL);
        if (!c2) {
                ERROR("clone of %s:%s failed", c->config_path, c->name);
                return -1;
@@ -3179,8 +3007,6 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
        return i;
 }
 
-WRAP_API_1(int, lxcapi_snapshot, const char *)
-
 static void lxcsnap_free(struct lxc_snapshot *s)
 {
        free(s->name);
@@ -3235,7 +3061,7 @@ static char *get_timestamp(char* snappath, char *name)
        return s;
 }
 
-static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret_snaps)
+static int lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret_snaps)
 {
        char snappath[MAXPATHLEN], path2[MAXPATHLEN];
        int count = 0, ret;
@@ -3311,9 +3137,7 @@ out_free:
        return -1;
 }
 
-WRAP_API_1(int, lxcapi_snapshot_list, struct lxc_snapshot **)
-
-static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname)
+static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname)
 {
        char clonelxcpath[MAXPATHLEN];
        int flags = 0;
@@ -3374,8 +3198,6 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
        return b;
 }
 
-WRAP_API_2(bool, lxcapi_snapshot_restore, const char *, const char *)
-
 static bool do_snapshot_destroy(const char *snapname, const char *clonelxcpath)
 {
        struct lxc_container *snap = NULL;
@@ -3387,7 +3209,7 @@ static bool do_snapshot_destroy(const char *snapname, const char *clonelxcpath)
                goto err;
        }
 
-       if (!do_lxcapi_destroy(snap)) {
+       if (!lxcapi_destroy(snap)) {
                ERROR("Could not destroy snapshot %s", snapname);
                goto err;
        }
@@ -3431,7 +3253,7 @@ static bool remove_all_snapshots(const char *path)
        return bret;
 }
 
-static bool do_lxcapi_snapshot_destroy(struct lxc_container *c, const char *snapname)
+static bool lxcapi_snapshot_destroy(struct lxc_container *c, const char *snapname)
 {
        char clonelxcpath[MAXPATHLEN];
 
@@ -3444,9 +3266,7 @@ static bool do_lxcapi_snapshot_destroy(struct lxc_container *c, const char *snap
        return do_snapshot_destroy(snapname, clonelxcpath);
 }
 
-WRAP_API_1(bool, lxcapi_snapshot_destroy, const char *)
-
-static bool do_lxcapi_snapshot_destroy_all(struct lxc_container *c)
+static bool lxcapi_snapshot_destroy_all(struct lxc_container *c)
 {
        char clonelxcpath[MAXPATHLEN];
 
@@ -3459,15 +3279,11 @@ static bool do_lxcapi_snapshot_destroy_all(struct lxc_container *c)
        return remove_all_snapshots(clonelxcpath);
 }
 
-WRAP_API(bool, lxcapi_snapshot_destroy_all)
-
-static bool do_lxcapi_may_control(struct lxc_container *c)
+static bool lxcapi_may_control(struct lxc_container *c)
 {
        return lxc_try_cmd(c->name, c->config_path) == 0;
 }
 
-WRAP_API(bool, lxcapi_may_control)
-
 static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
                struct stat *st)
 {
@@ -3531,7 +3347,7 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path
        const char *p;
 
        /* make sure container is running */
-       if (!do_lxcapi_is_running(c)) {
+       if (!c->is_running(c)) {
                ERROR("container is not running");
                return false;
        }
@@ -3555,17 +3371,17 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path
        if (ret < 0 || ret >= MAX_BUFFER)
                return false;
 
-       if (!do_add_remove_node(do_lxcapi_init_pid(c), p, add, &st))
+       if (!do_add_remove_node(c->init_pid(c), p, add, &st))
                return false;
 
        /* add or remove device to/from cgroup access list */
        if (add) {
-               if (!do_lxcapi_set_cgroup_item(c, "devices.allow", value)) {
+               if (!c->set_cgroup_item(c, "devices.allow", value)) {
                        ERROR("set_cgroup_item failed while adding the device node");
                        return false;
                }
        } else {
-               if (!do_lxcapi_set_cgroup_item(c, "devices.deny", value)) {
+               if (!c->set_cgroup_item(c, "devices.deny", value)) {
                        ERROR("set_cgroup_item failed while removing the device node");
                        return false;
                }
@@ -3574,7 +3390,7 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path
        return true;
 }
 
-static bool do_lxcapi_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
+static bool lxcapi_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
 {
        if (am_unpriv()) {
                ERROR(NOT_SUPPORTED_ERROR, __FUNCTION__);
@@ -3583,9 +3399,7 @@ static bool do_lxcapi_add_device_node(struct lxc_container *c, const char *src_p
        return add_remove_device_node(c, src_path, dest_path, true);
 }
 
-WRAP_API_2(bool, lxcapi_add_device_node, const char *, const char *)
-
-static bool do_lxcapi_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
+static bool lxcapi_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
 {
        if (am_unpriv()) {
                ERROR(NOT_SUPPORTED_ERROR, __FUNCTION__);
@@ -3594,9 +3408,7 @@ static bool do_lxcapi_remove_device_node(struct lxc_container *c, const char *sr
        return add_remove_device_node(c, src_path, dest_path, false);
 }
 
-WRAP_API_2(bool, lxcapi_remove_device_node, const char *, const char *)
-
-static bool do_lxcapi_attach_interface(struct lxc_container *c, const char *ifname,
+static bool lxcapi_attach_interface(struct lxc_container *c, const char *ifname,
                                const char *dst_ifname)
 {
        int ret = 0;
@@ -3619,7 +3431,7 @@ static bool do_lxcapi_attach_interface(struct lxc_container *c, const char *ifna
                        goto err;
        }
 
-       ret = lxc_netdev_move_by_name(ifname, do_lxcapi_init_pid(c), dst_ifname);
+       ret = lxc_netdev_move_by_name(ifname, c->init_pid(c), dst_ifname);
        if (ret)
                goto err;
 
@@ -3629,9 +3441,7 @@ err:
        return false;
 }
 
-WRAP_API_2(bool, lxcapi_attach_interface, const char *, const char *)
-
-static bool do_lxcapi_detach_interface(struct lxc_container *c, const char *ifname,
+static bool lxcapi_detach_interface(struct lxc_container *c, const char *ifname,
                                        const char *dst_ifname)
 {
        pid_t pid, pid_outside;
@@ -3686,8 +3496,6 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c, const char *ifna
        return true;
 }
 
-WRAP_API_2(bool, lxcapi_detach_interface, const char *, const char *)
-
 struct criu_opts {
        /* The type of criu invocation, one of "dump" or "restore" */
        char *action;
@@ -4049,7 +3857,7 @@ out:
        return true;
 }
 
-static bool do_lxcapi_checkpoint(struct lxc_container *c, char *directory, bool stop, bool verbose)
+static bool lxcapi_checkpoint(struct lxc_container *c, char *directory, bool stop, bool verbose)
 {
        pid_t pid;
        int status;
@@ -4094,8 +3902,6 @@ static bool do_lxcapi_checkpoint(struct lxc_container *c, char *directory, bool
        }
 }
 
-WRAP_API_3(bool, lxcapi_checkpoint, char *, bool, bool)
-
 static bool restore_net_info(struct lxc_container *c)
 {
        struct lxc_list *it;
@@ -4274,7 +4080,7 @@ out:
        exit(1);
 }
 
-static bool do_lxcapi_restore(struct lxc_container *c, char *directory, bool verbose)
+static bool lxcapi_restore(struct lxc_container *c, char *directory, bool verbose)
 {
        pid_t pid;
        int status, nread;
@@ -4328,8 +4134,6 @@ err_wait:
        return false;
 }
 
-WRAP_API_2(bool, lxcapi_restore, char *, bool)
-
 static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...)
 {
        va_list ap;
@@ -4339,24 +4143,18 @@ static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t
        if (!c)
                return -1;
 
-       struct lxc_conf *old = current_config;
-       current_config = c->lxc_conf;
-
        va_start(ap, arg);
        argv = lxc_va_arg_list_to_argv_const(ap, 1);
        va_end(ap);
 
        if (!argv) {
                ERROR("Memory allocation error.");
-               ret = -1;
-               goto out;
+               return -1;
        }
        argv[0] = arg;
 
-       ret = do_lxcapi_attach_run_wait(c, options, program, (const char * const *)argv);
+       ret = lxcapi_attach_run_wait(c, options, program, (const char * const *)argv);
        free((void*)argv);
-out:
-       current_config = old;
        return ret;
 }
 
@@ -4473,6 +4271,12 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
        c->checkpoint = lxcapi_checkpoint;
        c->restore = lxcapi_restore;
 
+       /* we'll allow the caller to update these later */
+       if (lxc_log_init(NULL, "none", NULL, "lxc_container", 0, c->config_path)) {
+               fprintf(stderr, "failed to open log\n");
+               goto err;
+       }
+
        return c;
 
 err:
@@ -4546,7 +4350,7 @@ int list_defined_containers(const char *lxcpath, char ***names, struct lxc_conta
                                        goto free_bad;
                        continue;
                }
-               if (!do_lxcapi_is_defined(c)) {
+               if (!lxcapi_is_defined(c)) {
                        INFO("Container %s:%s has a config but is not defined",
                                lxcpath, direntp->d_name);
                        if (names)