From: Daniel Lezcano Date: Fri, 17 Dec 2010 10:43:37 +0000 (+0100) Subject: encapsulate the ns_cgroup X-Git-Tag: lxc-0.7.4-rc1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36b862992a8e685534774a59793fb5c5bad46fae;p=thirdparty%2Flxc.git encapsulate the ns_cgroup Create a single API to create a cgroup which will switch to the old ns_cgroup automatically. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index 350d43966..4b549065f 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -142,6 +142,16 @@ int lxc_unlink_nsgroup(const char *name) return ret; } +int lxc_cgroup_create(const char *name, pid_t pid) +{ + return lxc_rename_nsgroup(name, pid); +} + +int lxc_cgroup_destroy(const char *name) +{ + return lxc_unlink_nsgroup(name); +} + int lxc_cgroup_path_get(char **path, const char *name) { char cgroup[MAXPATHLEN]; diff --git a/src/lxc/cgroup.h b/src/lxc/cgroup.h index 905686e4c..8607fa804 100644 --- a/src/lxc/cgroup.h +++ b/src/lxc/cgroup.h @@ -26,8 +26,8 @@ #define MAXPRIOLEN 24 struct lxc_handler; -int lxc_rename_nsgroup(const char *name, pid_t pid); -int lxc_unlink_nsgroup(const char *name); +int lxc_cgroup_create(const char *name, pid_t pid); +int lxc_cgroup_destroy(const char *name); int lxc_cgroup_path_get(char **path, const char *name); int lxc_cgroup_nrtasks(const char *name); #endif diff --git a/src/lxc/lxc_unshare.c b/src/lxc/lxc_unshare.c index 62349eb6c..a82490eef 100644 --- a/src/lxc/lxc_unshare.c +++ b/src/lxc/lxc_unshare.c @@ -214,7 +214,7 @@ int main(int argc, char *argv[]) ERROR("pid_name: failed to allocate memory"); return -1; } - lxc_unlink_nsgroup(pid_name); + lxc_cgroup_destroy(pid_name); free(pid_name); return lxc_error_set_and_log(pid, status); diff --git a/src/lxc/start.c b/src/lxc/start.c index 7e17cc557..b8ceff6bd 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -506,7 +506,7 @@ int lxc_spawn(struct lxc_handler *handler) if (lxc_sync_wait_child(handler, LXC_SYNC_CONFIGURE)) failed_before_rename = 1; - if (lxc_rename_nsgroup(name, handler->pid)) + if (lxc_cgroup_create(name, handler->pid)) goto out_delete_net; if (failed_before_rename) @@ -585,7 +585,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf, out_fini: LXC_TTY_DEL_HANDLER(SIGQUIT); LXC_TTY_DEL_HANDLER(SIGINT); - lxc_unlink_nsgroup(name); + lxc_cgroup_destroy(name); lxc_fini(name, handler); return err;