]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxclock: move container locks into /run/lock
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Wed, 5 Jun 2013 22:37:03 +0000 (17:37 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 11 Jun 2013 17:43:25 +0000 (12:43 -0500)
Currently the lxc API mutexes configuration file read/writes with a
lock called $lxcpath/locks/$lxcname.  This fails if the container
is on a rofs.

This patch moves those locks under /run/lock/lxc.

The $lxcpath/$lxcname/partial file is not moved - if you can't
create it, you probably can't create the container either.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxclock.c
src/tests/locktests.c

index d004cc55ffa303994e8bea8443497cb80feb6a07..31bedd8ab772a682f5dfa59a06e44e61d4f510e8 100644 (file)
@@ -40,12 +40,14 @@ pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;
 static char *lxclock_name(const char *p, const char *n)
 {
        int ret;
-       // $lxcpath/locks/$lxcname + '\0'
-       int len = strlen(p) + strlen(n) + strlen("/locks/") + 1;
+       // /run/lock/lxc/$lxcpath/$lxcname + '\0'
+       int len = strlen(p) + strlen(n) + strlen("/run/lock/lxc/") + 2;
        char *dest = malloc(len);
+       struct stat sb;
+
        if (!dest)
                return NULL;
-       ret = snprintf(dest, len, "%s/locks", p);
+       ret = snprintf(dest, len, "/run/lock/lxc/%s", p);
        if (ret < 0 || ret >= len) {
                free(dest);
                return NULL;
@@ -58,7 +60,16 @@ static char *lxclock_name(const char *p, const char *n)
                return NULL;
        }
 
-       ret = snprintf(dest, len, "%s/locks/%s", p, n);
+       ret = stat(p, &sb);
+       if (ret == 0) {
+               // best effort.  If this fails, ignore it
+               if (chown(dest, sb.st_uid, sb.st_gid) < 0)
+                       ERROR("Failed ot set owner for lockdir %s\n", dest);
+               if (chmod(dest, sb.st_mode) < 0)
+                       ERROR("Failed to set mode for lockdir %s\n", dest);
+       }
+
+       ret = snprintf(dest, len, "/run/lock/lxc/%s/%s", p, n);
        if (ret < 0 || ret >= len) {
                free(dest);
                return NULL;
index 96df9468b73d15b0a724e217e55942779731f5c9..360851fdf69c3c50c27063526da5ed4ef5437321 100644 (file)
@@ -121,7 +121,10 @@ int main(int argc, char *argv[])
                exit(1);
        }
        struct stat sb;
-       char *pathname = "/var/lib/lxc/locks/" mycontainername;
+       // we don't create the file until the container is running, so this
+       // bit of the test needs to be changed
+       //char *pathname = "/run/lock/lxc/var/lib/lxc/" mycontainername;
+       char *pathname = "/run/lock/lxc/var/lib/lxc/";
        ret = stat(pathname, &sb);
        if (ret != 0) {
                fprintf(stderr, "%d: filename %s not created\n", __LINE__,