]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/commands.c
pass lxcpath to lxc_command
[mirror_lxc.git] / src / lxc / commands.c
index 2c4d6036d4c9e603185708f0db8d3eb78710dd0f..2776f032fc304a4f7227d5236f69d26ee0923b11 100644 (file)
 
 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;
@@ -86,7 +95,7 @@ static int receive_answer(int sock, struct lxc_answer *answer)
 }
 
 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 };
@@ -94,7 +103,7 @@ static int __lxc_command(const char *name, struct lxc_command *command,
        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);
@@ -129,19 +138,21 @@ out:
 }
 
 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 },
@@ -149,7 +160,7 @@ pid_t get_init_pid(const char *name)
 
        int ret, stopped = 0;
 
-       ret = lxc_command(name, &command, &stopped);
+       ret = lxc_command(name, &command, &stopped, lxcpath);
        if (ret < 0 && stopped)
                return -1;
 
@@ -167,7 +178,7 @@ pid_t get_init_pid(const char *name)
        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 },
@@ -175,7 +186,7 @@ int lxc_get_clone_flags(const char *name)
 
        int ret, stopped = 0;
 
-       ret = lxc_command(name, &command, &stopped);
+       ret = lxc_command(name, &command, &stopped, lxcpath);
        if (ret < 0 && stopped)
                return -1;
 
@@ -300,7 +311,8 @@ out_close:
        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 };
@@ -308,7 +320,7 @@ extern int lxc_command_init(const char *name, struct lxc_handler *handler)
        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);