]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add error status for the API
authordlezcano <dlezcano>
Mon, 17 Nov 2008 15:18:19 +0000 (15:18 +0000)
committerdlezcano <dlezcano>
Mon, 17 Nov 2008 15:18:19 +0000 (15:18 +0000)
From: Daniel Lezcano <dlezcano@fr.ibm.com>

Added the error codes and the corresponding strings to the liblxc, so
the error raised to the user can be more understandable.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/Makefile.am
src/lxc/error.c [new file with mode: 0644]
src/lxc/error.h [new file with mode: 0644]
src/lxc/lxc.h

index 62871c5f4de1bf3398b17f54a43788902cbeb2aa..ead9a8ac9d639d2cb43cfe59438b1361bf24b364 100644 (file)
@@ -22,6 +22,7 @@ liblxc_la_SOURCES = \
        checkpoint.c \
        restart.c \
        version.c \
+       error.h error.c \
        cgroup.c cgroup.h \
        lxc.h \
        lxc_utils.h \
diff --git a/src/lxc/error.c b/src/lxc/error.c
new file mode 100644 (file)
index 0000000..a98fdf8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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
+ */
+
+#include <stdio.h>
+#include "error.h"
+
+
+static char *catalogue[] = {
+       [LXC_ERROR_EMPTY] = "The container is not running",
+       [LXC_ERROR_BUSY] = "The container is busy",
+       [LXC_ERROR_NOT_FOUND] = "The container was not found",
+       [LXC_ERROR_PERMISSION_DENIED] = "Permission denied",
+       [LXC_ERROR_WRONG_COMMAND] = "Wrong command",
+
+       [LXC_ERROR_CONF_CGROUP] = "Failed to configure the control group",
+       [LXC_ERROR_CONF_MOUNT] = "Failed to configure the mount points",
+       [LXC_ERROR_CONF_UTSNAME] = "Failed to configure the utsname",
+       [LXC_ERROR_CONF_NETWORK] = "Failed to configure the network",
+       [LXC_ERROR_CONF_ROOTFS] = "Failed to configure the root fs",
+
+       [LXC_ERROR_SETUP_CGROUP] = "Failed to setup the control group",
+       [LXC_ERROR_SETUP_MOUNT] = "Failed to setup the mount points",
+       [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",
+};
+
+const char *const lxc_strerror(int error)
+{
+       if (error < 0 || error >= LXC_LAST_ERROR)
+               return NULL;
+       return catalogue[error];
+}
diff --git a/src/lxc/error.h b/src/lxc/error.h
new file mode 100644 (file)
index 0000000..295e8cd
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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 __lxc_h
+#define __lxc_h
+
+typedef enum {
+       LXC_ERROR_EMPTY,
+       LXC_ERROR_BUSY,
+       LXC_ERROR_NOT_FOUND,
+       LXC_ERROR_PERMISSION_DENIED,
+       LXC_ERROR_WRONG_COMMAND,
+
+       LXC_ERROR_CONF_CGROUP,
+       LXC_ERROR_CONF_MOUNT,
+       LXC_ERROR_CONF_UTSNAME,
+       LXC_ERROR_CONF_NETWORK,
+       LXC_ERROR_CONF_ROOTFS,
+
+       LXC_ERROR_SETUP_CGROUP,
+       LXC_ERROR_SETUP_MOUNT,
+       LXC_ERROR_SETUP_UTSNAME,
+       LXC_ERROR_SETUP_NETWORK,
+       LXC_ERROR_SETUP_ROOTFS,
+
+       LXC_LAST_ERROR,
+} lxc_error_t;
+
+#endif
index af3f0878f4690391de6423cb7af78a0534b5cd90..fa040589bd1800c93041c5fbe8a842e6352057f2 100644 (file)
@@ -64,7 +64,8 @@ extern int lxc_create(const char *name, struct lxc_conf *conf);
 extern int lxc_destroy(const char *name);
 
 /*
- * Start the container previously created with lxc_create.
+ * Start the specified command inside a container which has
+ * been created before with lxc_create.
  * @name     : the name of the container
  * @argv     : an array of char * corresponding to the commande line
  * Returns 0 on sucess, < 0 otherwise
@@ -72,7 +73,8 @@ extern int lxc_destroy(const char *name);
 extern int lxc_start(const char *name, char *argv[]);
 
 /*
- * Stop the container previously started with lxc_start or lxc_exec
+ * Stop the container previously started with lxc_start, all
+ * the processes running inside this container will be killed.
  * @name : the name of the container
  * Returns 0 on success, < 0 otherwise
  */
@@ -163,6 +165,14 @@ extern int lxc_cgroup_set(const char *name, const char *subsystem, const char *v
 extern int lxc_cgroup_get(const char *name, const char *subsystem, 
                          char *value, size_t len);
 
+/*
+ * Retrieve the error string associated with the error returned by
+ * the function.
+ * @error : the value of the error
+ * Returns a string on success or NULL otherwise.
+ */
+extern int lxc_strerror(int error);
+
 /*
  * Checkpoint a container previously frozen
  * @name : the name of the container being checkpointed