lxc_log_define(lxc_commands, lxc);
-static int fill_sock_name(char *path, int len, const char *name) {
- char *lxcpath = default_lxc_path();
+static int fill_sock_name(char *path, int len, const char *name,
+ const char *inpath)
+{
+ char *lxcpath = NULL;
int ret;
- if (!lxcpath) {
- ERROR("Out of memory getting lxcpath");
- return -1;
+
+ if (!inpath) {
+ lxcpath = default_lxc_path();
+ if (!lxcpath) {
+ ERROR("Out of memory getting lxcpath");
+ return -1;
+ }
}
- ret = snprintf(path, len, "%s/%s/command", lxcpath, name);
+ ret = snprintf(path, len, "%s/%s/command", lxcpath ? lxcpath : inpath, name);
+ if (lxcpath)
+ free(lxcpath);
+
if (ret < 0 || ret >= len) {
ERROR("Name too long");
return -1;
}
static int __lxc_command(const char *name, struct lxc_command *command,
- int *stopped, int stay_connected)
+ int *stopped, int stay_connected, const char *lxcpath)
{
int sock, ret = -1;
char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 };
int len;
len = sizeof(path)-1;
- if (fill_sock_name(offset, len, name))
+ if (fill_sock_name(offset, len, name, lxcpath))
return -1;
sock = lxc_af_unix_connect(path);
}
extern int lxc_command(const char *name,
- struct lxc_command *command, int *stopped)
+ struct lxc_command *command, int *stopped,
+ const char *lxcpath)
{
- return __lxc_command(name, command, stopped, 0);
+ return __lxc_command(name, command, stopped, 0, lxcpath);
}
extern int lxc_command_connected(const char *name,
- struct lxc_command *command, int *stopped)
+ struct lxc_command *command, int *stopped,
+ const char *lxcpath)
{
- return __lxc_command(name, command, stopped, 1);
+ return __lxc_command(name, command, stopped, 1, lxcpath);
}
-pid_t get_init_pid(const char *name)
+pid_t get_init_pid(const char *name, const char *lxcpath)
{
struct lxc_command command = {
.request = { .type = LXC_COMMAND_PID },
int ret, stopped = 0;
- ret = lxc_command(name, &command, &stopped);
+ ret = lxc_command(name, &command, &stopped, lxcpath);
if (ret < 0 && stopped)
return -1;
return command.answer.pid;
}
-int lxc_get_clone_flags(const char *name)
+int lxc_get_clone_flags(const char *name, const char *lxcpath)
{
struct lxc_command command = {
.request = { .type = LXC_COMMAND_CLONE_FLAGS },
int ret, stopped = 0;
- ret = lxc_command(name, &command, &stopped);
+ ret = lxc_command(name, &command, &stopped, lxcpath);
if (ret < 0 && stopped)
return -1;
goto out;
}
-extern int lxc_command_init(const char *name, struct lxc_handler *handler)
+extern int lxc_command_init(const char *name, struct lxc_handler *handler,
+ const char *lxcpath)
{
int fd;
char path[sizeof(((struct sockaddr_un *)0)->sun_path)] = { 0 };
int len;
len = sizeof(path)-1;
- if (fill_sock_name(offset, len, name))
+ if (fill_sock_name(offset, len, name, lxcpath))
return -1;
fd = lxc_af_unix_open(path, SOCK_STREAM, 0);
struct lxc_answer answer;
};
-extern pid_t get_init_pid(const char *name);
-extern int lxc_get_clone_flags(const char *name);
+extern pid_t get_init_pid(const char *name, const char *lxcpath);
+extern int lxc_get_clone_flags(const char *name, const char *lxcpath);
extern int lxc_command(const char *name, struct lxc_command *command,
- int *stopped);
+ int *stopped, const char *lxcpath);
extern int lxc_command_connected(const char *name, struct lxc_command *command,
- int *stopped);
+ int *stopped, const char *lxcpath);
struct lxc_epoll_descr;
struct lxc_handler;
-extern int lxc_command_init(const char *name, struct lxc_handler *handler);
+extern int lxc_command_init(const char *name, struct lxc_handler *handler,
+ const char *lxcpath);
extern int lxc_command_mainloop_add(const char *name, struct lxc_epoll_descr *descr,
struct lxc_handler *handler);
lxc_log_define(lxc_console, lxc);
-extern int lxc_console(const char *name, int ttynum, int *fd)
+extern int lxc_console(const char *name, int ttynum, int *fd, const char *lxcpath)
{
int ret, stopped = 0;
struct lxc_command command = {
.request = { .type = LXC_COMMAND_TTY, .data = ttynum },
};
- ret = lxc_command_connected(name, &command, &stopped);
+ ret = lxc_command_connected(name, &command, &stopped, lxcpath);
if (ret < 0 && stopped) {
ERROR("'%s' is stopped", name);
return -1;
};
int lxc_execute(const char *name, char *const argv[], int quiet,
- struct lxc_conf *conf)
+ struct lxc_conf *conf, const char *lxcpath)
{
struct execute_args args = {
.argv = argv,
if (lxc_check_inherited(conf, -1))
return -1;
- return __lxc_start(name, conf, &execute_start_ops, &args);
+ return __lxc_start(name, conf, &execute_start_ops, &args, lxcpath);
}
* @conf : configuration
* Returns 0 on sucess, < 0 otherwise
*/
-extern int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf);
+extern int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf,
+ const char *lxcpath);
/*
* Stop the container previously started with lxc_start, all
* @name : the name of the container
* Returns 0 on success, < 0 otherwise
*/
-extern int lxc_stop(const char *name);
+extern int lxc_stop(const char *name, const char *lxcpath);
/*
* Start the specified command inside an application container
* Returns 0 on sucess, < 0 otherwise
*/
extern int lxc_execute(const char *name, char *const argv[], int quiet,
- struct lxc_conf *conf);
+ struct lxc_conf *conf, const char *lxcpath);
/*
* Open the monitoring mechanism for a specific container
* @fd : a pointer to a tty file descriptor
* Returns 0 on sucess, < 0 otherwise
*/
-extern int lxc_console(const char *name, int ttynum, int *fd);
+extern int lxc_console(const char *name, int ttynum, int *fd, const char *lxcpath);
/*
* Freeze all the tasks running inside the container <name>
* @name : the name of the container
* Returns the state of the container on success, < 0 otherwise
*/
-extern lxc_state_t lxc_state(const char *name);
+extern lxc_state_t lxc_state(const char *name, const char *lxcpath);
/*
* Set a specified value for a specified subsystem. The specified
void *cgroup_data = NULL;
uid_t uid;
char *curdir;
+ /* TODO: add cmdline arg to set lxcpath */
+ const char *lxcpath = NULL;
ret = lxc_caps_init();
if (ret)
if (ret)
return ret;
- init_pid = get_init_pid(my_args.name);
+ init_pid = get_init_pid(my_args.name, lxcpath);
if (init_pid < 0) {
ERROR("failed to get the init pid");
return -1;
* by asking lxc-start
*/
if (namespace_flags == -1) {
- namespace_flags = lxc_get_clone_flags(my_args.name);
+ namespace_flags = lxc_get_clone_flags(my_args.name, lxcpath);
/* call failed */
if (namespace_flags == -1) {
ERROR("failed to automatically determine the "
int err, std_in = 1;
struct lxc_epoll_descr descr;
struct termios newtios, oldtios;
+ /* TODO: add cmdline arg to specify lxcpath */
+ char *lxcpath = NULL;
err = lxc_arguments_parse(&my_args, argc, argv);
if (err)
return -1;
}
- err = lxc_console(my_args.name, my_args.ttynum, &master);
+ err = lxc_console(my_args.name, my_args.ttynum, &master, lxcpath);
if (err)
goto out;
if (lxc_config_define_load(&defines, conf))
return -1;
- return lxc_execute(my_args.name, my_args.argv, my_args.quiet, conf);
+ return lxc_execute(my_args.name, my_args.argv, my_args.quiet, conf, NULL);
}
int main(int argc, char *argv[])
{
int ret;
+ /* TODO: add lxcpath cmdline arg */
+ const char *lxcpath = NULL;
ret = lxc_arguments_parse(&my_args, argc, argv);
if (ret)
state = pid = true;
if (state || test_state) {
- ret = lxc_getstate(my_args.name);
+ ret = lxc_getstate(my_args.name, lxcpath);
if (ret < 0)
return 1;
if (test_state)
}
if (pid)
- printf("pid:%10d\n", get_init_pid(my_args.name));
+ printf("pid:%10d\n", get_init_pid(my_args.name, lxcpath));
return 0;
}
int ret;
pid_t pid;
int sig;
+ /* TODO: add lxcpath cmdline arg */
+ const char *lxcpath = NULL;
ret = lxc_arguments_parse(&my_args, argc, argv);
if (ret)
} else
sig=SIGKILL;
- pid = get_init_pid(my_args.name);
+ pid = get_init_pid(my_args.name, lxcpath);
if (pid < 0) {
ERROR("failed to get the init pid");
return -1;
'\0',
};
FILE *pid_fp = NULL;
+ /* TODO: add cmdline arg to specify lxcpath */
+ char *lxcpath = NULL;
lxc_list_init(&defines);
if (my_args.close_all_fds)
conf->close_all_fds = 1;
- err = lxc_start(my_args.name, args, conf);
+ err = lxc_start(my_args.name, args, conf, lxcpath);
/*
* exec ourself, that requires to have all opened fd
int main(int argc, char *argv[])
{
+ /* TODO - make lxcpath a cmdline arg */
+ const char *lxcpath = NULL;
+
if (lxc_arguments_parse(&my_args, argc, argv))
return -1;
my_args.progname, my_args.quiet))
return -1;
- return lxc_stop(my_args.name);
+ return lxc_stop(my_args.name, lxcpath);
}
return NULL;
if (lxclock(c->slock, 0))
return NULL;
- s = lxc_getstate(c->name);
+ s = lxc_getstate(c->name, c->config_path);
ret = lxc_state2str(s);
lxcunlock(c->slock);
static bool is_stopped_nolock(struct lxc_container *c)
{
lxc_state_t s;
- s = lxc_getstate(c->name);
+ s = lxc_getstate(c->name, c->config_path);
return (s == STOPPED);
}
if (lxclock(c->slock, 0))
return -1;
- ret = get_init_pid(c->name);
+ ret = get_init_pid(c->name, c->config_path);
lxcunlock(c->slock);
return ret;
}
lxcunlock(c->privlock);
if (useinit) {
- ret = lxc_execute(c->name, argv, 1, conf);
+ ret = lxc_execute(c->name, argv, 1, conf, c->config_path);
return ret == 0 ? true : false;
}
reboot:
conf->reboot = 0;
- ret = lxc_start(c->name, argv, conf);
+ ret = lxc_start(c->name, argv, conf, c->config_path);
if (conf->reboot) {
INFO("container requested reboot");
if (!c)
return false;
- ret = lxc_stop(c->name);
+ ret = lxc_stop(c->name, c->config_path);
return ret == 0;
}
.sfd = sfd,
.flags = flags
};
+ /* TODO - make lxcpath a cmdline arg */
+ const char *lxcpath = NULL;
if (lxc_check_inherited(conf, sfd))
return -1;
- return __lxc_start(name, conf, &restart_ops, &restart_arg);
+ return __lxc_start(name, conf, &restart_ops, &restart_arg, lxcpath);
}
extern int lxc_caps_check(void);
-struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf)
+struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char *lxcpath)
{
struct lxc_handler *handler;
goto out_free;
}
- if (lxc_command_init(name, handler))
+ if (lxc_command_init(name, handler, lxcpath))
goto out_free_name;
if (lxc_read_seccomp_config(conf) != 0) {
}
int __lxc_start(const char *name, struct lxc_conf *conf,
- struct lxc_operations* ops, void *data)
+ struct lxc_operations* ops, void *data, const char *lxcpath)
{
struct lxc_handler *handler;
int err = -1;
int status;
- handler = lxc_init(name, conf);
+ handler = lxc_init(name, conf, lxcpath);
if (!handler) {
ERROR("failed to initialize the container");
return -1;
.post_start = post_start
};
-int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf)
+int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf,
+ const char *lxcpath)
{
struct start_args start_arg = {
.argv = argv,
return -1;
conf->need_utmp_watch = 1;
- return __lxc_start(name, conf, &start_ops, &start_arg);
+ return __lxc_start(name, conf, &start_ops, &start_arg, lxcpath);
}
int pinfd;
};
-extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *);
+extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *, const char *);
extern int lxc_spawn(struct lxc_handler *);
extern int lxc_poll(const char *name, struct lxc_handler *handler);
extern int lxc_set_state(const char *, struct lxc_handler *, lxc_state_t);
extern int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore);
int __lxc_start(const char *, struct lxc_conf *, struct lxc_operations *,
- void *);
+ void *, const char *);
#endif
return lxc_str2state(status);
}
-static lxc_state_t __lxc_getstate(const char *name)
+static lxc_state_t __lxc_getstate(const char *name, const char *lxcpath)
{
struct lxc_command command = {
.request = { .type = LXC_COMMAND_STATE },
int ret, stopped = 0;
- ret = lxc_command(name, &command, &stopped);
+ ret = lxc_command(name, &command, &stopped, lxcpath);
if (ret < 0 && stopped)
return STOPPED;
return command.answer.ret;
}
-lxc_state_t lxc_getstate(const char *name)
+lxc_state_t lxc_getstate(const char *name, const char *lxcpath)
{
int state = freezer_state(name);
if (state != FROZEN && state != FREEZING)
- state = __lxc_getstate(name);
+ state = __lxc_getstate(name, lxcpath);
return state;
}
struct lxc_msg msg;
int state, ret;
int s[MAX_STATE] = { }, fd;
+ /* TODO: add cmdline arg to specify lxcpath */
+ char *lxcpath = NULL;
if (fillwaitedstates(states, s))
return -1;
* then check if already in requested state
*/
ret = -1;
- state = lxc_getstate(lxcname);
+ state = lxc_getstate(lxcname, lxcpath);
if (state < 0) {
goto out_close;
} else if ((state >= 0) && (s[state])) {
} lxc_state_t;
extern int lxc_rmstate(const char *name);
-extern lxc_state_t lxc_getstate(const char *name);
+extern lxc_state_t lxc_getstate(const char *name, const char *lxcpath);
extern lxc_state_t lxc_str2state(const char *state);
extern const char *lxc_state2str(lxc_state_t state);
lxc_log_define(lxc_stop, lxc);
-int lxc_stop(const char *name)
+int lxc_stop(const char *name, const char *lxcpath)
{
struct lxc_command command = {
.request = { .type = LXC_COMMAND_STOP },
int ret, stopped = 0;
- ret = lxc_command(name, &command,&stopped);
+ ret = lxc_command(name, &command,&stopped, lxcpath);
if (ret < 0 && stopped) {
INFO("'%s' is already stopped", name);
return 0;