Hello,
As part of the FOSS.in workout, I had worked on improving the error
reporting of libcgroup. So, instead of displaying the error code of
50019, with the patch, the user would get a more meaningful error
message.
Testing done: Tried several incorrect scenarios, like, mount point not
existing, executing parser without appropriate permissions, incorrect
config file format, etc.
Note: errno is still not thread specific. So, chances are that the
global variable would be over-written and un-related error message might
be printed. This is a to-do.
Thoughts on the patch ?
Signed-off-by: Ankita Garg <[EMAIL PROTECTED]>
Index: trunk/cgconfig.c
===================================================================
--- trunk.orig/cgconfig.c 2008-11-29 11:21:17.000000000 +0530
+++ trunk/cgconfig.c 2008-12-01 15:01:38.000000000 +0530
@@ -24,6 +24,78 @@
#include <string.h>
#include <errno.h>
+void cgerror(int code)
+{
+ switch(code) {
+ case ECGROUPNOTCOMPILED:
+ printf("Cgroup has not compiled\n");
+ break;
+ case ECGROUPNOTMOUNTED:
+ printf("Cgroup not mounted\n");
+ break;
+ case ECGROUPNOTEXIST:
+ printf("Cgroup does not exist. Check
/proc/cgroups\n");
+ break;
+ case ECGROUPNOTCREATED:
+ printf("Cgroup not created\n");
+ break;
+ case ECGROUPSUBSYSNOTMOUNTED:
+ printf("Cgroup subsystem not mounted\n");
+ break;
+ case ECGROUPNOTOWNER:
+ printf("Caller does not have access to the
cgroup\n");
+ break;
+ case ECGROUPMULTIMOUNTED:
+ printf("Controller bound to different mount
points\n");
+ break;
+ case ECGROUPNOTALLOWED:
+ printf("Operation not allowed\n");
+ break;
+ case ECGCONTROLLEREXISTS:
+ printf("Controller already exists\n");
+ break;
+ case ECGMAXVALUESEXCEEDED:
+ printf("Exceeded maximum number of control
group values in the config file\n");
+ break;
+ case ECGVALUEEXISTS:
+ printf("Control group value already exists.
Check config file\n");
+ break;
+ case ECGINVAL:
+ printf("Invalid operation\n");
+ break;
+ case ECGCONTROLLERCREATEFAILED:
+ printf("Failed to create controller\n");
+ break;
+ case ECGFAIL:
+ printf("Operation failed\n");
+ break;
+ case ECGROUPNOTINITIALIZED:
+ printf("Cgroup not initialized\n");
+ break;
+ case ECGROUPVALUENOTEXIST:
+ printf("Cgroup value does not exist. Check the
config file\n");
+ break;
+ case ECGOTHER:
+ printf("%s\n", strerror(errno));
+ break;
+ case ECGROUPNOTEQUAL:
+ printf("Cgroups not equal\n");
+ break;
+ case ECGCONTROLLERNOTEQUAL:
+ printf("Cgroup controller not equal\n");
+ break;
+ case ECGROUPPARSEFAIL:
+ printf("Error parsing configuration file\n");
+ break;
+ case ECGROUPNORULES:
+ printf("Rules list does not exist\n");
+ break;
+ case ECGMOUNTFAIL:
+ printf("Failed to mount cgroup\n");
+ break;
+ }
+}
+
int main(int argc, char *argv[])
{
int c;
@@ -43,9 +115,8 @@
ret = cgroup_config_load_config(filename);
if (ret) {
printf("Loading configuration file %s "
- "failed, error: %s\n", filename,
- strerror(errno));
- printf("return code = %d\n", ret);
+ "failed, ", filename);
+ cgerror(ret);
exit(3);
}
return 0;
Index: trunk/parse.y
===================================================================
--- trunk.orig/parse.y 2008-11-29 12:40:15.000000000 +0530
+++ trunk/parse.y 2008-11-29 12:42:05.000000000 +0530
@@ -26,7 +26,7 @@
void yyerror(char *s)
{
- fprintf(stderr, "error at line number %d at %c:%s", line_no, *yytext,
+ fprintf(stderr, "error at line number %d at %c:%s. ", line_no, *yytext,
s);
}
--
Regards,
Ankita Garg ([EMAIL PROTECTED])
Linux Technology Center
IBM India Systems & Technology Labs,
Bangalore, India
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel