int lxc_create(const char *name, const char *confile)
{
- int lock, err = -1;
+ int err = -1;
if (create_lxc_directory(name))
return err;
if (!confile)
return 0;
- lock = lxc_get_lock(name);
- if (lock < 0)
- goto err;
-
if (copy_config_file(name, confile)) {
ERROR("failed to copy the configuration file");
- goto err_state;
+ goto err;
}
err = 0;
out:
- lxc_put_lock(lock);
return err;
-err_state:
+err:
lxc_unconfigure(name);
if (lxc_rmstate(name))
ERROR("failed to remove state file for %s", name);
-err:
+
if (remove_lxc_directory(name))
ERROR("failed to cleanup lxc directory for %s", name);
goto out;
int lxc_destroy(const char *name)
{
- int lock, ret = -1;
+ int ret = -1;
char path[MAXPATHLEN];
- lock = lxc_get_lock(name);
- if (lock < 0)
- return ret;
-
if (remove_config_file(name))
WARN("failed to remove the configuration file");
if (lxc_rmstate(name)) {
ERROR("failed to remove state file for %s", name);
- goto out_lock;
+ return -1;
}
#warning keep access to LXCPATH/<name> to destroy old created container
if (lxc_unconfigure(name)) {
ERROR("failed to cleanup %s", name);
- goto out_lock;
+ return -1;
}
if (remove_lxc_directory(name)) {
SYSERROR("failed to remove '%s'", name);
- goto out_lock;
+ return -1;
}
- ret = 0;
-
-out_lock:
- lxc_put_lock(lock);
- return ret;
+ return 0;
}
+++ /dev/null
-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <dlezcano at fr.ibm.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#undef _GNU_SOURCE
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/file.h>
-#include <sys/param.h>
-
-#include "error.h"
-#include "config.h"
-
-#include <lxc/lxc.h>
-
-lxc_log_define(lxc_lock, lxc);
-
-static int __lxc_get_lock(const char *name)
-{
- char lock[MAXPATHLEN];
- int fd, ret;
-
- snprintf(lock, MAXPATHLEN, LXCPATH "/%s", name);
-
- /* need to check access because of cap_dac_override */
- if (access(lock, R_OK |W_OK | X_OK))
- return -errno;
-
- fd = open(lock, O_RDONLY|O_DIRECTORY, S_IRUSR|S_IWUSR);
- if (fd < 0)
- return -errno;
-
- fcntl(fd, F_SETFD, FD_CLOEXEC);
-
- if (flock(fd, LOCK_EX|LOCK_NB)) {
- ret = -errno;
- close(fd);
- goto out;
- }
-
- ret = fd;
-out:
- return ret;
-}
-
-int lxc_get_lock(const char *name)
-{
- int ret;
-
- ret = __lxc_get_lock(name);
- if (ret < 0)
- goto out_err;
-
- return ret;
-out_err:
- switch (-ret) {
- case EWOULDBLOCK:
- ERROR("container '%s' is busy", name);
- break;
- case ENOENT:
- ERROR("container '%s' is not found", name);
- break;
- case EACCES:
- ERROR("not enough privilege to use container '%s'", name);
- break;
- default:
- ERROR("container '%s' failed to lock : %s",
- name, strerror(-ret));
- }
- return -1;
-}
-
-int lxc_check_lock(const char *name)
-{
- int ret;
-
- ret = __lxc_get_lock(name);
- if (ret >= 0) {
- ERROR("container '%s' is not active", name);
- lxc_put_lock(ret);
- return -1;
- }
- if (ret != -EWOULDBLOCK) {
- ERROR("container '%s' : %s", name, strerror(-ret));
- return -1;
- }
- return 0;
-}
-
-void lxc_put_lock(int lock)
-{
- flock(lock, LOCK_UN);
- close(lock);
-}
+++ /dev/null
-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <dlezcano at fr.ibm.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef _lock_h
-#define _lock_h
-
-extern int lxc_get_lock(const char *name);
-extern int lxc_check_lock(const char *name);
-extern void lxc_put_lock(int lock);
-
-#endif
#include <lxc/list.h>
#include <lxc/log.h>
#include <lxc/conf.h>
-#include <lxc/lock.h>
#include <lxc/namespace.h>
#include <lxc/utils.h>
#include <lxc/error.h>
memset(handler, 0, sizeof(*handler));
- handler->lock = lxc_get_lock(name);
- if (handler->lock < 0)
- goto out_free;
-
/* Begin the set the state to STARTING*/
if (set_state(name, handler, STARTING)) {
ERROR("failed to set state '%s'", lxc_state2str(STARTING));
- goto out_put_lock;
+ goto out_free;
}
if (lxc_conf_init(&handler->conf)) {
lxc_delete_tty(&handler->conf.tty_info);
out_aborting:
set_state(name, handler, ABORTING);
-out_put_lock:
- lxc_put_lock(handler->lock);
out_free:
free(handler);
handler = NULL;
if (handler) {
remove_init_pid(name, handler->pid);
lxc_delete_tty(&handler->conf.tty_info);
- lxc_put_lock(handler->lock);
free(handler);
}
lxc_state_t state;
int sigfd;
- int lock;
char nsgroup[MAXPATHLEN];
sigset_t oldmask;
struct lxc_conf conf;