Commit 58412580 by dlezcano

Add error status for the API

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 2aa79ee7
......@@ -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 \
......
/*
* 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];
}
/*
* 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
......@@ -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
*/
......@@ -164,6 +166,14 @@ 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
* @fd : file descriptor on which the container is checkpointed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment