diff options
author | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2008-06-16 18:11:37 +0000 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2008-06-16 18:11:37 +0000 |
commit | 7e671e48c7a2cfc4f9cae4fd8f909111ded24c60 (patch) | |
tree | 2641e9182cf80d8c080299ff2992d314e2929be0 /tests/libcg_ba.cpp | |
parent | d90a5a5fcfd899f32eae6fd3ce87b082ff221df8 (diff) | |
parent | f00b82b6f9114694e3c05e2bb3a5395ce59c85de (diff) | |
download | libcg-7e671e48c7a2cfc4f9cae4fd8f909111ded24c60.tar.gz libcg-7e671e48c7a2cfc4f9cae4fd8f909111ded24c60.tar.xz libcg-7e671e48c7a2cfc4f9cae4fd8f909111ded24c60.zip |
libcg: Add a new trunk
Setting trunk to v0.1c. This is the branch against which
all development should take place.
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@79 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests/libcg_ba.cpp')
-rw-r--r-- | tests/libcg_ba.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/tests/libcg_ba.cpp b/tests/libcg_ba.cpp index b8df520..f06ba9b 100644 --- a/tests/libcg_ba.cpp +++ b/tests/libcg_ba.cpp @@ -11,17 +11,19 @@ * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * Basic acceptance test for libcg - Written one late night by Balbir Singh + * Basic acceptance test for libcgroup - Written one late night by Balbir Singh */ using namespace std; #include <string> #include <stdexcept> #include <iostream> -#include <libcg.h> +#include <libcgroup.h> #include <sys/types.h> #include <pwd.h> #include <errno.h> +#include <stdlib.h> +#include <string.h> namespace cgtest { @@ -40,7 +42,7 @@ cg::cg(void) { int ret; - ret = cg_init(); + ret = cgroup_init(); if (ret) throw logic_error("Control Group Initialization failed..." "Please check that cgroups are mounted and\n" @@ -53,13 +55,13 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid, { uid_t tuid, cuid; gid_t tgid, cgid; + char *cgroup_name; struct cgroup *ccg; + struct cgroup_controller *cpu, *memory, *cpuacct; struct passwd *passwd; struct group *grp; int ret; - ccg = (struct cgroup *)malloc(sizeof(*ccg)); - passwd = getpwnam(task_uid.c_str()); if (!passwd) return NULL; @@ -82,24 +84,23 @@ struct cgroup *cg::makenode(const string &name, const string &task_uid, dbg("tuid %d, tgid %d, cuid %d, cgid %d\n", tuid, tgid, cuid, cgid); - strcpy(ccg->name, name.c_str()); - ccg->controller[0] = (struct controller *) - calloc(1, sizeof(struct controller)); - strcpy(ccg->controller[0]->name,"cpu"); - - ccg->controller[0]->values[0] = (struct control_value *) - calloc(1, sizeof(struct control_value)); - strcpy(ccg->controller[0]->values[0]->name,"cpu.shares"); - strcpy(ccg->controller[0]->values[0]->value, "100"); - ccg->tasks_uid = tuid; - ccg->tasks_gid = tgid; - ccg->control_uid = cuid; - ccg->control_gid = cgid; - - ret = cg_create_cgroup(ccg, 1); + cgroup_name = (char *) malloc(name.length()); + memset(cgroup_name, '\0', name.length()); + strncpy(cgroup_name, name.c_str(), name.length()); + + ccg = cgroup_new_cgroup(cgroup_name, tuid, tgid, cuid, cgid); + cpu = cgroup_add_controller(ccg, "cpu"); + cgroup_add_value_uint64(cpu, "cpu.shares", 2048); + memory = cgroup_add_controller(ccg, "memory"); + cgroup_add_value_uint64(memory, "memory.limit_in_bytes", 102400); + cpuacct = cgroup_add_controller(ccg, "cpuacct"); + cgroup_add_value_uint64(cpuacct, "cpuacct.usage", 0); + + + ret = cgroup_create_cgroup(ccg, 1); if (ret) { cout << "cg create group failed " << errno << endl; - ret = cg_delete_cgroup(ccg, 1); + ret = cgroup_delete_cgroup(ccg, 1); if (ret) cout << "cg delete group failed " << errno << endl; } @@ -116,6 +117,7 @@ int main(int argc, char *argv[]) struct cgroup *ccg; ccg = app->makenode("database", "root", "root", "balbir", "balbir"); + cgroup_free(&ccg); delete app; } catch (exception &e) { cout << e.what() << endl; |