diff options
| -rw-r--r-- | libcgroup.h | 5 | ||||
| -rw-r--r-- | wrapper.c | 62 |
2 files changed, 67 insertions, 0 deletions
diff --git a/libcgroup.h b/libcgroup.h index 89f923a..508fe48 100644 --- a/libcgroup.h +++ b/libcgroup.h @@ -122,6 +122,8 @@ enum cgroup_errors { * users need to check errno upon encoutering ECGOTHER. */ ECGOTHER, + ECGROUPNOTEQUAL, + ECGCONTROLLERNOTEQUAL, }; #define CG_MAX_MSG_SIZE 256 @@ -181,6 +183,9 @@ int cgroup_add_value_uint64(struct cgroup_controller *controller, const char *name, u_int64_t value); int cgroup_add_value_bool(struct cgroup_controller *controller, const char *name, bool value); +int cgroup_compare_cgroup(struct cgroup *cgroup_a, struct cgroup *cgroup_b); +int cgroup_compare_controllers(struct cgroup_controller *cgca, + struct cgroup_controller *cgcb); __END_DECLS @@ -229,3 +229,65 @@ int cgroup_add_value_bool(struct cgroup_controller *controller, return 0; } + +int cgroup_compare_controllers(struct cgroup_controller *cgca, + struct cgroup_controller *cgcb) +{ + int i; + + if (!cgca || !cgcb) + return ECGINVAL; + + if (strcmp(cgca->name, cgcb->name)) + return ECGCONTROLLERNOTEQUAL; + + if (cgca->index != cgcb->index) + return ECGCONTROLLERNOTEQUAL; + + for (i = 0; i < cgca->index; i++) { + struct control_value *cva = cgca->values[i]; + struct control_value *cvb = cgcb->values[i]; + + if (strcmp(cva->name, cvb->name)) + return ECGCONTROLLERNOTEQUAL; + + if (strcmp(cva->value, cvb->value)) + return ECGCONTROLLERNOTEQUAL; + } + return 0; +} + +int cgroup_compare_cgroup(struct cgroup *cgroup_a, struct cgroup *cgroup_b) +{ + int i; + + if (!cgroup_a || !cgroup_b) + return ECGINVAL; + + if (strcmp(cgroup_a->name, cgroup_b->name)) + return ECGROUPNOTEQUAL; + + if (cgroup_a->tasks_uid != cgroup_b->tasks_uid) + return ECGROUPNOTEQUAL; + + if (cgroup_a->tasks_gid != cgroup_b->tasks_gid) + return ECGROUPNOTEQUAL; + + if (cgroup_a->control_uid != cgroup_b->control_uid) + return ECGROUPNOTEQUAL; + + if (cgroup_a->control_gid != cgroup_b->control_gid) + return ECGROUPNOTEQUAL; + + if (cgroup_a->index != cgroup_b->index) + return ECGROUPNOTEQUAL; + + for (i = 0; i < cgroup_a->index; i++) { + struct cgroup_controller *cgca = cgroup_a->controller[i]; + struct cgroup_controller *cgcb = cgroup_b->controller[i]; + + if (cgroup_compare_controllers(cgca, cgcb)) + return ECGCONTROLLERNOTEQUAL; + } + return 0; +} |
