]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Better error reporting for libcgroup
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Tue, 9 Dec 2008 11:18:39 +0000 (11:18 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Tue, 9 Dec 2008 11:18:39 +0000 (11:18 +0000)
From: Ankita Garg <ankita@in.ibm.com>

This patch adds human readable error messages to the configuration parser.
The error lookup is implemented as a simple table, indexed by the error.

TODO: Save errno at ECGOTHER and pass it down as cgroup_lasterror.

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: Ankita Garg <ankita@in.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@228 4f4bb910-9a46-0410-90c8-c897d4f1cd53

api.c
cgconfig.c
libcgroup.h
libcgroup.map

diff --git a/api.c b/api.c
index 4efb3909508d030aed4ad50799f7174784820bf8..b5bb8ee67f71566cf549675a09bb7aa31d14ffb2 100644 (file)
--- a/api.c
+++ b/api.c
@@ -40,6 +40,7 @@
 #include <ctype.h>
 #include <pwd.h>
 #include <libgen.h>
+#include <assert.h>
 
 #ifndef PACKAGE_VERSION
 #define PACKAGE_VERSION 0.01
@@ -70,6 +71,31 @@ static struct cgroup_rule_list trl;
 /* Lock for the list of rules (rl) */
 static pthread_rwlock_t rl_lock = PTHREAD_RWLOCK_INITIALIZER;
 
+char *cgroup_strerror_codes[] = {
+       "Cgroup is not compiled in",
+       "Cgroup is not mounted",
+       "Cgroup does not exist",
+       "Cgroup has not been created",
+       "Cgroup one of the needed subsystems is not mounted",
+       "Cgroup, request came in from non owner",
+       "Cgroup controllers controllers are bound to different mount points",
+       "Cgroup, operation not allowed",
+       "Cgroup value set exceeds maximum",
+       "Cgroup controller already exists",
+       "Cgroup value already exists",
+       "Cgroup invalid operation",
+       "Cgroup, creation of controller failed",
+       "Cgroup operation failed",
+       "Cgroup not initialized",
+       "Cgroup trying to set value for control that does not exist",
+       "Cgroup generic error, see errno",
+       "Cgroup values are not equal",
+       "Cgroup controllers are different",
+       "Cgroup parsing failed",
+       "Cgroup, rules file does not exist",
+       "Cgroup mounting failed",
+};
+
 static int cg_chown_file(FTS *fts, FTSENT *ent, uid_t owner, gid_t group)
 {
        int ret = 0;
@@ -2077,3 +2103,9 @@ cleanup_path:
        free(path);
        return ret;
 }
+
+char *cgroup_strerror(int code)
+{
+       assert((code >= ECGROUPNOTCOMPILED) && (code < ECGSENTINEL));
+       return cgroup_strerror_codes[code % ECGROUPNOTCOMPILED];
+}
index fab3a720239141a7c8b1bd6ab059fe9cc18a77d5..043678a76055c93d0ac9f326cda8a5eb6db7e3df 100644 (file)
@@ -61,8 +61,7 @@ int main(int argc, char *argv[])
                        if (ret) {
                                printf("Loading configuration file %s "
                                        "failed, error: %s\n", filename,
-                                       strerror(errno));
-                               printf("return code = %d\n", ret);
+                                       cgroup_strerror(ret));
                                exit(3);
                        }
                        return 0;
index 2a93022e2f02d69163e82ee18df45de29c275e5f..4fb99ffb83c477a239f0f202df89de13be3f6023 100644 (file)
@@ -94,6 +94,7 @@ enum cgroup_errors {
        ECGROUPPARSEFAIL, /* Failed to parse rules configuration file. */
        ECGROUPNORULES, /* Rules list does not exist. */
        ECGMOUNTFAIL,
+       ECGSENTINEL,    /* Please insert further error codes above this */
 };
 
 #define CG_NV_MAX 100
@@ -187,6 +188,12 @@ int cgroup_init_rules_cache(void);
  */
 int cgroup_get_current_controller_path(pid_t pid, const char *controller,
                                        char **current_path);
+/**
+ * Return error corresponding to @code in human readable format.
+ * @code: error code for which the corresponding error string is to be
+ * returned
+ */
+char *cgroup_strerror(int code);
 
 /* The wrappers for filling libcg structures */
 
index 61ae3bac3c986d6869999b830fe96b9907803293..3b55ff284334bdd930ed8b9a277ef77b8f2aaf9d 100644 (file)
@@ -40,3 +40,8 @@ global:
 local:
        *;
 };
+
+CGROUP_0.32.1 {
+global:
+       cgroup_strerror;
+} CGROUP_0.32;