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);