]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands: mv lxc_make_abstract_socket_name()
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 3 Jul 2017 21:31:04 +0000 (23:31 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 8 Jul 2017 22:14:46 +0000 (00:14 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c
src/lxc/commands_utils.c
src/lxc/commands_utils.h
src/lxc/start.c
src/lxc/utils.c
src/lxc/utils.h

index 61ac6e708479ec7f463cb1dcd30f0b88c049780a..bda9d7e81f71e853c7ce4eb2fe937a3a048f65db 100644 (file)
@@ -40,6 +40,7 @@
 #include "utils.h"
 #include "cgroup.h"
 #include "commands.h"
+#include "commands_utils.h"
 #include "console.h"
 #include "confile.h"
 #include "lxclock.h"
index 1d5e9a51b82b461b51a697d452a3d4a95debbcf6..d82e20ffef5badcdcf2e73a38adb8fb4f9784e82 100644 (file)
  */
 
 #define _GNU_SOURCE
+#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
 #include <errno.h>
+#include <inttypes.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/socket.h>
@@ -30,6 +33,7 @@
 #include "log.h"
 #include "monitor.h"
 #include "state.h"
+#include "utils.h"
 
 lxc_log_define(lxc_commands_utils, lxc);
 
@@ -89,3 +93,63 @@ int lxc_cmd_sock_get_state(const char *name, const char *lxcpath,
        close(state_client_fd);
        return ret;
 }
+
+int lxc_make_abstract_socket_name(char *path, int len, const char *lxcname,
+                                 const char *lxcpath,
+                                 const char *hashed_sock_name,
+                                 const char *suffix)
+{
+       const char *name;
+       char *tmppath;
+       size_t tmplen;
+       uint64_t hash;
+       int ret;
+
+       name = lxcname;
+       if (!name)
+               name = "";
+
+       if (hashed_sock_name != NULL) {
+               ret =
+                   snprintf(path, len, "lxc/%s/%s", hashed_sock_name, suffix);
+               if (ret < 0 || ret >= len) {
+                       ERROR("Failed to create abstract socket name");
+                       return -1;
+               }
+               return 0;
+       }
+
+       if (!lxcpath) {
+               lxcpath = lxc_global_config_value("lxc.lxcpath");
+               if (!lxcpath) {
+                       ERROR("Failed to allocate memory");
+                       return -1;
+               }
+       }
+
+       ret = snprintf(path, len, "%s/%s/%s", lxcpath, name, suffix);
+       if (ret < 0) {
+               ERROR("Failed to create abstract socket name");
+               return -1;
+       }
+       if (ret < len)
+               return 0;
+
+       /* ret >= len; lxcpath or name is too long.  hash both */
+       tmplen = strlen(name) + strlen(lxcpath) + 2;
+       tmppath = alloca(tmplen);
+       ret = snprintf(tmppath, tmplen, "%s/%s", lxcpath, name);
+       if (ret < 0 || (size_t)ret >= tmplen) {
+               ERROR("Failed to create abstract socket name");
+               return -1;
+       }
+
+       hash = fnv_64a_buf(tmppath, ret, FNV1A_64_INIT);
+       ret = snprintf(path, len, "lxc/%016" PRIx64 "/%s", hash, suffix);
+       if (ret < 0 || ret >= len) {
+               ERROR("Failed to create abstract socket name");
+               return -1;
+       }
+
+       return 0;
+}
index c1acdb5f17ba86bf0500d61acb3da8c49edcab2e..40307b6abe84010c1b50bbeb326bef1ebe47db42 100644 (file)
 
 #include "state.h"
 
+int lxc_make_abstract_socket_name(char *path, int len, const char *lxcname,
+                                 const char *lxcpath,
+                                 const char *hashed_sock_name,
+                                 const char *suffix);
+
 /* lxc_cmd_sock_get_state      Register a new state client fd in the container's
  *                             in-memory handler and retrieve the requested
  *                             states.
index 8291fda125732af323cf82bbec2d85dbad3f898a..cd9dc18beed44a49b1aeab63ce3dc918011a368c 100644 (file)
@@ -67,6 +67,7 @@
 #include "caps.h"
 #include "cgroup.h"
 #include "commands.h"
+#include "commands_utils.h"
 #include "conf.h"
 #include "console.h"
 #include "error.h"
index c82cc694338c2073ef9f33c4e87deab6a07c8488..2b30c056e35096375c61e1e2439310dd900be2a2 100644 (file)
@@ -2338,62 +2338,3 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
 
        return fret;
 }
-
-int lxc_make_abstract_socket_name(char *path, int len, const char *lxcname,
-                                 const char *lxcpath,
-                                 const char *hashed_sock_name,
-                                 const char *suffix)
-{
-       const char *name;
-       char *tmppath;
-       size_t tmplen;
-       uint64_t hash;
-       int ret;
-
-       name = lxcname;
-       if (!name)
-               name = "";
-
-       if (hashed_sock_name != NULL) {
-               ret =
-                   snprintf(path, len, "lxc/%s/%s", hashed_sock_name, suffix);
-               if (ret < 0 || ret >= len) {
-                       ERROR("Failed to create abstract socket name");
-                       return -1;
-               }
-               return 0;
-       }
-
-       if (!lxcpath) {
-               lxcpath = lxc_global_config_value("lxc.lxcpath");
-               if (!lxcpath) {
-                       ERROR("Failed to allocate memory");
-                       return -1;
-               }
-       }
-
-       ret = snprintf(path, len, "%s/%s/%s", lxcpath, name, suffix);
-       if (ret < 0) {
-               ERROR("Failed to create abstract socket name");
-               return -1;
-       }
-       if (ret < len)
-               return 0;
-
-       /* ret >= len; lxcpath or name is too long.  hash both */
-       tmplen = strlen(name) + strlen(lxcpath) + 2;
-       tmppath = alloca(tmplen);
-       ret = snprintf(tmppath, tmplen, "%s/%s", lxcpath, name);
-       if (ret < 0 || ret >= tmplen) {
-               ERROR("Failed to create abstract socket name");
-               return -1;
-       }
-       hash = fnv_64a_buf(tmppath, ret, FNV1A_64_INIT);
-       ret = snprintf(path, len, "lxc/%016" PRIx64 "/%s", hash, suffix);
-       if (ret < 0 || ret >= len) {
-               ERROR("Failed to create abstract socket name");
-               return -1;
-       }
-
-       return 0;
-}
index 7d81a32702d3a1a32488830830a0cfdc522b56e8..916ee56a6869f4080e7d9d630fffc97f85d2087f 100644 (file)
@@ -374,9 +374,5 @@ int lxc_unstack_mountpoint(const char *path, bool lazy);
  * @param[in] args     Arguments to be passed to child_fn.
  */
 int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args);
-int lxc_make_abstract_socket_name(char *path, int len, const char *lxcname,
-                                 const char *lxcpath,
-                                 const char *hashed_sock_name,
-                                 const char *suffix);
 
 #endif /* __LXC_UTILS_H */