#include <netinet/in.h>
#include <net/if.h>
+#include "error.h"
#include <lxc/lxc.h>
#define MTAB "/etc/mtab"
int lxc_cgroup_set(const char *name, const char *subsystem, const char *value)
{
- int fd, ret = -1;;
+ int fd, ret = -LXC_ERROR_INTERNAL;;
char path[MAXPATHLEN];
snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
int lxc_cgroup_get(const char *name, const char *subsystem,
char *value, size_t len)
{
- int fd, ret = -1;;
+ int fd, ret = -LXC_ERROR_INTERNAL;
char path[MAXPATHLEN];
snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
#include <sys/stat.h>
#include <sys/types.h>
+#include "error.h"
#include <lxc/lxc.h>
static int dir_filter(const struct dirent *dirent)
int lxc_create(const char *name, struct lxc_conf *conf)
{
- int lock, err = -1;
+ int lock, err = -LXC_ERROR_INTERNAL;
if (create_lxc_directory(name)) {
lxc_log_error("failed to create %s directory", name);
- return -1;
+ return -LXC_ERROR_INTERNAL;
}
lock = lxc_get_lock(name);
if (!lock) {
lxc_log_error("'%s' is busy", name);
- goto err;
+ return -LXC_ERROR_ALREADY_EXISTS;
}
if (lock < 0) {
#include <errno.h>
#include <sys/param.h>
+#include "error.h"
#include <lxc/lxc.h>
static int remove_lxc_directory(const char *dirname)
int lxc_destroy(const char *name)
{
- int ret = -1, lock;
+ int lock, ret = -LXC_ERROR_INTERNAL;
char path[MAXPATHLEN];
lock = lxc_get_lock(name);
if (!lock) {
lxc_log_error("'%s' is busy", name);
- goto out;
+ return -LXC_ERROR_BUSY;
}
if (lock < 0) {
static char *catalogue[] = {
[LXC_ERROR_EMPTY] = "The container is not running",
+ [LXC_ERROR_ALREADY_EXISTS] = "The container already exists",
[LXC_ERROR_BUSY] = "The container is busy",
[LXC_ERROR_NOT_FOUND] = "The container was not found",
[LXC_ERROR_PERMISSION_DENIED] = "Permission denied",
[LXC_ERROR_SETUP_UTSNAME] = "Failed to setup the utsname",
[LXC_ERROR_SETUP_NETWORK] = "Failed to setup the network",
[LXC_ERROR_SETUP_ROOTFS] = "Failed to setup the root fs",
+
+ [LXC_ERROR_INTERNAL] = "Internal system error",
};
const char *const lxc_strerror(int error)
* 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 __lxc_h
-#define __lxc_h
+#ifndef __lxc_error_h
+#define __lxc_error_h
typedef enum {
LXC_ERROR_EMPTY,
LXC_ERROR_BUSY,
+ LXC_ERROR_ALREADY_EXISTS,
LXC_ERROR_NOT_FOUND,
LXC_ERROR_PERMISSION_DENIED,
LXC_ERROR_WRONG_COMMAND,
LXC_ERROR_SETUP_NETWORK,
LXC_ERROR_SETUP_ROOTFS,
+ LXC_ERROR_INTERNAL,
+
LXC_LAST_ERROR,
} lxc_error_t;
#include <sys/types.h>
#include <sys/param.h>
+#include "error.h"
#include <lxc/lxc.h>
static int freeze_unfreeze(const char *name, int freeze)
int lxc_freeze(const char *name)
{
if (freeze_unfreeze(name, 1))
- return -1;
+ return -LXC_ERROR_INTERNAL;
if (lxc_setstate(name, FROZEN))
- return -1;
+ return -LXC_ERROR_INTERNAL;
return 0;
}
int lxc_unfreeze(const char *name)
{
if (freeze_unfreeze(name, 0))
- return -1;
+ return -LXC_ERROR_INTERNAL;
if (lxc_setstate(name, RUNNING))
- return -1;
+ return -LXC_ERROR_INTERNAL;
return 0;
}
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
+#include "error.h"
#include <lxc/lxc.h>
#ifndef UNIX_PATH_MAX
fd = socket(PF_NETLINK, SOCK_RAW, 0);
if (fd < 0) {
lxc_log_syserror("failed to create notification socket");
- return -1;
+ return -LXC_ERROR_INTERNAL;
}
memset(&addr, 0, sizeof(addr));
(struct sockaddr *)&from, &len);
if (ret < 0) {
lxc_log_syserror("failed to received state");
- return -1;
+ return -LXC_ERROR_INTERNAL;
}
return ret;
#include <sys/capability.h>
#include <sys/wait.h>
+#include "error.h"
+
#include <lxc/lxc.h>
LXC_TTY_HANDLER(SIGINT);
char init[MAXPATHLEN];
char *val = NULL;
char ttyname[MAXPATHLEN];
- int fd, lock, sv[2], sync = 0, err = -1;
+ int fd, lock, sv[2], sync = 0, err = -LXC_ERROR_INTERNAL;
pid_t pid;
int clone_flags;
lock = lxc_get_lock(name);
if (!lock) {
lxc_log_error("'%s' is busy", name);
- return -1;
+ return -LXC_ERROR_BUSY;
}
if (lock < 0) {
lxc_log_error("failed to acquire lock on '%s':%s",
name, strerror(-lock));
- return -1;
+ return -LXC_ERROR_INTERNAL;
}
/* Begin the set the state to STARTING*/
#include <sys/stat.h>
#include <fcntl.h>
+#include "error.h"
#include <lxc/lxc.h>
#define MAXPIDLEN 20
{
char init[MAXPATHLEN];
char val[MAXPIDLEN];
- int fd, lock, ret = -1;
+ int fd, lock, ret = -LXC_ERROR_INTERNAL;
size_t pid;
lock = lxc_get_lock(name);
if (lock > 0) {
lxc_log_error("'%s' is not running", name);
lxc_put_lock(lock);
- return -1;
+ return -LXC_ERROR_EMPTY;
}
if (lock < 0) {
lxc_log_error("failed to acquire the lock on '%s':%s",
name, strerror(-lock));
- return -1;
+ return -LXC_ERROR_INTERNAL;
}
snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);