summaryrefslogtreecommitdiffstats
path: root/src/api.c
Commit message (Collapse)AuthorAgeFilesLines
* libcgroup: Dont assign values to variables inside if conditionsDhaval Giani2010-03-261-2/+4
| | | | Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* libcgroup: Fix coding style issues in api.cDhaval Giani2010-03-261-55/+57
| | | | | | | | | | | | Pre this patch total: 16 errors, 40 warnings, 3321 lines checked Post this patch total: 2 errors, 5 warnings, 3323 lines checked The remaining errors will cause a code change, and so go in a separate patch. Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* don't export functions that should not be exportedLennart Poettering2010-03-261-3/+3
| | | | | | Signed-off-by: Lennart Poettering <lennart@poettering.net> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* api: don't keep one copy of the mount table per .c fileLennart Poettering2010-03-261-0/+3
| | | | | | | | | | The mount table variables need to be declared in the header file and defined in the .c file. If we don't do that every .o file will end up with its own copy of those variables. Signed-off-by: Lennart Poettering <lennart@poettering.net> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* unexport a couple of variables that don't need to be exportedLennart Poettering2010-03-261-1/+1
| | | | | | Signed-off-by: Lennart Poettering <lennart@poettering.net> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* api: bzero is obsolete BSD, use memset insteadLennart Poettering2010-03-261-1/+1
| | | | | | Signed-off-by: Lennart Poettering <lennart@poettering.net> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* make functions without arguments proper C99 functionsLennart Poettering2010-03-261-6/+6
| | | | | | Signed-off-by: Lennart Poettering <lennart@poettering.net> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* add a couple of FIXMEs to broken codeLennart Poettering2010-03-261-0/+9
| | | | | | Signed-off-by: Lennart Poettering <lennart@poettering.net> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* add const where applicable, drop const where unnecessaryLennart Poettering2010-03-261-28/+28
| | | | | | | | | | | | | | | This patch adds the const qualifier to a number of function arguments (mostly string arguments) so that client libraries can pass their own const strings to the library without having to cast their const'ness away. This also drops a couple of consts where call-by-value is done anyway, and which hence has no effect and just misleads the users and adds unnecessary noise to the signal. After all this is C, not C++. Signed-off-by: Lennart Poettering <lennart@poettering.net> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* Split header file IIIJan Safranek2010-03-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Changelog: - since there are no global macros, base.h is gone - since there is no base.h, all headers need to include <features.h> to get __BEGIN_DECLS - new init.h with cgroup_init() and cgroup_get_subsys_mount_point() - new error.h with error handling enum and related stuff - use #ifndef _LIBCGROUP_*_H instead _LIBCG_*_H in header guards - fix few checkpatch complaints (long lines, whitespaces, ...) The patch includes Makefile and .spec changes. I tested it compiles, make dist produces tarball with all headers, so does also the rpm. 'make' should automatically catch all changes in new headers and recompile dependent (=all) sources when any header changes. libcgroup.h - does not declare anything, it just includes all the other files. In future, it might contain base of doxygen documentation (some introduction etc.) libcgroup/error.h - the big enum with errors + error related functions libcgroup/init.h - libcgroup_init() and cgroup_get_subsys_mount_point() libcgroup/config.h - configuration reading/unloading libcgroup/groups.h - group manipulation stuff (create/modify/delete/free, incl. controllers and get/set values) + definition of struct cgroup (=must be included by libcgroup/tasks.h, which needs it) libcgroup/iterators.h - various walks, *_begin/next/end libcgroup/tasks.h - task classification, incl. rules cache manipulation In addition, I probably removed some #includes, which are not needed now when looking for the minimal #include set to build the project. I also hope I did not miss any function declaration or macro... Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* Make the error stings constJan Safranek2010-03-081-2/+2
| | | | | | | Make the error stings const, just to be safe. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
* [PATCH-v2] Add the write error handling to cg_set_control_value().Ken'ichi Ohmichi2010-01-281-2/+9
| | | | | | | | | | | | | | Changelog since v1: o Use fopen/fprintf/fclose instead of open/write/close. o Add the error handling against fclose. cg_set_control_value() is the function for setting a value to a file of cgroup file system. And current function does not handle the error of writing to a file. So we cannot know whether setting value is enable or not. This patch add the error handling for knowing it. Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
* libcgroup: Modify the APIs to use the namespaceDhaval Giani2010-01-071-1/+7
| | | | | | | | | | | Since every API builds its patch via build_path, updating that function should be enough. Changes from v1: 1. Append the namespace only if it is defined. This will remove an additional "/" which would be introduced otherwise. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Setup the namespace datastructuresDhaval Giani2010-01-071-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch handles the validation of the newer configuration files. Some of the rules to be followed 1. We cannot have more controllers in the namespcae section than already mounted. 2. If more than one controller are mounted at the same point, then they will have the same namespace. In case it is not explicitly mentioned, the subsystems at the mount point will be set to the same namespace. This does not mean that controllers mounted at different points need to have the same namespace. Changes from v4: 1. Changed a variable name from mount to mount_path 2. Added more comments Changes from v3: 1. Removed most of the strdups 2. Fixed return values for errors Changes from v2: 1. mount and namespace keyword cannot come in the same file. Changes from v1: 1. Fix a bug where if a namespace was not defined, we were not exiting 2. Comment the validate namespace function 3. Make some of the variables more descriptive 4. Make namespace thread specific Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Remove assert in cgroup_strerror()Dhaval Giani2010-01-041-1/+1
| | | | | | | Since we add new errors after ECGSENTINEL, it makes no sense to have the assert in place. Remove the assert. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix reading of empty parameter valuesJan Safranek2009-12-221-3/+7
| | | | | | | | | | | When a group parameter has empty value (like uninitialized cpuset.cpus), libcgroup does not return this parameter value - it returns ECGROUPVALUENOTEXIST instead. I think reading whole parameter file instead of just '%s' is the right thing to do - it helps also with multiline values, like cpuacct.stat. Signed-off-by: Jan Safranek <jsafrane@redhat.com>
* Fix error text on failed reading of parameter.Jan Safranek2009-12-221-1/+1
| | | | | | | | | | ECGROUPVALUENOTEXIST is translated by cgroup_strerr to "Cgroup trying to set value for control that does not exist". This is wrong, because the error code is being returned also when *reading* non-existing value, I propose "Cgroup, requested group parameter does not exist". Signed-off-by: Jan Safranek <jsafrane@redhat.com>
* libcgroup: trivial: Fix typoDhaval Giani2009-12-161-1/+1
| | | | | | opened is spelled as opened and not opend Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix cgroup_get_all_controller_{begin, next, end} apiIvana Hutarova Varekova2009-12-161-9/+0
| | | | | | | remove the cgroup_initialized need from all of them - not needed Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Define ECGRULESPARSEFAIL for the parser error of cgrules.conf.Ken'ichi Ohmichi2009-11-111-2/+2
| | | | | | | | | | | | | | | Changelog since v2: o Define ECGRULESPARSEFAIL for avoiding breaking ABI. Changelog since v1: o A new patch [Cleanup: Rename ECGROUPPARSEFAIL to ECGRULESPARSEFAIL.] Now ECGROUPPARSEFAIL is defined for a parser error of /etc/cgrules.conf and this patch defines ECGRULESPARSEFAIL for the same value for clarifying its meaning. Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Remove VERSION macro from api.cJan Safranek2009-08-291-11/+0
| | | | | | | | | The macro and assosicated cg_version is not used anywhere and it generates warning: api.c:58:1: warning: "VERSION" redefined Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Shorten error text of ECGOTHERJan Safranek2009-08-291-4/+1
| | | | | | | | | | | | | | | Let's reformat cgroup_strerror output from Cgroup generic error, error message: Device or resource busy to shorter and clearer Device or resource busy The patch assumes that _GNU_SOURCE is defined. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Fix compile errorDhaval Giani2009-08-061-1/+1
| | | | | | The correct error code is ECGOTHER and not CGOTHER Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* add api for generating the list of all controllers (not only mount ones)Ivana Hutarova Varekova2009-08-061-0/+76
| | | | | | | | | | | | | | | | | | | | | | this patch add api for generating the list of all controllers (not only mount ones) - it uses three functions: cgroup_get_all_controller_begin cgroup_get_all_controller_next cgroup_get_all_controller_end and structure: struct controller_data { char name[FILENAME_MAX]; int hierarchy; int num_cgroups; int enabled; }; the data are read from /proc/cgroups file Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Reviewed-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add recursive cgroup_delete_cgroup_ext.Jan Safranek2009-08-061-26/+124
| | | | | | | | | | | | | | | | | | | Changelog: - add braces to cgroup_delete_cgroup_ext to improve readability - use enum instead of macro to define flags The new function allows to recursively delete whole tree of groups. There is new infrastructure created around (cg_delete_cgroup_controller_recursive). It has inconsistent behavior when root group removal is requested - it removes all children (if requested), but does not remove the root itself and returns success value. This allows simple rewrite of cgclear functions to use this function. Original cgroup_delete_cgroup now leads to cgroup_delete_cgroup_ext. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Split cgroup removal to separate functions.Jan Safranek2009-08-061-49/+154
| | | | | | | | | | | | | | | | | | | | | | | Changelog: - simplify error handling in cg_move_task_files cgroup_delete_cgroup does all the stuff on it's own. This patch refactors the function and moves the parts with complete error handling. The new functions are cg_delete_cgroup_controller and cg_move_task_files. They are not necessarily needed, but it simplifies error handling and clearly distinguishes functionality of cgroup_delete_cgroup. Purpose of the functions should be clearly specified in the doxygen comments. Especially note that cg_delete_cgroup_controller wants already opened file, where all tasks should be moved - this is optimization, which will be used in subsequent patches. I could use cgroup_get_task_* and cgroup_attach_task, which would look definitely nicer, but it would lead to lot of fopen() and fclose() calls. Let me know what do you think about it. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* RFC: Fix cgroup_find_parent functionJan Safranek2009-08-061-31/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | There are more issues with cgroup_find_parent function: 1. The cgroup_find_parent expects, that it's argument is group in cg_mount_table[0] controller, which is not always the case. IMHO the function should accept complete struct cgroup and find real parent. 2. when checking the st_dev of the group and it's parent to prevent "underflow" to real filesystem, actually the parent and it's parent are checked instead of group and it's parent. In addition, I enhanced the function to return real error code when something goes wrong. Open question is, if the function should return just char* as parent's name or whole struct cgroup*. The second case is more natural - we should work with groups and not group names, but in some cases just the name is needed and whole cgroup creation would be unnecessary overhead (I have prepared cgcdelete tool, which needs just parent's name). Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: find better name for CGRULE_CGRED_TEMP_FILEJan Safranek2009-07-011-2/+2
| | | | | | | | Rename CGRULE_CGRED_TEMP_FILE to CGRULE_CGRED_SOCKET_PATH to better describe the macro usage - it's not a temporary file, it's a socket. Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix cgroup_find_matching_rule() call.Ken'ichi Ohmichi2009-06-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Hi, If compiling the latest code (8cc1d9743201cb9ae9a5286c898b9d47e318ed46), the following warning messages are printed. The problem is due to invalid call of cgroup_find_matching_rule_uid_gid(). Instead of this function call, cgroup_find_matching_rule() should be called as "[PATCH-v6 03/11] Add the key "process name" to find a matching rule.". $ make [snip] api.c: In function 'cgroup_change_cgroup_flags': api.c:1994: warning: passing argument 3 of 'cgroup_find_matching_rule_uid_gid' from incompatible pointer type api.c: At top level: api.c:1923: warning: 'cgroup_find_matching_rule' defined but not used [snip] $ * Reference: "[PATCH-v6 03/11] Add the key "process name" to find a matching rule." http://sourceforge.net/mailarchive/message.php?msg_name=4A44617E.9060002%40mxs.nes.nec.co.jp Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Clarify the number meanings of string length.Ken'ichi Ohmichi2009-06-291-4/+4
| | | | | | | | | | | | | | | | Hi, This patch clarifies the number meanings of string length in the function cgroup_get_uid_gid_from_procfs(). This is recreated based on Igawa-san's patch for the latest code. * Reference Igawa-san's patch http://sourceforge.net/mailarchive/message.php?msg_name=20090515.085922.109268324.igawa%40mxs.nes.nec.co.jp Signed-off-by: Masayuki Igawa <igawa@mxs.nes.nec.co.jp> Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the library function cgroup_register_unchanged_process().Ken'ichi Ohmichi2009-06-291-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * No change. Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * No change. Changelog of v3: ================ * No change. Changelog of v2: ================ * New patch. Description: ============ This patch adds the library function cgroup_register_unchanged_process() for notifying cgrulesengd daemon of the unchanged process. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the key "process name" to find a matching rule.Ken'ichi Ohmichi2009-06-291-59/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * No change. Changelog of v5.1: ================== * BUGFIX: Clear the flags meaning "found a matching rule" when a process name does not match. There was a problem that cgexec and cgclassify didn't work correctly if a user executes cgexec/cgclassify based on /etc/cgrules.conf. For example, if a root user executes `cgclassify $$` on the following /etc/cgrules.conf, the process ($$) should be moved to users/root on cpuset and memory subsystems. But the process was moved to users/root/cp on memory subsystem only. Example of /etc/cgrules.conf: ============================= root:cp cpuset users/root/cp % memory users/root/cp root cpuset users/root % memory users/root The cause is why the flags meaning "found a matching rule" (uid, gid, and matched) is not cleared when a process name does not match. This problem is fixed on this patch. Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * No change. Changelog of v3: ================ * BUGFIX: Fix the handling of '%' in /etc/cgrules.conf. Changelog of v2: ================ * Use strcmp() instead of strncmp() for checking a process name strictly. * Some cleanups. Description: ============ This patch adds the key "process name" to find a matching rule. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add the parser of process name in /etc/cgrules.conf.Ken'ichi Ohmichi2009-06-291-4/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * The definations of CGROUP_RULE_MAXKEY and CGROUP_RULE_MAXLINE are moved to libcgroup-internal.h since no one from outside should be using them. Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * Use more safety length of a user name for the buffer "username". * Move the macros min()/max() to src/libcgroup-internal.h for using in src/api.c also. Changelog of v3: ================ * Fix unclear buffer of user by memset(). Changelog of v2: ================ * Remove unnecessary memset(). * Some cleanups. Description: ============ This patch adds the parser of process name in /etc/cgrules.conf. A new rule based on process name is as the following, and the process name is stored into the member "procname" in struct cgroup_rule. <user>:<process name> <controllers> <destination> Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Add cgroup_get_procname_from_procfs() for getting a process name.Ken'ichi Ohmichi2009-06-291-0/+188
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hi, Changelog of v6: ================ * Change the returning values of *_get_procname_from_proc*() to integer from charactor pointer. * Clarify the number meaning of string length in cg_get_procname_from_ ~proc_status() Changelog of v5: ================ * Rebase the patch to the latest code. Changelog of v4: ================ * Add the error handling for strdup()'s error. * Reduce strlen() calls. * Make the check code of a process name simple. Changelog of v3: ================ * Move cgroup_get_procname_from_procfs() to libcgroup-internal.h. * Fix unclear buffer of buf_cwd by memset(). * Get a real path of script file by realpath(). Changelog of v2: ================ * It is possible to handle a process, which name length is over than 16 characters, also. Description: ============ This patch adds a new function cgroup_get_procname_from_procfs() for getting a process name. This function allocates the memory for a process name, and writes the name to the memory, and returns the pointer of the memory. So a caller should free the memory if unusing it. The process name, which is wrotten by this function, depends on the specified process: If a command process) the full path of command. If a shell script process) the full path of shell script. If a kernel thread) the process name of kernel thread. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Introduce an API to get the mount point of a specific subsystemDhaval Giani2009-06-261-0/+28
| | | | | | | | | Introduce an API which will query the mount table and return the mount point of a specific subsystem. This is needed in the case when the user knows which subsystem he wants the details of, which would make the use of the get_controller* APIs cumbersome. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix some warnings.Ken'ichi Ohmichi2009-06-251-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | Hi, The latest source (commit: 5ea9a7819b717a83af03aa2ea234f105ed717589) outputs some following warnings: $ make [snip] api.c: In function 'cgroup_walk_tree_begin': api.c:2350: warning: passing argument 3 of 'cg_walk_node' makes integer from pointer without a cast api.c:2315: warning: unused variable 'fts' [snip] $ This patch fixes them. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* libcgroup: Introduce get_controller APIDhaval Giani2009-06-181-0/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | This set of APIs will allow the caller to query the mount table and find out what controller is mounted at what path. Test program has been included in the patch. Running the test program results in [dhaval@gondor tests]$ ../libtool --mode=execute ./get_controller Controller cpu is mounted at /cgroup Controller cpuacct is mounted at /cgroup Controller memory is mounted at /cgroup1 [dhaval@gondor tests]$ Which is the setup on this system. Changes from v2 1. Remove the incorrect comments as pointed out by Bharata Changes from v1 1. Use a new structure as mentioned by bharata to return the values. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Cc: Jan Safranek <jsafrane@redhat.com> Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
* libcgroup: Use double pointers everywhere in the get_task APIsDhaval Giani2009-06-181-3/+3
| | | | | | | | As Jan Safranek pointed out, it is better to have double pointers everywhere in the get_task API to keep consistency. Do the same. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
* libcgroup: Introduce post order walkDhaval Giani2009-06-181-4/+13
| | | | | | | | | | With the introduction of the flags, we now actually make use of them. This patch adds a post mode and modifies the test case to also do a post order walk. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
* libcgroup: Add flags to the walk_tree handleDhaval Giani2009-06-181-10/+50
| | | | | | | | | | | | | | Introduce a cgroup_tree_handle structure so that we can track flags for the walk_tree operation. In a number of cases we would prefer to walk the tree in postorder as opposed to pre-order which is the current default. This patch does the addition. Changes since V1: 1. Added checks for !handle as suggested by Bharata Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
* cgconfigparser: Change mkdir in cgroup_config_mount_fs to mkdir -pDhaval Giani2009-06-181-1/+1
| | | | | | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=502687 mentioned that the directory was not getting created when a cgconfig start was being run. This is was because we failed the mkdir. The mkdir for directories at depth was not succeeding. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
* Prevent to add multiple versions of the same controller to mount_tableIvana Varekova2009-06-181-0/+18
| | | | | | | | | | | | This patche add a test to cgroup_init function, which prevent to add multiple records for the same controller (this is a problem eg. in cgroup_get_cgroup function - which looks to mount table and add all relevant controllers using cgroup_add_controller function and when the function calls cgroup_add_cgroup function twice on the same controller, it returns error so the result is cgroup_get_cgroup failed). Signed-off-by: Ivana Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Integrate similar code to cgroup_get_uid_gid_from_procfs().Ken'ichi Ohmichi2009-06-081-0/+55
| | | | | | | | | | | | | | CHANGELOG of v2.1: ================ * Rebase the patch for commit '340feae163c4797a6cb1247b3812c1ccdc52fa41'. There are some similar functions for getting process's data (uid, gid) from /proc/<pid>/status file, so this patch integrates these functions into one cgroup_get_uid_gid_from_procfs(). Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Rename "name" to "username" in struct cgroup_rule.Ken'ichi Ohmichi2009-06-081-8/+9
| | | | | | | | | | | | | | | | | | Hi, CHANGELOG of v2: ================ * No change. To add the member "procname" to struct cgroup_rule by later patch, this patch renames the member "name" to "username" for the clarification. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Add cg_skip_unused_charactors_in_rule().Ken'ichi Ohmichi2009-06-081-16/+29
| | | | | | | | | | | | | | | | | | | Hi, CHANGELOG of v2: ================ * No change. The loop in cgroup_parse_rules() is a little long now, and it is not easy to read the loop. Then, This patch shortens the loop for the readability. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Use sizeof() in memset().Ken'ichi Ohmichi2009-06-081-23/+5
| | | | | | | | | | | | | Changelog of v3: ================ * Remove unnecessary memset(). fgets()/sscanf() does not care what is in the buffer, and it is unnecessary to clear the buffer before. Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: Remove unnecessary strlen() in strncpy().Ken'ichi Ohmichi2009-06-081-2/+3
| | | | | | | | | | | | | | | | Hi, CHANGELOG of v2: ================ * Specify the buffer size of 'user' instead of strlen(). It actually walks through 'user' twice, once to compute length by strlen() and then this patch specifies the buffer size of 'user' instead. Reported-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Cleanup: make the indent of cgroup_init()shallower.Ken'ichi Ohmichi2009-05-181-22/+20
| | | | | | | | | | | | | Hi, This patch makes the indent of cgroup_init() shallower for the readability. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Acked-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix the error handling if failing to open/etc/cgrules.conf.Ken'ichi Ohmichi2009-05-181-4/+5
| | | | | | | | | | | | | Hi, If failing to open /etc/cgrules.conf in cgroup_parse_rules(), rl_lock should be unlocked. This patch fixes the code for doing it. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
* Fix ECGOTHER error messageIvana Varekova2009-05-081-2/+2
| | | | | | | | | | | | For now the result is eg.: Cgroup generic error, see errno: error message: No such file or directory this patch remove outdated "see errno: " part. second version Signed-off-by: Ivana Varekova <varekova@redhat.com> Acked-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>