Commit 17f48b96 by Serge Hallyn Committed by Stéphane Graber

Revert (by hand) "logs: introduce a thread-local 'current' lxc_config"

This is hopefully temporary - it works great for lxc itself, but seems to be upsetting golang. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Tested-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
parent 5dc49b29
...@@ -248,7 +248,6 @@ endif ...@@ -248,7 +248,6 @@ endif
init_lxc_static_LDFLAGS = -static init_lxc_static_LDFLAGS = -static
init_lxc_static_LDADD = @CAP_LIBS@ init_lxc_static_LDADD = @CAP_LIBS@
init_lxc_static_CFLAGS = $(AM_CFLAGS) -DNO_LXC_CONF
endif endif
install-exec-local: install-soPROGRAMS install-exec-local: install-soPROGRAMS
......
...@@ -178,17 +178,6 @@ struct caps_opt { ...@@ -178,17 +178,6 @@ struct caps_opt {
int value; 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. */ /* Declare this here, since we don't want to reshuffle the whole file. */
static int in_caplist(int cap, struct lxc_list *caps); static int in_caplist(int cap, struct lxc_list *caps);
...@@ -2584,7 +2573,6 @@ struct lxc_conf *lxc_conf_init(void) ...@@ -2584,7 +2573,6 @@ struct lxc_conf *lxc_conf_init(void)
return NULL; return NULL;
} }
new->kmsg = 0; new->kmsg = 0;
new->logfd = -1;
lxc_list_init(&new->cgroup); lxc_list_init(&new->cgroup);
lxc_list_init(&new->network); lxc_list_init(&new->network);
lxc_list_init(&new->mount_list); lxc_list_init(&new->mount_list);
...@@ -4252,8 +4240,6 @@ void lxc_conf_free(struct lxc_conf *conf) ...@@ -4252,8 +4240,6 @@ void lxc_conf_free(struct lxc_conf *conf)
free(conf->rootfs.path); free(conf->rootfs.path);
free(conf->rootfs.pivot); free(conf->rootfs.pivot);
free(conf->logfile); free(conf->logfile);
if (conf->logfd != -1)
close(conf->logfd);
free(conf->utsname); free(conf->utsname);
free(conf->ttydir); free(conf->ttydir);
free(conf->fstab); free(conf->fstab);
......
...@@ -335,7 +335,6 @@ struct lxc_conf { ...@@ -335,7 +335,6 @@ struct lxc_conf {
// store the config file specified values here. // store the config file specified values here.
char *logfile; // the logfile as specifed in config char *logfile; // the logfile as specifed in config
int loglevel; // loglevel as specifed in config (if any) int loglevel; // loglevel as specifed in config (if any)
int logfd;
int inherit_ns_fd[LXC_NS_MAX]; int inherit_ns_fd[LXC_NS_MAX];
...@@ -365,12 +364,6 @@ struct lxc_conf { ...@@ -365,12 +364,6 @@ struct lxc_conf {
char *init_cmd; 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, int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
const char *lxcpath, char *argv[]); const char *lxcpath, char *argv[]);
......
...@@ -1169,15 +1169,15 @@ static int config_lsm_se_context(const char *key, const char *value, ...@@ -1169,15 +1169,15 @@ static int config_lsm_se_context(const char *key, const char *value,
} }
static int config_logfile(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; int ret;
// store these values in the lxc_conf, and then try to set for // store these values in the lxc_conf, and then try to set for
// actual current logging. // actual current logging.
ret = config_path_item(&c->logfile, value); ret = config_path_item(&lxc_conf->logfile, value);
if (ret == 0) if (ret == 0)
ret = lxc_log_set_file(&c->logfd, c->logfile); ret = lxc_log_set_file(lxc_conf->logfile);
return ret; return ret;
} }
...@@ -1196,7 +1196,7 @@ static int config_loglevel(const char *key, const char *value, ...@@ -1196,7 +1196,7 @@ static int config_loglevel(const char *key, const char *value,
// store these values in the lxc_conf, and then try to set for // store these values in the lxc_conf, and then try to set for
// actual current logging. // actual current logging.
lxc_conf->loglevel = newlevel; 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, static int config_autodev(const char *key, const char *value,
...@@ -2367,9 +2367,9 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv, ...@@ -2367,9 +2367,9 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
else if (strcmp(key, "lxc.se_context") == 0) else if (strcmp(key, "lxc.se_context") == 0)
v = c->lsm_se_context; v = c->lsm_se_context;
else if (strcmp(key, "lxc.logfile") == 0) else if (strcmp(key, "lxc.logfile") == 0)
v = c->logfile; v = lxc_log_get_file();
else if (strcmp(key, "lxc.loglevel") == 0) 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 else if (strcmp(key, "lxc.cgroup") == 0) // all cgroup info
return lxc_get_cgroup_entry(c, retv, inlen, "all"); return lxc_get_cgroup_entry(c, retv, inlen, "all");
else if (strncmp(key, "lxc.cgroup.", 11) == 0) // specific cgroup info else if (strncmp(key, "lxc.cgroup.", 11) == 0) // specific cgroup info
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <pthread.h>
#define __USE_GNU /* for *_CLOEXEC */ #define __USE_GNU /* for *_CLOEXEC */
...@@ -41,44 +40,27 @@ ...@@ -41,44 +40,27 @@
#define LXC_LOG_PREFIX_SIZE 32 #define LXC_LOG_PREFIX_SIZE 32
#define LXC_LOG_BUFFER_SIZE 512 #define LXC_LOG_BUFFER_SIZE 512
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; #ifdef HAVE_TLS
static void lock_mutex(pthread_mutex_t *l) __thread int lxc_log_fd = -1;
{ static __thread char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
int ret; static __thread char *log_fname = NULL;
/* command line values for logfile or logpriority should always override
if ((ret = pthread_mutex_lock(l)) != 0) { * values from the configuration file or defaults
fprintf(stderr, "pthread_mutex_lock returned:%d %s\n", ret, strerror(ret)); */
exit(1); static __thread int lxc_logfile_specified = 0;
} static __thread int lxc_loglevel_specified = 0;
} static __thread int lxc_quiet_specified = 0;
#else
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);
}
int lxc_log_fd = -1; 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_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
static char *log_fname = NULL; 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); lxc_log_define(lxc_log, lxc);
...@@ -103,17 +85,8 @@ static int log_append_logfile(const struct lxc_log_appender *appender, ...@@ -103,17 +85,8 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
char buffer[LXC_LOG_BUFFER_SIZE]; char buffer[LXC_LOG_BUFFER_SIZE];
int n; int n;
int ms; 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) if (lxc_log_fd == -1)
fd_to_use = lxc_log_fd;
if (fd_to_use == -1)
return 0; return 0;
ms = event->timestamp.tv_usec / 1000; ms = event->timestamp.tv_usec / 1000;
...@@ -138,7 +111,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender, ...@@ -138,7 +111,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
buffer[n] = '\n'; 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 = { static struct lxc_log_appender log_appender_stderr = {
...@@ -163,7 +136,7 @@ static struct lxc_log_category log_root = { ...@@ -163,7 +136,7 @@ static struct lxc_log_category log_root = {
struct lxc_log_category lxc_log_category_lxc = { struct lxc_log_category lxc_log_category_lxc = {
.name = "lxc", .name = "lxc",
.priority = LXC_LOG_PRIORITY_ERROR, .priority = LXC_LOG_PRIORITY_ERROR,
.appender = &log_appender_logfile, .appender = &log_appender_stderr,
.parent = &log_root .parent = &log_root
}; };
...@@ -332,11 +305,6 @@ static int _lxc_log_set_file(const char *name, const char *lxcpath, int create_d ...@@ -332,11 +305,6 @@ static int _lxc_log_set_file(const char *name, const char *lxcpath, int create_d
return ret; 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, extern int lxc_log_init(const char *name, const char *file,
const char *priority, const char *prefix, int quiet, const char *priority, const char *prefix, int quiet,
const char *lxcpath) const char *lxcpath)
...@@ -352,12 +320,10 @@ extern int lxc_log_init(const char *name, const char *file, ...@@ -352,12 +320,10 @@ extern int lxc_log_init(const char *name, const char *file,
if (priority) if (priority)
lxc_priority = lxc_log_priority_to_int(priority); lxc_priority = lxc_log_priority_to_int(priority);
if (!lxc_loglevel_specified) {
lxc_log_category_lxc.priority = lxc_priority; lxc_log_category_lxc.priority = lxc_priority;
lxc_loglevel_specified = 1;
}
if (!lxc_quiet_specified) { if (!lxc_quiet_specified) {
lxc_log_category_lxc.appender = &log_appender_logfile;
if (!quiet) if (!quiet)
lxc_log_category_lxc.appender->next = &log_appender_stderr; lxc_log_category_lxc.appender->next = &log_appender_stderr;
} }
...@@ -369,7 +335,6 @@ extern int lxc_log_init(const char *name, const char *file, ...@@ -369,7 +335,6 @@ extern int lxc_log_init(const char *name, const char *file,
if (strcmp(file, "none") == 0) if (strcmp(file, "none") == 0)
return 0; return 0;
ret = __lxc_log_set_file(file, 1); ret = __lxc_log_set_file(file, 1);
lxc_log_use_global_fd = 1;
} else { } else {
/* if no name was specified, there nothing to do */ /* if no name was specified, there nothing to do */
if (!name) if (!name)
...@@ -420,13 +385,15 @@ extern void lxc_log_close(void) ...@@ -420,13 +385,15 @@ extern void lxc_log_close(void)
* happens after processing command line arguments, which override the .conf * happens after processing command line arguments, which override the .conf
* settings. So only set the level if previously unset. * 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) { if (level < 0 || level >= LXC_LOG_PRIORITY_NOTSET) {
ERROR("invalid log priority %d", level); ERROR("invalid log priority %d", level);
return -1; return -1;
} }
*dest = level; lxc_log_category_lxc.priority = level;
return 0; return 0;
} }
...@@ -448,23 +415,11 @@ extern bool lxc_log_has_valid_level(void) ...@@ -448,23 +415,11 @@ extern bool lxc_log_has_valid_level(void)
* happens after processing command line arguments, which override the .conf * happens after processing command line arguments, which override the .conf
* settings. So only set the file if previously unset. * 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) { if (lxc_logfile_specified)
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; return 0;
return __lxc_log_set_file(fname, 0);
} }
extern const char *lxc_log_get_file(void) extern const char *lxc_log_get_file(void)
...@@ -485,6 +440,11 @@ extern const char *lxc_log_get_prefix(void) ...@@ -485,6 +440,11 @@ extern const char *lxc_log_get_prefix(void)
extern void lxc_log_options_no_override() extern void lxc_log_options_no_override()
{ {
lxc_quiet_specified = 1; if (lxc_log_get_file())
lxc_logfile_specified = 1;
if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET)
lxc_loglevel_specified = 1; lxc_loglevel_specified = 1;
lxc_quiet_specified = 1;
} }
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
#include <strings.h> #include <strings.h>
#include <stdbool.h> #include <stdbool.h>
#include "conf.h"
#ifndef O_CLOEXEC #ifndef O_CLOEXEC
#define O_CLOEXEC 02000000 #define O_CLOEXEC 02000000
#endif #endif
...@@ -106,10 +104,6 @@ struct lxc_log_category { ...@@ -106,10 +104,6 @@ struct lxc_log_category {
const struct lxc_log_category *parent; 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 * Returns true if the chained priority is equal to or higher than
* given priority. * given priority.
...@@ -122,14 +116,7 @@ lxc_log_priority_is_enabled(const struct lxc_log_category* category, ...@@ -122,14 +116,7 @@ lxc_log_priority_is_enabled(const struct lxc_log_category* category,
category->parent) category->parent)
category = category->parent; category = category->parent;
int cmp_prio = category->priority; return priority >= 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;
} }
/* /*
...@@ -307,14 +294,18 @@ ATTR_UNUSED static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo, \ ...@@ -307,14 +294,18 @@ ATTR_UNUSED static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo, \
ERROR("%s - " format, strerror(errno), ##__VA_ARGS__); \ ERROR("%s - " format, strerror(errno), ##__VA_ARGS__); \
} while (0) } while (0)
#ifdef HAVE_TLS
extern __thread int lxc_log_fd;
#else
extern int lxc_log_fd; extern int lxc_log_fd;
#endif
extern int lxc_log_init(const char *name, const char *file, extern int lxc_log_init(const char *name, const char *file,
const char *priority, const char *prefix, int quiet, const char *priority, const char *prefix, int quiet,
const char *lxcpath); const char *lxcpath);
extern int lxc_log_set_file(int *fd, const char *fname); extern int lxc_log_set_file(const char *fname);
extern int lxc_log_set_level(int *dest, int level); extern int lxc_log_set_level(int level);
extern void lxc_log_set_prefix(const char *prefix); extern void lxc_log_set_prefix(const char *prefix);
extern const char *lxc_log_get_file(void); extern const char *lxc_log_get_file(void);
extern int lxc_log_get_level(void); extern int lxc_log_get_level(void);
......
...@@ -91,15 +91,6 @@ return -1; ...@@ -91,15 +91,6 @@ return -1;
lxc_log_define(lxc_container, lxc); 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) static bool config_file_exists(const char *lxcpath, const char *cname)
{ {
/* $lxcpath + '/' + $cname + '/config' + \0 */ /* $lxcpath + '/' + $cname + '/config' + \0 */
...@@ -316,7 +307,7 @@ int lxc_container_put(struct lxc_container *c) ...@@ -316,7 +307,7 @@ int lxc_container_put(struct lxc_container *c)
return 0; return 0;
} }
static bool do_lxcapi_is_defined(struct lxc_container *c) static bool lxcapi_is_defined(struct lxc_container *c)
{ {
struct stat statbuf; struct stat statbuf;
bool ret = false; bool ret = false;
...@@ -339,53 +330,7 @@ out: ...@@ -339,53 +330,7 @@ out:
return ret; return ret;
} }
#define WRAP_API(rettype, fnname) \ static const char *lxcapi_state(struct lxc_container *c)
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)
{ {
lxc_state_t s; lxc_state_t s;
...@@ -395,8 +340,6 @@ static const char *do_lxcapi_state(struct lxc_container *c) ...@@ -395,8 +340,6 @@ static const char *do_lxcapi_state(struct lxc_container *c)
return lxc_state2str(s); return lxc_state2str(s);
} }
WRAP_API(const char *, lxcapi_state)
static bool is_stopped(struct lxc_container *c) static bool is_stopped(struct lxc_container *c)
{ {
lxc_state_t s; lxc_state_t s;
...@@ -404,21 +347,19 @@ static bool is_stopped(struct lxc_container *c) ...@@ -404,21 +347,19 @@ static bool is_stopped(struct lxc_container *c)
return (s == STOPPED); 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; const char *s;
if (!c) if (!c)
return false; return false;
s = do_lxcapi_state(c); s = lxcapi_state(c);
if (!s || strcmp(s, "STOPPED") == 0) if (!s || strcmp(s, "STOPPED") == 0)
return false; return false;
return true; return true;
} }
WRAP_API(bool, lxcapi_is_running) static bool lxcapi_freeze(struct lxc_container *c)
static bool do_lxcapi_freeze(struct lxc_container *c)
{ {
int ret; int ret;
if (!c) if (!c)
...@@ -430,9 +371,7 @@ static bool do_lxcapi_freeze(struct lxc_container *c) ...@@ -430,9 +371,7 @@ static bool do_lxcapi_freeze(struct lxc_container *c)
return true; return true;
} }
WRAP_API(bool, lxcapi_freeze) static bool lxcapi_unfreeze(struct lxc_container *c)
static bool do_lxcapi_unfreeze(struct lxc_container *c)
{ {
int ret; int ret;
if (!c) if (!c)
...@@ -444,9 +383,7 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c) ...@@ -444,9 +383,7 @@ static bool do_lxcapi_unfreeze(struct lxc_container *c)
return true; return true;
} }
WRAP_API(bool, lxcapi_unfreeze) static int lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd)
static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd)
{ {
int ttyfd; int ttyfd;
if (!c) if (!c)
...@@ -456,24 +393,13 @@ static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *ma ...@@ -456,24 +393,13 @@ static int do_lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *ma
return ttyfd; return ttyfd;
} }
WRAP_API_2(int, lxcapi_console_getfd, int *, int *)
static int lxcapi_console(struct lxc_container *c, int ttynum, int stdinfd, static int lxcapi_console(struct lxc_container *c, int ttynum, int stdinfd,
int stdoutfd, int stderrfd, int escape) int stdoutfd, int stderrfd, int escape)
{ {
int ret; return lxc_console(c, ttynum, stdinfd, stdoutfd, stderrfd, escape);
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;
} }
static pid_t do_lxcapi_init_pid(struct lxc_container *c) static pid_t lxcapi_init_pid(struct lxc_container *c)
{ {
if (!c) if (!c)
return -1; return -1;
...@@ -481,8 +407,6 @@ static pid_t do_lxcapi_init_pid(struct lxc_container *c) ...@@ -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); 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) static bool load_config_locked(struct lxc_container *c, const char *fname)
{ {
if (!c->lxc_conf) if (!c->lxc_conf)
...@@ -494,7 +418,7 @@ static bool load_config_locked(struct lxc_container *c, const char *fname) ...@@ -494,7 +418,7 @@ static bool load_config_locked(struct lxc_container *c, const char *fname)
return true; 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; bool ret = false, need_disklock = false;
int lret; int lret;
...@@ -531,9 +455,7 @@ static bool do_lxcapi_load_config(struct lxc_container *c, const char *alt_file) ...@@ -531,9 +455,7 @@ static bool do_lxcapi_load_config(struct lxc_container *c, const char *alt_file)
return ret; return ret;
} }
WRAP_API_1(bool, lxcapi_load_config, const char *) static bool lxcapi_want_daemonize(struct lxc_container *c, bool state)
static bool do_lxcapi_want_daemonize(struct lxc_container *c, bool state)
{ {
if (!c || !c->lxc_conf) if (!c || !c->lxc_conf)
return false; return false;
...@@ -546,9 +468,7 @@ static bool do_lxcapi_want_daemonize(struct lxc_container *c, bool state) ...@@ -546,9 +468,7 @@ static bool do_lxcapi_want_daemonize(struct lxc_container *c, bool state)
return true; return true;
} }
WRAP_API_1(bool, lxcapi_want_daemonize, bool) static bool lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
static bool do_lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
{ {
if (!c || !c->lxc_conf) if (!c || !c->lxc_conf)
return false; return false;
...@@ -561,9 +481,7 @@ static bool do_lxcapi_want_close_all_fds(struct lxc_container *c, bool state) ...@@ -561,9 +481,7 @@ static bool do_lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
return true; return true;
} }
WRAP_API_1(bool, lxcapi_want_close_all_fds, bool) static bool lxcapi_wait(struct lxc_container *c, const char *state, int timeout)
static bool do_lxcapi_wait(struct lxc_container *c, const char *state, int timeout)
{ {
int ret; int ret;
...@@ -574,9 +492,8 @@ static bool do_lxcapi_wait(struct lxc_container *c, const char *state, int timeo ...@@ -574,9 +492,8 @@ static bool do_lxcapi_wait(struct lxc_container *c, const char *state, int timeo
return ret == 0; 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? */ /* we'll probably want to make this timeout configurable? */
int timeout = 5, ret, status; int timeout = 5, ret, status;
...@@ -588,11 +505,9 @@ static bool do_wait_on_daemonized_start(struct lxc_container *c, int pid) ...@@ -588,11 +505,9 @@ static bool do_wait_on_daemonized_start(struct lxc_container *c, int pid)
ret = waitpid(pid, &status, 0); ret = waitpid(pid, &status, 0);
if (ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) if (ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
DEBUG("failed waiting for first dual-fork child"); 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) static bool am_single_threaded(void)
{ {
struct dirent dirent, *direntp; struct dirent dirent, *direntp;
...@@ -625,7 +540,7 @@ static bool am_single_threaded(void) ...@@ -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 '...', * 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) * 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; int ret;
struct lxc_conf *conf; struct lxc_conf *conf;
...@@ -650,7 +565,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -650,7 +565,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
} }
if (ret == 2) { if (ret == 2) {
ERROR("Error: %s creation was not completed", c->name); ERROR("Error: %s creation was not completed", c->name);
do_lxcapi_destroy(c); c->destroy(c);
return false; return false;
} else if (ret == 1) { } else if (ret == 1) {
ERROR("Error: creation of %s is ongoing", c->name); ERROR("Error: creation of %s is ongoing", c->name);
...@@ -793,16 +708,6 @@ out: ...@@ -793,16 +708,6 @@ out:
return (ret == 0 ? true : false); 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 * note there MUST be an ending NULL
*/ */
...@@ -816,9 +721,6 @@ static bool lxcapi_startl(struct lxc_container *c, int useinit, ...) ...@@ -816,9 +721,6 @@ static bool lxcapi_startl(struct lxc_container *c, int useinit, ...)
if (!c) if (!c)
return false; return false;
struct lxc_conf *old = current_config;
current_config = c->lxc_conf;
va_start(ap, useinit); va_start(ap, useinit);
inargs = lxc_va_arg_list_to_argv(ap, 0, 1); inargs = lxc_va_arg_list_to_argv(ap, 0, 1);
va_end(ap); va_end(ap);
...@@ -829,7 +731,7 @@ static bool lxcapi_startl(struct lxc_container *c, int useinit, ...) ...@@ -829,7 +731,7 @@ static bool lxcapi_startl(struct lxc_container *c, int useinit, ...)
} }
/* pass NULL if no arguments were supplied */ /* 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: out:
if (inargs) { if (inargs) {
...@@ -839,11 +741,10 @@ out: ...@@ -839,11 +741,10 @@ out:
free(inargs); free(inargs);
} }
current_config = old;
return bret; return bret;
} }
static bool do_lxcapi_stop(struct lxc_container *c) static bool lxcapi_stop(struct lxc_container *c)
{ {
int ret; int ret;
...@@ -855,8 +756,6 @@ static bool do_lxcapi_stop(struct lxc_container *c) ...@@ -855,8 +756,6 @@ static bool do_lxcapi_stop(struct lxc_container *c)
return ret == 0; return ret == 0;
} }
WRAP_API(bool, lxcapi_stop)
static int do_create_container_dir(const char *path, struct lxc_conf *conf) static int do_create_container_dir(const char *path, struct lxc_conf *conf)
{ {
int ret = -1, lasterr; int ret = -1, lasterr;
...@@ -904,6 +803,9 @@ static bool create_container_dir(struct lxc_container *c) ...@@ -904,6 +803,9 @@ static bool create_container_dir(struct lxc_container *c)
return ret == 0; 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(), * do_bdev_create: thin wrapper around bdev_create(). Like bdev_create(),
* it returns a mounted bdev on success, NULL on error. * 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, ...@@ -923,7 +825,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
dest = alloca(len); dest = alloca(len);
ret = snprintf(dest, len, "%s", rpath); ret = snprintf(dest, len, "%s", rpath);
} else { } 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; len = strlen(c->name) + strlen(lxcpath) + 9;
dest = alloca(len); dest = alloca(len);
ret = snprintf(dest, len, "%s/%s/rootfs", lxcpath, c->name); 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, ...@@ -937,7 +839,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
return NULL; 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 /* if we are not root, chown the rootfs dir to root in the
* target uidmap */ * target uidmap */
...@@ -1314,8 +1216,9 @@ static void lxcapi_clear_config(struct lxc_container *c) ...@@ -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: * lxcapi_create:
* create a container with the given parameters. * create a container with the given parameters.
...@@ -1330,7 +1233,7 @@ static void lxcapi_clear_config(struct lxc_container *c) ...@@ -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 * @argv: the arguments to pass to the template, terminated by NULL. If no
* arguments, you can just pass NULL. * 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, const char *bdevtype, struct bdev_specs *specs, int flags,
char *const argv[]) char *const argv[])
{ {
...@@ -1356,14 +1259,14 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, ...@@ -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 * an existing container. Return an error, but do NOT delete the
* container. * 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) { access(c->lxc_conf->rootfs.path, F_OK) == 0 && tpath) {
ERROR("Container %s:%s already exists", c->config_path, c->name); ERROR("Container %s:%s already exists", c->config_path, c->name);
goto free_tpath; goto free_tpath;
} }
if (!c->lxc_conf) { 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")); ERROR("Error loading default configuration file %s", lxc_global_config_value("lxc.default_config"));
goto free_tpath; goto free_tpath;
} }
...@@ -1383,7 +1286,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, ...@@ -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) if (c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) != 0)
/* rootfs passed into configuration, but does not exist: error */ /* rootfs passed into configuration, but does not exist: error */
goto out; 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 /* Rootfs already existed, user just wanted to save the
* loaded configuration */ * loaded configuration */
ret = true; ret = true;
...@@ -1419,7 +1322,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, ...@@ -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 */ /* 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); ERROR("failed to save starting configuration for %s", c->name);
// parent task won't see bdev in config so we delete it // parent task won't see bdev in config so we delete it
bdev->ops->umount(bdev); bdev->ops->umount(bdev);
...@@ -1442,7 +1345,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t, ...@@ -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 // now clear out the lxc_conf we have, reload from the created
// container // container
do_lxcapi_clear_config(c); lxcapi_clear_config(c);
if (t) { if (t) {
if (!prepend_lxc_header(c->configfile, tpath, argv)) { if (!prepend_lxc_header(c->configfile, tpath, argv)) {
...@@ -1463,27 +1366,15 @@ free_tpath: ...@@ -1463,27 +1366,15 @@ free_tpath:
return ret; return ret;
} }
static bool lxcapi_create(struct lxc_container *c, const char *t, static bool lxcapi_reboot(struct lxc_container *c)
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)
{ {
pid_t pid; pid_t pid;
if (!c) if (!c)
return false; return false;
if (!do_lxcapi_is_running(c)) if (!c->is_running(c))
return false; return false;
pid = do_lxcapi_init_pid(c); pid = c->init_pid(c);
if (pid <= 0) if (pid <= 0)
return false; return false;
if (kill(pid, SIGINT) < 0) if (kill(pid, SIGINT) < 0)
...@@ -1492,9 +1383,7 @@ static bool do_lxcapi_reboot(struct lxc_container *c) ...@@ -1492,9 +1383,7 @@ static bool do_lxcapi_reboot(struct lxc_container *c)
} }
WRAP_API(bool, lxcapi_reboot) static bool lxcapi_shutdown(struct lxc_container *c, int timeout)
static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
{ {
bool retv; bool retv;
pid_t pid; pid_t pid;
...@@ -1503,20 +1392,18 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout) ...@@ -1503,20 +1392,18 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
if (!c) if (!c)
return false; return false;
if (!do_lxcapi_is_running(c)) if (!c->is_running(c))
return true; return true;
pid = do_lxcapi_init_pid(c); pid = c->init_pid(c);
if (pid <= 0) if (pid <= 0)
return true; return true;
if (c->lxc_conf && c->lxc_conf->haltsignal) if (c->lxc_conf && c->lxc_conf->haltsignal)
haltsignal = c->lxc_conf->haltsignal; haltsignal = c->lxc_conf->haltsignal;
kill(pid, haltsignal); kill(pid, haltsignal);
retv = do_lxcapi_wait(c, "STOPPED", timeout); retv = c->wait(c, "STOPPED", timeout);
return retv; return retv;
} }
WRAP_API_1(bool, lxcapi_shutdown, int)
static bool lxcapi_createl(struct lxc_container *c, const char *t, static bool lxcapi_createl(struct lxc_container *c, const char *t,
const char *bdevtype, struct bdev_specs *specs, int flags, ...) const char *bdevtype, struct bdev_specs *specs, int flags, ...)
{ {
...@@ -1527,9 +1414,6 @@ static bool lxcapi_createl(struct lxc_container *c, const char *t, ...@@ -1527,9 +1414,6 @@ static bool lxcapi_createl(struct lxc_container *c, const char *t,
if (!c) if (!c)
return false; 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 * since we're going to wait for create to finish, I don't think we
* need to get a copy of the arguments. * need to get a copy of the arguments.
...@@ -1542,11 +1426,10 @@ static bool lxcapi_createl(struct lxc_container *c, const char *t, ...@@ -1542,11 +1426,10 @@ static bool lxcapi_createl(struct lxc_container *c, const char *t,
goto out; goto out;
} }
bret = do_lxcapi_create(c, t, bdevtype, specs, flags, args); bret = c->create(c, t, bdevtype, specs, flags, args);
out: out:
free(args); free(args);
current_config = old;
return bret; return bret;
} }
...@@ -1564,7 +1447,7 @@ static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key) ...@@ -1564,7 +1447,7 @@ static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key)
WARN("Error clearing configuration for %s", 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; int ret;
...@@ -1579,11 +1462,9 @@ static bool do_lxcapi_clear_config_item(struct lxc_container *c, const char *key ...@@ -1579,11 +1462,9 @@ static bool do_lxcapi_clear_config_item(struct lxc_container *c, const char *key
return ret == 0; return ret == 0;
} }
WRAP_API_1(bool, lxcapi_clear_config_item, const char *)
static inline bool enter_net_ns(struct lxc_container *c) 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 ((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")) if (!switch_to_ns(pid, "user"))
...@@ -1663,7 +1544,7 @@ static bool remove_from_array(char ***names, char *cname, int size) ...@@ -1663,7 +1544,7 @@ static bool remove_from_array(char ***names, char *cname, int size)
return false; return false;
} }
static char ** do_lxcapi_get_interfaces(struct lxc_container *c) static char** lxcapi_get_interfaces(struct lxc_container *c)
{ {
pid_t pid; pid_t pid;
int i, count = 0, pipefd[2]; int i, count = 0, pipefd[2];
...@@ -1750,9 +1631,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c) ...@@ -1750,9 +1631,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
return interfaces; return interfaces;
} }
WRAP_API(char **, lxcapi_get_interfaces) static char** lxcapi_get_ips(struct lxc_container *c, const char* interface, const char* family, int scope)
static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface, const char* family, int scope)
{ {
pid_t pid; pid_t pid;
int i, count = 0, pipefd[2]; int i, count = 0, pipefd[2];
...@@ -1869,9 +1748,7 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface, ...@@ -1869,9 +1748,7 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
return addresses; return addresses;
} }
WRAP_API_3(char **, lxcapi_get_ips, const char *, const char *, int) static int lxcapi_get_config_item(struct lxc_container *c, const char *key, char *retv, int inlen)
static int do_lxcapi_get_config_item(struct lxc_container *c, const char *key, char *retv, int inlen)
{ {
int ret; int ret;
...@@ -1884,9 +1761,7 @@ static int do_lxcapi_get_config_item(struct lxc_container *c, const char *key, c ...@@ -1884,9 +1761,7 @@ static int do_lxcapi_get_config_item(struct lxc_container *c, const char *key, c
return ret; return ret;
} }
WRAP_API_3(int, lxcapi_get_config_item, const char *, char *, int) static char* lxcapi_get_running_config_item(struct lxc_container *c, const char *key)
static char* do_lxcapi_get_running_config_item(struct lxc_container *c, const char *key)
{ {
char *ret; char *ret;
...@@ -1894,14 +1769,12 @@ static char* do_lxcapi_get_running_config_item(struct lxc_container *c, const ch ...@@ -1894,14 +1769,12 @@ static char* do_lxcapi_get_running_config_item(struct lxc_container *c, const ch
return NULL; return NULL;
if (container_mem_lock(c)) if (container_mem_lock(c))
return NULL; 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); container_mem_unlock(c);
return ret; return ret;
} }
WRAP_API_1(char *, lxcapi_get_running_config_item, const char *) static int lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
{ {
if (!key) if (!key)
return lxc_listconfigs(retv, inlen); return lxc_listconfigs(retv, inlen);
...@@ -1921,9 +1794,7 @@ static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *re ...@@ -1921,9 +1794,7 @@ static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *re
return ret; return ret;
} }
WRAP_API_3(int, lxcapi_get_keys, const char *, char *, int) static bool lxcapi_save_config(struct lxc_container *c, const char *alt_file)
static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file)
{ {
FILE *fout; FILE *fout;
bool ret = false, need_disklock = false; bool ret = false, need_disklock = false;
...@@ -1936,7 +1807,7 @@ static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file) ...@@ -1936,7 +1807,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 we haven't yet loaded a config, load the stock config
if (!c->lxc_conf) { 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); ERROR("Error loading default configuration file %s while saving %s", lxc_global_config_value("lxc.default_config"), c->name);
return false; return false;
} }
...@@ -1976,8 +1847,6 @@ out: ...@@ -1976,8 +1847,6 @@ out:
return ret; return ret;
} }
WRAP_API_1(bool, lxcapi_save_config, const char *)
static bool mod_rdep(struct lxc_container *c, bool inc) static bool mod_rdep(struct lxc_container *c, bool inc)
{ {
char path[MAXPATHLEN]; char path[MAXPATHLEN];
...@@ -2166,7 +2035,7 @@ static bool container_destroy(struct lxc_container *c) ...@@ -2166,7 +2035,7 @@ static bool container_destroy(struct lxc_container *c)
bool bret = false; bool bret = false;
int ret; int ret;
if (!c || !do_lxcapi_is_defined(c)) if (!c || !lxcapi_is_defined(c))
return false; return false;
if (container_disk_lock(c)) if (container_disk_lock(c))
...@@ -2191,7 +2060,7 @@ static bool container_destroy(struct lxc_container *c) ...@@ -2191,7 +2060,7 @@ static bool container_destroy(struct lxc_container *c)
mod_all_rdeps(c, false); 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); char *path = alloca(strlen(p1) + strlen(c->name) + 2);
sprintf(path, "%s/%s", p1, c->name); sprintf(path, "%s/%s", p1, c->name);
if (am_unpriv()) if (am_unpriv())
...@@ -2209,7 +2078,7 @@ out: ...@@ -2209,7 +2078,7 @@ out:
return bret; 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)) if (!c || !lxcapi_is_defined(c))
return false; return false;
...@@ -2226,9 +2095,9 @@ static bool do_lxcapi_destroy(struct lxc_container *c) ...@@ -2226,9 +2095,9 @@ static bool do_lxcapi_destroy(struct lxc_container *c)
return container_destroy(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)) if (!c || !lxcapi_is_defined(c))
return false; return false;
...@@ -2239,8 +2108,6 @@ static bool do_lxcapi_destroy_with_snapshots(struct lxc_container *c) ...@@ -2239,8 +2108,6 @@ static bool do_lxcapi_destroy_with_snapshots(struct lxc_container *c)
return lxcapi_destroy(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) static bool set_config_item_locked(struct lxc_container *c, const char *key, const char *v)
{ {
struct lxc_config_t *config; struct lxc_config_t *config;
...@@ -2257,7 +2124,7 @@ static bool set_config_item_locked(struct lxc_container *c, const char *key, con ...@@ -2257,7 +2124,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); 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; bool b = false;
...@@ -2273,8 +2140,6 @@ static bool do_lxcapi_set_config_item(struct lxc_container *c, const char *key, ...@@ -2273,8 +2140,6 @@ static bool do_lxcapi_set_config_item(struct lxc_container *c, const char *key,
return b; return b;
} }
WRAP_API_2(bool, lxcapi_set_config_item, const char *, const char *)
static char *lxcapi_config_file_name(struct lxc_container *c) static char *lxcapi_config_file_name(struct lxc_container *c)
{ {
if (!c || !c->configfile) if (!c || !c->configfile)
...@@ -2322,7 +2187,7 @@ static bool set_config_filename(struct lxc_container *c) ...@@ -2322,7 +2187,7 @@ static bool set_config_filename(struct lxc_container *c)
return true; 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; char *p;
bool b = false; bool b = false;
...@@ -2360,9 +2225,8 @@ err: ...@@ -2360,9 +2225,8 @@ err:
return b; 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; int ret;
...@@ -2381,9 +2245,7 @@ static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsy ...@@ -2381,9 +2245,7 @@ static bool do_lxcapi_set_cgroup_item(struct lxc_container *c, const char *subsy
return ret == 0; return ret == 0;
} }
WRAP_API_2(bool, lxcapi_set_cgroup_item, const char *, const char *) static int lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, char *retv, int inlen)
static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, char *retv, int inlen)
{ {
int ret; int ret;
...@@ -2402,8 +2264,6 @@ static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys ...@@ -2402,8 +2264,6 @@ static int do_lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys
return ret; return ret;
} }
WRAP_API_3(int, lxcapi_get_cgroup_item, const char *, char *, int)
const char *lxc_get_global_config_item(const char *key) const char *lxc_get_global_config_item(const char *key)
{ {
return lxc_global_config_value(key); return lxc_global_config_value(key);
...@@ -2520,7 +2380,7 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c) ...@@ -2520,7 +2380,7 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
ERROR("Error saving new hooks in clone"); ERROR("Error saving new hooks in clone");
return -1; return -1;
} }
do_lxcapi_save_config(c, NULL); c->save_config(c, NULL);
return 0; return 0;
} }
...@@ -2792,7 +2652,7 @@ static int create_file_dirname(char *path, struct lxc_conf *conf) ...@@ -2792,7 +2652,7 @@ static int create_file_dirname(char *path, struct lxc_conf *conf)
return ret; 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 *lxcpath, int flags,
const char *bdevtype, const char *bdevdata, uint64_t newsize, const char *bdevtype, const char *bdevdata, uint64_t newsize,
char **hookargs) char **hookargs)
...@@ -2805,7 +2665,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char ...@@ -2805,7 +2665,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
FILE *fout; FILE *fout;
pid_t pid; pid_t pid;
if (!c || !do_lxcapi_is_defined(c)) if (!c || !c->is_defined(c))
return NULL; return NULL;
if (container_mem_lock(c)) if (container_mem_lock(c))
...@@ -2820,7 +2680,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char ...@@ -2820,7 +2680,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
if (!newname) if (!newname)
newname = c->name; newname = c->name;
if (!lxcpath) if (!lxcpath)
lxcpath = do_lxcapi_get_config_path(c); lxcpath = c->get_config_path(c);
ret = snprintf(newpath, MAXPATHLEN, "%s/%s/config", lxcpath, newname); ret = snprintf(newpath, MAXPATHLEN, "%s/%s/config", lxcpath, newname);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= MAXPATHLEN) {
SYSERROR("clone: failed making config pathname"); SYSERROR("clone: failed making config pathname");
...@@ -2949,20 +2809,7 @@ out: ...@@ -2949,20 +2809,7 @@ out:
return NULL; return NULL;
} }
static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname, static bool lxcapi_rename(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)
{ {
struct bdev *bdev; struct bdev *bdev;
struct lxc_container *newc; struct lxc_container *newc;
...@@ -2997,24 +2844,15 @@ static bool do_lxcapi_rename(struct lxc_container *c, const char *newname) ...@@ -2997,24 +2844,15 @@ static bool do_lxcapi_rename(struct lxc_container *c, const char *newname)
return true; 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) 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) if (!c)
return -1; return -1;
current_config = c->lxc_conf; return lxc_attach(c->name, c->config_path, exec_function, exec_payload, options, attached_process);
ret = lxc_attach(c->name, c->config_path, exec_function, exec_payload, options, attached_process);
current_config = old;
return ret;
} }
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; lxc_attach_command_t command;
pid_t pid; pid_t pid;
...@@ -3033,16 +2871,6 @@ static int do_lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options ...@@ -3033,16 +2871,6 @@ static int do_lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options
return lxc_wait_for_pid_status(pid); 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) static int get_next_index(const char *lxcpath, char *cname)
{ {
char *fname; char *fname;
...@@ -3086,7 +2914,7 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath) ...@@ -3086,7 +2914,7 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
return true; 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; int i, flags, ret;
struct lxc_container *c2; struct lxc_container *c2;
...@@ -3128,7 +2956,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile) ...@@ -3128,7 +2956,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
ERROR("and keep the original container pristine."); ERROR("and keep the original container pristine.");
flags &= ~LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT; 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) { if (!c2) {
ERROR("clone of %s:%s failed", c->config_path, c->name); ERROR("clone of %s:%s failed", c->config_path, c->name);
return -1; return -1;
...@@ -3176,8 +3004,6 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile) ...@@ -3176,8 +3004,6 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
return i; return i;
} }
WRAP_API_1(int, lxcapi_snapshot, const char *)
static void lxcsnap_free(struct lxc_snapshot *s) static void lxcsnap_free(struct lxc_snapshot *s)
{ {
free(s->name); free(s->name);
...@@ -3232,7 +3058,7 @@ static char *get_timestamp(char* snappath, char *name) ...@@ -3232,7 +3058,7 @@ static char *get_timestamp(char* snappath, char *name)
return s; 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]; char snappath[MAXPATHLEN], path2[MAXPATHLEN];
int count = 0, ret; int count = 0, ret;
...@@ -3308,9 +3134,7 @@ out_free: ...@@ -3308,9 +3134,7 @@ out_free:
return -1; return -1;
} }
WRAP_API_1(int, lxcapi_snapshot_list, struct lxc_snapshot **) static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname)
static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname)
{ {
char clonelxcpath[MAXPATHLEN]; char clonelxcpath[MAXPATHLEN];
int flags = 0; int flags = 0;
...@@ -3371,8 +3195,6 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap ...@@ -3371,8 +3195,6 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
return b; return b;
} }
WRAP_API_2(bool, lxcapi_snapshot_restore, const char *, const char *)
static bool do_snapshot_destroy(const char *snapname, const char *clonelxcpath) static bool do_snapshot_destroy(const char *snapname, const char *clonelxcpath)
{ {
struct lxc_container *snap = NULL; struct lxc_container *snap = NULL;
...@@ -3384,7 +3206,7 @@ static bool do_snapshot_destroy(const char *snapname, const char *clonelxcpath) ...@@ -3384,7 +3206,7 @@ static bool do_snapshot_destroy(const char *snapname, const char *clonelxcpath)
goto err; goto err;
} }
if (!do_lxcapi_destroy(snap)) { if (!lxcapi_destroy(snap)) {
ERROR("Could not destroy snapshot %s", snapname); ERROR("Could not destroy snapshot %s", snapname);
goto err; goto err;
} }
...@@ -3428,7 +3250,7 @@ static bool remove_all_snapshots(const char *path) ...@@ -3428,7 +3250,7 @@ static bool remove_all_snapshots(const char *path)
return bret; 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]; char clonelxcpath[MAXPATHLEN];
...@@ -3441,9 +3263,7 @@ static bool do_lxcapi_snapshot_destroy(struct lxc_container *c, const char *snap ...@@ -3441,9 +3263,7 @@ static bool do_lxcapi_snapshot_destroy(struct lxc_container *c, const char *snap
return do_snapshot_destroy(snapname, clonelxcpath); return do_snapshot_destroy(snapname, clonelxcpath);
} }
WRAP_API_1(bool, lxcapi_snapshot_destroy, const char *) static bool lxcapi_snapshot_destroy_all(struct lxc_container *c)
static bool do_lxcapi_snapshot_destroy_all(struct lxc_container *c)
{ {
char clonelxcpath[MAXPATHLEN]; char clonelxcpath[MAXPATHLEN];
...@@ -3456,15 +3276,11 @@ static bool do_lxcapi_snapshot_destroy_all(struct lxc_container *c) ...@@ -3456,15 +3276,11 @@ static bool do_lxcapi_snapshot_destroy_all(struct lxc_container *c)
return remove_all_snapshots(clonelxcpath); return remove_all_snapshots(clonelxcpath);
} }
WRAP_API(bool, lxcapi_snapshot_destroy_all) static bool lxcapi_may_control(struct lxc_container *c)
static bool do_lxcapi_may_control(struct lxc_container *c)
{ {
return lxc_try_cmd(c->name, c->config_path) == 0; 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, static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
struct stat *st) struct stat *st)
{ {
...@@ -3528,7 +3344,7 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path ...@@ -3528,7 +3344,7 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path
const char *p; const char *p;
/* make sure container is running */ /* make sure container is running */
if (!do_lxcapi_is_running(c)) { if (!c->is_running(c)) {
ERROR("container is not running"); ERROR("container is not running");
return false; return false;
} }
...@@ -3552,17 +3368,17 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path ...@@ -3552,17 +3368,17 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path
if (ret < 0 || ret >= MAX_BUFFER) if (ret < 0 || ret >= MAX_BUFFER)
return false; 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; return false;
/* add or remove device to/from cgroup access list */ /* add or remove device to/from cgroup access list */
if (add) { 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"); ERROR("set_cgroup_item failed while adding the device node");
return false; return false;
} }
} else { } 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"); ERROR("set_cgroup_item failed while removing the device node");
return false; return false;
} }
...@@ -3571,7 +3387,7 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path ...@@ -3571,7 +3387,7 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path
return true; 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()) { if (am_unpriv()) {
ERROR(NOT_SUPPORTED_ERROR, __FUNCTION__); ERROR(NOT_SUPPORTED_ERROR, __FUNCTION__);
...@@ -3580,9 +3396,7 @@ static bool do_lxcapi_add_device_node(struct lxc_container *c, const char *src_p ...@@ -3580,9 +3396,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); 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 lxcapi_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
static bool do_lxcapi_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
{ {
if (am_unpriv()) { if (am_unpriv()) {
ERROR(NOT_SUPPORTED_ERROR, __FUNCTION__); ERROR(NOT_SUPPORTED_ERROR, __FUNCTION__);
...@@ -3591,9 +3405,7 @@ static bool do_lxcapi_remove_device_node(struct lxc_container *c, const char *sr ...@@ -3591,9 +3405,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); 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 lxcapi_attach_interface(struct lxc_container *c, const char *ifname,
static bool do_lxcapi_attach_interface(struct lxc_container *c, const char *ifname,
const char *dst_ifname) const char *dst_ifname)
{ {
int ret = 0; int ret = 0;
...@@ -3616,7 +3428,7 @@ static bool do_lxcapi_attach_interface(struct lxc_container *c, const char *ifna ...@@ -3616,7 +3428,7 @@ static bool do_lxcapi_attach_interface(struct lxc_container *c, const char *ifna
goto err; 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) if (ret)
goto err; goto err;
...@@ -3626,9 +3438,7 @@ err: ...@@ -3626,9 +3438,7 @@ err:
return false; return false;
} }
WRAP_API_2(bool, lxcapi_attach_interface, const char *, const char *) static bool lxcapi_detach_interface(struct lxc_container *c, const char *ifname,
static bool do_lxcapi_detach_interface(struct lxc_container *c, const char *ifname,
const char *dst_ifname) const char *dst_ifname)
{ {
pid_t pid, pid_outside; pid_t pid, pid_outside;
...@@ -3683,8 +3493,6 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c, const char *ifna ...@@ -3683,8 +3493,6 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c, const char *ifna
return true; return true;
} }
WRAP_API_2(bool, lxcapi_detach_interface, const char *, const char *)
struct criu_opts { struct criu_opts {
/* The type of criu invocation, one of "dump" or "restore" */ /* The type of criu invocation, one of "dump" or "restore" */
char *action; char *action;
...@@ -4046,7 +3854,7 @@ out: ...@@ -4046,7 +3854,7 @@ out:
return true; 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; pid_t pid;
int status; int status;
...@@ -4091,8 +3899,6 @@ static bool do_lxcapi_checkpoint(struct lxc_container *c, char *directory, bool ...@@ -4091,8 +3899,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) static bool restore_net_info(struct lxc_container *c)
{ {
struct lxc_list *it; struct lxc_list *it;
...@@ -4271,7 +4077,7 @@ out: ...@@ -4271,7 +4077,7 @@ out:
exit(1); 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; pid_t pid;
int status, nread; int status, nread;
...@@ -4325,8 +4131,6 @@ err_wait: ...@@ -4325,8 +4131,6 @@ err_wait:
return false; 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, ...) static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...)
{ {
va_list ap; va_list ap;
...@@ -4336,24 +4140,18 @@ static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t ...@@ -4336,24 +4140,18 @@ static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t
if (!c) if (!c)
return -1; return -1;
struct lxc_conf *old = current_config;
current_config = c->lxc_conf;
va_start(ap, arg); va_start(ap, arg);
argv = lxc_va_arg_list_to_argv_const(ap, 1); argv = lxc_va_arg_list_to_argv_const(ap, 1);
va_end(ap); va_end(ap);
if (!argv) { if (!argv) {
ERROR("Memory allocation error."); ERROR("Memory allocation error.");
ret = -1; return -1;
goto out;
} }
argv[0] = arg; 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); free((void*)argv);
out:
current_config = old;
return ret; return ret;
} }
...@@ -4470,6 +4268,12 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath ...@@ -4470,6 +4268,12 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
c->checkpoint = lxcapi_checkpoint; c->checkpoint = lxcapi_checkpoint;
c->restore = lxcapi_restore; 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; return c;
err: err:
...@@ -4543,7 +4347,7 @@ int list_defined_containers(const char *lxcpath, char ***names, struct lxc_conta ...@@ -4543,7 +4347,7 @@ int list_defined_containers(const char *lxcpath, char ***names, struct lxc_conta
goto free_bad; goto free_bad;
continue; continue;
} }
if (!do_lxcapi_is_defined(c)) { if (!lxcapi_is_defined(c)) {
INFO("Container %s:%s has a config but is not defined", INFO("Container %s:%s has a config but is not defined",
lxcpath, direntp->d_name); lxcpath, direntp->d_name);
if (names) if (names)
......
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