Re: [lxc-devel] [PATCH] make sure to check c->lxc_conf is not NULL before dereferencing it.
Quoting S.Çağlar Onur (cag...@10ur.org): > Signed-off-by: S.Çağlar Onur Acked-by: Serge E. Hallyn > --- > src/lxc/lxccontainer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c > index a9d97ad..362b429 100644 > --- a/src/lxc/lxccontainer.c > +++ b/src/lxc/lxccontainer.c > @@ -441,7 +441,7 @@ static bool lxcapi_load_config(struct lxc_container *c, > const char *alt_file) > > static void lxcapi_want_daemonize(struct lxc_container *c) > { > - if (!c) > + if (!c || !c->lxc_conf) > return; > if (container_mem_lock(c)) { > ERROR("Error getting mem lock"); > -- > 1.8.3.2 > > > -- > Android is increasing in popularity, but the open development platform that > developers love is also attractive to malware creators. Download this white > paper to learn more about secure code signing practices that can help keep > Android apps secure. > http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH] allow setting/getting lxc.loglevel and lxc.logfile via set_config_item/get_config_item API calls
Quoting S.Çağlar Onur (cag...@10ur.org): > Signed-off-by: S.Çağlar Onur A bit more description would have been appreciated :) But I think I see. We also may want to change it so that the logfile and loglevel can actually be changed mid-run. At some point. Acked-by: Serge E. Hallyn > --- > src/lxc/log.c | 10 ++ > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/src/lxc/log.c b/src/lxc/log.c > index 0946e44..e5eb04f 100644 > --- a/src/lxc/log.c > +++ b/src/lxc/log.c > @@ -295,13 +295,13 @@ extern int lxc_log_init(const char *name, const char > *file, > } > > if (priority) { > - lxc_loglevel_specified = 1; > - lxc_priority = lxc_log_priority_to_int(priority); > - > if (lxc_priority == LXC_LOG_PRIORITY_NOTSET) { > ERROR("invalid log priority %s", priority); > return -1; > } > + > + lxc_loglevel_specified = 1; > + lxc_priority = lxc_log_priority_to_int(priority); > } > > lxc_log_category_lxc.priority = lxc_priority; > @@ -314,9 +314,9 @@ extern int lxc_log_init(const char *name, const char > *file, > lxc_log_set_prefix(prefix); > > if (file) { > - lxc_logfile_specified = 1; > if (strcmp(file, "none") == 0) > return 0; > + lxc_logfile_specified = 1; > ret = __lxc_log_set_file(file, 1); > } else { > ret = -1; > @@ -362,6 +362,7 @@ extern int lxc_log_set_level(int level) > ERROR("invalid log priority %d", level); > return -1; > } > + lxc_loglevel_specified = 1; > lxc_log_category_lxc.priority = level; > return 0; > } > @@ -390,6 +391,7 @@ extern int lxc_log_set_file(const char *fname) > { > if (lxc_logfile_specified) > return 0; > + lxc_logfile_specified = 1; > return __lxc_log_set_file(fname, 0); > } > > -- > 1.8.3.2 > > > -- > Android is increasing in popularity, but the open development platform that > developers love is also attractive to malware creators. Download this white > paper to learn more about secure code signing practices that can help keep > Android apps secure. > http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [lxc/lxc] 497a29: make sure to check c->lxc_conf is not NULL before ...
Branch: refs/heads/master Home: https://github.com/lxc/lxc Commit: 497a2995687a56a1f12a69311d8bacbb645e0d97 https://github.com/lxc/lxc/commit/497a2995687a56a1f12a69311d8bacbb645e0d97 Author: S.Çağlar Onur Date: 2013-11-04 (Mon, 04 Nov 2013) Changed paths: M src/lxc/lxccontainer.c Log Message: --- make sure to check c->lxc_conf is not NULL before dereferencing it. Signed-off-by: S.Çağlar Onur Signed-off-by: Serge Hallyn Commit: b12e1cb533be198ee71d9e517ab816617279e537 https://github.com/lxc/lxc/commit/b12e1cb533be198ee71d9e517ab816617279e537 Author: S.Çağlar Onur Date: 2013-11-04 (Mon, 04 Nov 2013) Changed paths: M src/lxc/log.c Log Message: --- allow setting/getting lxc.loglevel and lxc.logfile via set_config_item/get_config_item API calls Signed-off-by: S.Çağlar Onur Signed-off-by: Serge Hallyn Compare: https://github.com/lxc/lxc/compare/702154800639...b12e1cb533be -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH 1/3] add [gs]et_cgroup_item to lua api
Quoting Dwight Engen (dwight.en...@gmail.com): > fix up api test to run and add test for new [gs]et_cgroup_item > > Signed-off-by: Dwight Engen For the set, Acked-by: Serge E. Hallyn > --- > src/lua-lxc/core.c | 35 +++ > src/lua-lxc/lxc.lua | 16 > src/lua-lxc/test/apitest.lua | 13 + > 3 files changed, 64 insertions(+) > > diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c > index 002e8bf..ea19cc3 100644 > --- a/src/lua-lxc/core.c > +++ b/src/lua-lxc/core.c > @@ -282,6 +282,29 @@ static int container_clear_config_item(lua_State *L) > return 1; > } > > +static int container_get_cgroup_item(lua_State *L) > +{ > +struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); > +const char *key = luaL_checkstring(L, 2); > +int len; > +char *value; > + > +len = c->get_cgroup_item(c, key, NULL, 0); > +if (len <= 0) > + goto not_found; > + > +value = alloca(sizeof(char)*len + 1); > +if (c->get_cgroup_item(c, key, value, len + 1) != len) > + goto not_found; > + > +lua_pushstring(L, value); > +return 1; > + > +not_found: > +lua_pushnil(L); > +return 1; > +} > + > static int container_get_config_item(lua_State *L) > { > struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); > @@ -305,6 +328,16 @@ not_found: > return 1; > } > > +static int container_set_cgroup_item(lua_State *L) > +{ > +struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); > +const char *key = luaL_checkstring(L, 2); > +const char *value = luaL_checkstring(L, 3); > + > +lua_pushboolean(L, !!c->set_cgroup_item(c, key, value)); > +return 1; > +} > + > static int container_set_config_item(lua_State *L) > { > struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME); > @@ -361,6 +394,8 @@ static luaL_Reg lxc_container_methods[] = > {"config_file_name", container_config_file_name}, > {"load_config", container_load_config}, > {"save_config", container_save_config}, > +{"get_cgroup_item", container_get_cgroup_item}, > +{"set_cgroup_item", container_set_cgroup_item}, > {"get_config_path", container_get_config_path}, > {"set_config_path", container_set_config_path}, > {"get_config_item", container_get_config_item}, > diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua > index aa80a95..7c9580e 100755 > --- a/src/lua-lxc/lxc.lua > +++ b/src/lua-lxc/lxc.lua > @@ -189,6 +189,10 @@ function container:clear_config_item(key) > return self.core:clear_config_item(key) > end > > +function container:get_cgroup_item(key) > +return self.core:get_cgroup_item(key) > +end > + > function container:get_config_item(key) > local value > local vals = {} > @@ -209,6 +213,10 @@ function container:get_config_item(key) > return vals > end > > +function container:set_cgroup_item(key, value) > +return self.core:set_cgroup_item(key, value) > +end > + > function container:set_config_item(key, value) > return self.core:set_config_item(key, value) > end > @@ -410,6 +418,14 @@ function M.containers_running(names_only) > return containers > end > > +function M.version_get() > +return core.version_get() > +end > + > +function M.default_config_path_get() > +return core.default_config_path_get() > +end > + > lxc_path = core.default_config_path_get() > cgroup_path = cgroup_path_get() > > diff --git a/src/lua-lxc/test/apitest.lua b/src/lua-lxc/test/apitest.lua > index 1365f91..f957ca4 100755 > --- a/src/lua-lxc/test/apitest.lua > +++ b/src/lua-lxc/test/apitest.lua > @@ -206,6 +206,17 @@ function test_container_in_cfglist(should_find) > end > end > > +function test_container_cgroup() > +log(0, "Test get/set cgroup items...") > + > +max_mem = container:get_cgroup_item("memory.max_usage_in_bytes") > +saved_limit = container:get_cgroup_item("memory.limit_in_bytes") > +assert(saved_limit ~= max_mem) > +assert(container:set_cgroup_item("memory.limit_in_bytes", max_mem)) > +assert(container:get_cgroup_item("memory.limit_in_bytes") ~= saved_limit) > +assert(container:set_cgroup_item("memory.limit_in_bytes", "-1")) > +end > + > function test_config_items() > log(0, "Test set/clear configuration items...") > > @@ -313,6 +324,8 @@ test_config_network(0) > test_container_start() > test_container_started() > > +test_container_cgroup() > + > test_container_freeze() > test_container_frozen() > test_container_unfreeze() > -- > 1.8.3.1 > > > -- > Android is increasing in popularity, but the open development platform that > developers love is also attractive to malware creators. Download this white > paper to learn more about secure code signing practices th
[lxc-devel] [lxc/lxc] 80ee22: add [gs]et_cgroup_item to lua api
Branch: refs/heads/master Home: https://github.com/lxc/lxc Commit: 80ee22284b4172f9ff1d55c62e4a0ef01a4be92e https://github.com/lxc/lxc/commit/80ee22284b4172f9ff1d55c62e4a0ef01a4be92e Author: Dwight Engen Date: 2013-11-04 (Mon, 04 Nov 2013) Changed paths: M src/lua-lxc/core.c M src/lua-lxc/lxc.lua M src/lua-lxc/test/apitest.lua Log Message: --- add [gs]et_cgroup_item to lua api fix up api test to run and add test for new [gs]et_cgroup_item Signed-off-by: Dwight Engen Signed-off-by: Serge Hallyn Commit: 891f838ba8c555a4fd3097f952d503d144ad9fb8 https://github.com/lxc/lxc/commit/891f838ba8c555a4fd3097f952d503d144ad9fb8 Author: Dwight Engen Date: 2013-11-04 (Mon, 04 Nov 2013) Changed paths: M src/lua-lxc/lxc.lua Log Message: --- lua: fix stats collection using get_cgroup_item Previously, the lua stats collection was building its own paths to the cgroup files, which could be wrong depending on what --with-cgroup-pattern was passed to configure. Fix it to use the get_cgroup_item api so it always finds the files. Remove cgroup_path_get since it is not used anymore. Signed-off-by: Dwight Engen Signed-off-by: Serge Hallyn Commit: 2752ecec3232c231469a2ad8513a5527fef66fd6 https://github.com/lxc/lxc/commit/2752ecec3232c231469a2ad8513a5527fef66fd6 Author: Dwight Engen Date: 2013-11-04 (Mon, 04 Nov 2013) Changed paths: M doc/lxc-top.sgml.in M src/lua-lxc/lxc.lua M src/lxc/lxc-top Log Message: --- lxc-top: show kernel memory being used if available - Also removed duplicate stats_clear lua function Signed-off-by: Dwight Engen Signed-off-by: Serge Hallyn Compare: https://github.com/lxc/lxc/compare/b12e1cb533be...2752ecec3232 -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] Heads up alpha-2
Hey everyone, I'm planning to tag alpha-2 early next week, probably on Monday or Tuesday, so please make sure any patch that you sent and wanted merged has been merged. If we missed something, please let us know. I'll do my usual pre-milestone round on the github bug tracker and process any outstanding merge proposal there. Now is a good time to give a proper test of current master and raise any bug/regression that you can find so we can try to get those resolved before alpha-2. -- Stéphane Graber Ubuntu developer http://www.ubuntu.com signature.asc Description: Digital signature -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH] allow setting/getting lxc.loglevel and lxc.logfile via set_config_item/get_config_item API calls
Hi Serge, On Mon, Nov 4, 2013 at 7:23 AM, Serge Hallyn wrote: > Quoting S.Çağlar Onur (cag...@10ur.org): >> Signed-off-by: S.Çağlar Onur > > A bit more description would have been appreciated :) But I think > I see. Yeah, you are right. I was working on something else when I observed this problem so prepared a patch quickly without proper explanation. Sorry about that :/ > We also may want to change it so that the logfile and loglevel > can actually be changed mid-run. At some point. > > Acked-by: Serge E. Hallyn > >> --- >> src/lxc/log.c | 10 ++ >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/src/lxc/log.c b/src/lxc/log.c >> index 0946e44..e5eb04f 100644 >> --- a/src/lxc/log.c >> +++ b/src/lxc/log.c >> @@ -295,13 +295,13 @@ extern int lxc_log_init(const char *name, const char >> *file, >> } >> >> if (priority) { >> - lxc_loglevel_specified = 1; >> - lxc_priority = lxc_log_priority_to_int(priority); >> - >> if (lxc_priority == LXC_LOG_PRIORITY_NOTSET) { >> ERROR("invalid log priority %s", priority); >> return -1; >> } >> + >> + lxc_loglevel_specified = 1; >> + lxc_priority = lxc_log_priority_to_int(priority); >> } >> >> lxc_log_category_lxc.priority = lxc_priority; >> @@ -314,9 +314,9 @@ extern int lxc_log_init(const char *name, const char >> *file, >> lxc_log_set_prefix(prefix); >> >> if (file) { >> - lxc_logfile_specified = 1; >> if (strcmp(file, "none") == 0) >> return 0; >> + lxc_logfile_specified = 1; >> ret = __lxc_log_set_file(file, 1); >> } else { >> ret = -1; >> @@ -362,6 +362,7 @@ extern int lxc_log_set_level(int level) >> ERROR("invalid log priority %d", level); >> return -1; >> } >> + lxc_loglevel_specified = 1; >> lxc_log_category_lxc.priority = level; >> return 0; >> } >> @@ -390,6 +391,7 @@ extern int lxc_log_set_file(const char *fname) >> { >> if (lxc_logfile_specified) >> return 0; >> + lxc_logfile_specified = 1; >> return __lxc_log_set_file(fname, 0); >> } >> >> -- >> 1.8.3.2 >> >> >> -- >> Android is increasing in popularity, but the open development platform that >> developers love is also attractive to malware creators. Download this white >> paper to learn more about secure code signing practices that can help keep >> Android apps secure. >> http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk >> ___ >> Lxc-devel mailing list >> Lxc-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/lxc-devel -- S.Çağlar Onur -- Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH RFC] create_run_template: tell the template what caller's uid was mapped to
This is still RFC at the conceptual level. Problem: when creating containers unprivileged, we run the template in a new user ns. For instance if I have lxc.id_map = u 0 10 1 lxc.id_map = g 0 10 1 in my lxc.conf and do lxc-create -f lxc.conf -P ~/lxcbase -t ubuntu-cloud -n a1, then the ubuntu-cloud template is run as root in a user ns where root is mapped to 10 on the host. Any files it creates are owned by uid 10, which can become inconvenient. I've considered splitting the templates up into two separate runs. One run as the calling uid in the host uid namespace to fetch and cache the image/tarball/whatever. The next, in a mapped user namespace as root in that namespace, to only extract and configure the container rootfs. What I'm doing here is passing the namespace uid to which the caller's uid (on the host) is mapped, to the template. The ubuntu-cloud template then chowns the cached images to that user. This doesn't clean everything up perfectly - the ubuntu-cloudimg-query has cached some info as well. # ls -l .cache drwxrwxr-x 5 serge 10 4096 Nov 4 18:03 lxc -rw-r--r-- 1 serge serge 0 Oct 21 21:21 motd.legal-displayed drwxrwxr-x 2 10 10 4096 Nov 4 17:58 ubuntu-cloudimg-query This suggests that there will always be side effects resulting in mis-owned files, and trying to fix those will just become unmaintainable in itself. I do also have a patch which splits the template calls into two (one for caching), which I wrote on friday, but I wasn't happy with that either. So I'm sending this out for comment. Failing any brilliant ideas, I will probably combine the two patches and just aim for the cleanest result with ubuntu-cloud and cirros templates. Signed-off-by: Serge Hallyn --- src/lxc/conf.c| 6 +++--- src/lxc/conf.h| 2 +- src/lxc/lxccontainer.c| 38 ++ templates/lxc-ubuntu-cloud.in | 19 +-- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 2a47e77..afdaa14 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -2912,7 +2912,7 @@ uid_t get_mapped_rootid(struct lxc_conf *conf) return (uid_t)-1; } -bool hostid_is_mapped(int id, struct lxc_conf *conf) +int mapped_hostid(int id, struct lxc_conf *conf) { struct lxc_list *it; struct id_map *map; @@ -2921,9 +2921,9 @@ bool hostid_is_mapped(int id, struct lxc_conf *conf) if (map->idtype != ID_TYPE_UID) continue; if (id >= map->hostid && id < map->hostid + map->range) - return true; + return (id - map->hostid) + map->nsid; } - return false; + return -1; } int find_unmapped_nsuid(struct lxc_conf *conf) diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 71399b9..940d493 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -362,7 +362,7 @@ extern void lxc_rename_phys_nics_on_shutdown(struct lxc_conf *conf); extern uid_t get_mapped_rootid(struct lxc_conf *conf); extern int find_unmapped_nsuid(struct lxc_conf *conf); -extern bool hostid_is_mapped(int id, struct lxc_conf *conf); +extern int mapped_hostid(int id, struct lxc_conf *conf); extern int chown_mapped_root(char *path, struct lxc_conf *conf); extern int ttys_shift_ids(struct lxc_conf *c); #endif diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 946133d..594a96d 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -916,20 +916,28 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool quiet * If we're running the template in a mapped userns, then * we prepend the template command with: * lxc-usernsexec <-m map1> ... <-m mapn> -- +* and we append "--mapped-uid x", where x is the mapped uid +* for our geteuid() */ if (geteuid() != 0 && !lxc_list_empty(&conf->id_map)) { int n2args = 1; + char txtuid[20]; char **n2 = malloc(n2args * sizeof(*n2)); struct lxc_list *it; struct id_map *map; + if (!n2) { + SYSERROR("out of memory"); + exit(1); + } newargv[0] = tpath; tpath = "lxc-usernsexec"; n2[0] = "lxc-usernsexec"; lxc_list_for_each(it, &conf->id_map) { map = it->elem; n2args += 2; - n2 = realloc(n2, n2args * sizeof(*n2)); + n2 = realloc(n2, n2args * sizeof(char *)); +INFO("allocated %d items to n2", n2args); if (!n2)
[lxc-devel] [PATCH 2/2] add statistics to lxc-info
- added list_all_containers() which returns both defined and active containers. - allow lxc-info to show more than one container, using regex for the name Signed-off-by: Dwight Engen --- doc/lxc-info.sgml.in | 65 - src/lxc/lxc_info.c | 257 + src/lxc/lxccontainer.c | 47 + src/lxc/lxccontainer.h | 2 + 4 files changed, 349 insertions(+), 22 deletions(-) diff --git a/doc/lxc-info.sgml.in b/doc/lxc-info.sgml.in index 819d5ca..791d780 100644 --- a/doc/lxc-info.sgml.in +++ b/doc/lxc-info.sgml.in @@ -47,20 +47,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA lxc-info - -n name + -n name -c KEY -s -p -i -t state + -S + -H Description - lxc-info queries and shows information about a - container. + lxc-info queries and shows information about + containers. @@ -70,11 +72,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -n name + -n name -The container name. +The container name. It is interpreted as a regular expression, +so it is possible to get information on all containers, several +of them or just one. See + + regex +7 + for regular expression syntax. If not specified, +name will default to '.*' which +will give information on all containers in +lxcpath. @@ -126,6 +137,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + -S + + + +Just print the container's statistics. +Note that for performance reasons the kernel does not account +kernel memory use unless a kernel memory limit is set. If a limit +is not set, lxc-info will display kernel memory +use as 0. A limit can be set by specifying + +lxc.cgroup.memory.kmem.limit_in_bytes = number + +in your container configuration file, see + + lxc.conf + 5 +. + + + + + + + -H + + + +Print the container's statistics in raw, non-humanized form. The +default is to print statistics in humanized form. + + + + + + -t state @@ -152,6 +198,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +lxc-info -n 'ubuntu.*' + + +Show information for all containers whose name starts with ubuntu. + + + + + lxc-info -n foo -t RUNNING diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c index aeaf9a8..a05d610 100644 --- a/src/lxc/lxc_info.c +++ b/src/lxc/lxc_info.c @@ -25,11 +25,14 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include "commands.h" @@ -38,6 +41,8 @@ static bool ips; static bool state; static bool pid; +static bool stats; +static bool humanize = true; static char *test_state = NULL; static char **key = NULL; static int keys = 0; @@ -53,6 +58,8 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) case 'i': ips = true; break; case 's': state = true; break; case 'p': pid = true; break; + case 'S': stats = true; break; + case 'H': humanize = false; break; case 't': test_state = arg; break; } return 0; @@ -63,6 +70,8 @@ static const struct option my_longopts[] = { {"ips", no_argument, 0, 'i'}, {"state", no_argument, 0, 's'}, {"pid", no_argument, 0, 'p'}, + {"stats", no_argument, 0, 'S'}, + {"no-humanize", no_argument, 0, 'H'}, {"state-is", required_argument, 0, 't'}, LXC_COMMON_OPTIONS, }; @@ -79,33 +88,177 @@ Options :\n\ -c, --config=KEY show configuration variable KEY from running container\n\ -i, --ips shows the IP addresses\n\ -p, --pid shows the process id of the init container\n\ + -S, --stats shows usage stats\n\ + -H, --no-humanize shows stats as raw numbers, not humanized\n\ -s, --state shows the state of the container\n\ -t, --state-is=STATE test if current state is STATE\n\ returns success if it matches, false otherwise\n", + .name = ".*", .options = my_longopts, .parser = my_parser, .checker = NULL, }; -int main(int argc, char *argv[]) +static void str_c
[lxc-devel] [PATCH] lua: add cmd_get_config_item to API
Signed-off-by: Dwight Engen --- src/lua-lxc/core.c | 25 + src/lua-lxc/lxc.lua | 8 src/lua-lxc/test/apitest.lua | 7 +++ 3 files changed, 40 insertions(+) diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c index ea19cc3..9492c07 100644 --- a/src/lua-lxc/core.c +++ b/src/lua-lxc/core.c @@ -30,6 +30,7 @@ #include #include #include +#include #if LUA_VERSION_NUM < 502 #define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l)) @@ -417,6 +418,29 @@ static int lxc_default_config_path_get(lua_State *L) { return 1; } +static int cmd_get_config_item(lua_State *L) +{ +int arg_cnt = lua_gettop(L); +const char *name = luaL_checkstring(L, 1); +const char *key = luaL_checkstring(L, 2); +const char *lxcpath = NULL; +char *value; + +if (arg_cnt > 2) + lxcpath = luaL_checkstring(L, 3); + +value = lxc_cmd_get_config_item(name, key, lxcpath); +if (!value) + goto not_found; + +lua_pushstring(L, value); +return 1; + +not_found: +lua_pushnil(L); +return 1; +} + /* utility functions */ static int lxc_util_usleep(lua_State *L) { usleep((useconds_t)luaL_checkunsigned(L, 1)); @@ -432,6 +456,7 @@ static int lxc_util_dirname(lua_State *L) { static luaL_Reg lxc_lib_methods[] = { {"version_get",lxc_version_get}, {"default_config_path_get",lxc_default_config_path_get}, +{"cmd_get_config_item",cmd_get_config_item}, {"container_new", container_new}, {"usleep", lxc_util_usleep}, {"dirname",lxc_util_dirname}, diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua index 265e991..44e4bf1 100755 --- a/src/lua-lxc/lxc.lua +++ b/src/lua-lxc/lxc.lua @@ -385,6 +385,14 @@ function M.default_config_path_get() return core.default_config_path_get() end +function M.cmd_get_config_item(name, item, lxcpath) +if (lxcpath) then + return core.cmd_get_config_item(name, item, lxcpath) +else + return core.cmd_get_config_item(name, item) +end +end + lxc_path = core.default_config_path_get() return M diff --git a/src/lua-lxc/test/apitest.lua b/src/lua-lxc/test/apitest.lua index f957ca4..f299b6a 100755 --- a/src/lua-lxc/test/apitest.lua +++ b/src/lua-lxc/test/apitest.lua @@ -217,6 +217,12 @@ function test_container_cgroup() assert(container:set_cgroup_item("memory.limit_in_bytes", "-1")) end +function test_container_cmd() +log(0, "Test get config from running container...") +veth_pair = lxc.cmd_get_config_item(optarg["n"], "lxc.network.0.veth.pair") +log(0, " veth.pair:%s", veth_pair) +end + function test_config_items() log(0, "Test set/clear configuration items...") @@ -325,6 +331,7 @@ test_container_start() test_container_started() test_container_cgroup() +test_container_cmd() test_container_freeze() test_container_frozen() -- 1.8.3.1 -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 1/2] allow lxcapi_get_cgroup_item() on lxc-execute containers
Containers started with lxc-execute may not have a conf, but nothing in the implementation of lxcapi_get_cgroup_item() actually needs/uses it, and it can be useful to get items out of the containers' cgroup items. Signed-off-by: Dwight Engen --- src/lxc/lxccontainer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index ef828dc..89b45ed 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -1977,7 +1977,7 @@ static int lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, c { int ret; - if (!c || !c->lxc_conf) + if (!c) return -1; if (is_stopped(c)) -- 1.8.3.1 -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH] fix leak when a veth.pair name is specified
Signed-off-by: Dwight Engen --- src/lxc/conf.c| 2 ++ src/lxc/confile.c | 14 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 2a47e77..0d1eccd 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3308,6 +3308,8 @@ static void lxc_remove_nic(struct lxc_list *it) free(netdev->link); if (netdev->name) free(netdev->name); + if (netdev->priv.veth_attr.pair) + free(netdev->priv.veth_attr.pair); if (netdev->upscript) free(netdev->upscript); if (netdev->hwaddr) diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 680d260..0e0b7e8 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -453,19 +453,7 @@ static struct lxc_netdev *network_netdev(const char *key, const char *value, static int network_ifname(char **valuep, const char *value) { - if (strlen(value) >= IFNAMSIZ) { - ERROR("interface name '%s' too long (>%d)\n", - value, IFNAMSIZ - 1); - return -1; - } - - *valuep = strdup(value); - if (!*valuep) { - ERROR("failed to dup string '%s'", value); - return -1; - } - - return 0; + return config_string_item_max(valuep, value, IFNAMSIZ); } #ifndef MACVLAN_MODE_PRIVATE -- 1.8.3.1 -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 1/1] resolve lxcpath and rcfile arguments
So we don't always have to give full paths. realpath(x,NULL) mallocs memory, but these paths shouldn't get called from the API so not freeing should be ok. Signed-off-by: Serge Hallyn --- src/lxc/arguments.c | 9 - src/lxc/lxc_execute.c | 10 +++--- src/lxc/lxc_start.c | 9 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/lxc/arguments.c b/src/lxc/arguments.c index adcf8fe..65b2284 100644 --- a/src/lxc/arguments.c +++ b/src/lxc/arguments.c @@ -155,6 +155,7 @@ See the %s man page for further information.\n\n", static int lxc_arguments_lxcpath_add(struct lxc_arguments *args, const char *lxcpath) { + char *resolved_path = NULL; if (args->lxcpath_additional != -1 && args->lxcpath_cnt > args->lxcpath_additional) { fprintf(stderr, "This command only accepts %d -P,--lxcpath arguments\n", @@ -168,7 +169,13 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args, lxc_error(args, "no memory"); return -ENOMEM; } - args->lxcpath[args->lxcpath_cnt++] = lxcpath; + resolved_path = realpath(lxcpath, NULL); + if (!resolved_path) { + perror("realpath"); + fprintf(stderr, "Error resolving lxcpath %s", lxcpath); + return -1; + } + args->lxcpath[args->lxcpath_cnt++] = resolved_path; return 0; } diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c index 6a54bf6..083b5db 100644 --- a/src/lxc/lxc_execute.c +++ b/src/lxc/lxc_execute.c @@ -105,9 +105,13 @@ int main(int argc, char *argv[]) return -1; /* rcfile is specified in the cli option */ - if (my_args.rcfile) - rcfile = (char *)my_args.rcfile; - else { + if (my_args.rcfile) { + rcfile = realpath((char *)my_args.rcfile, NULL); + if (!rcfile) { + SYSERROR("Failed to resolve file path: %s", my_args.rcfile); + return -1; + } + } else { int rc; rc = asprintf(&rcfile, "%s/%s/config", my_args.lxcpath[0], my_args.name); diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c index add2542..7eea26a 100644 --- a/src/lxc/lxc_start.c +++ b/src/lxc/lxc_start.c @@ -173,6 +173,15 @@ int main(int argc, char *argv[]) const char *lxcpath = my_args.lxcpath[0]; + if (my_args.rcfile) { + char *r = realpath(my_args.rcfile, NULL); + if (!r) { + SYSERROR("Failure resolving path: %s", my_args.rcfile); + exit(1); + } + my_args.rcfile = r; + } + /* * rcfile possibilities: * 1. rcfile from random path specified in cli option -- 1.8.1.2 -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH] lua: add cmd_get_config_item to API
On Mon, Nov 04, 2013 at 05:35:07PM -0500, Dwight Engen wrote: > Signed-off-by: Dwight Engen I first got pretty confused between get_config_item and cmd_get_config_item but once I got my brain to parse this all properly, it looks fine :) Acked-by: Stéphane Graber > --- > src/lua-lxc/core.c | 25 + > src/lua-lxc/lxc.lua | 8 > src/lua-lxc/test/apitest.lua | 7 +++ > 3 files changed, 40 insertions(+) > > diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c > index ea19cc3..9492c07 100644 > --- a/src/lua-lxc/core.c > +++ b/src/lua-lxc/core.c > @@ -30,6 +30,7 @@ > #include > #include > #include > +#include > > #if LUA_VERSION_NUM < 502 > #define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l)) > @@ -417,6 +418,29 @@ static int lxc_default_config_path_get(lua_State *L) { > return 1; > } > > +static int cmd_get_config_item(lua_State *L) > +{ > +int arg_cnt = lua_gettop(L); > +const char *name = luaL_checkstring(L, 1); > +const char *key = luaL_checkstring(L, 2); > +const char *lxcpath = NULL; > +char *value; > + > +if (arg_cnt > 2) > + lxcpath = luaL_checkstring(L, 3); > + > +value = lxc_cmd_get_config_item(name, key, lxcpath); > +if (!value) > + goto not_found; > + > +lua_pushstring(L, value); > +return 1; > + > +not_found: > +lua_pushnil(L); > +return 1; > +} > + > /* utility functions */ > static int lxc_util_usleep(lua_State *L) { > usleep((useconds_t)luaL_checkunsigned(L, 1)); > @@ -432,6 +456,7 @@ static int lxc_util_dirname(lua_State *L) { > static luaL_Reg lxc_lib_methods[] = { > {"version_get", lxc_version_get}, > {"default_config_path_get", lxc_default_config_path_get}, > +{"cmd_get_config_item", cmd_get_config_item}, > {"container_new",container_new}, > {"usleep", lxc_util_usleep}, > {"dirname", lxc_util_dirname}, > diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua > index 265e991..44e4bf1 100755 > --- a/src/lua-lxc/lxc.lua > +++ b/src/lua-lxc/lxc.lua > @@ -385,6 +385,14 @@ function M.default_config_path_get() > return core.default_config_path_get() > end > > +function M.cmd_get_config_item(name, item, lxcpath) > +if (lxcpath) then > + return core.cmd_get_config_item(name, item, lxcpath) > +else > + return core.cmd_get_config_item(name, item) > +end > +end > + > lxc_path = core.default_config_path_get() > > return M > diff --git a/src/lua-lxc/test/apitest.lua b/src/lua-lxc/test/apitest.lua > index f957ca4..f299b6a 100755 > --- a/src/lua-lxc/test/apitest.lua > +++ b/src/lua-lxc/test/apitest.lua > @@ -217,6 +217,12 @@ function test_container_cgroup() > assert(container:set_cgroup_item("memory.limit_in_bytes", "-1")) > end > > +function test_container_cmd() > +log(0, "Test get config from running container...") > +veth_pair = lxc.cmd_get_config_item(optarg["n"], > "lxc.network.0.veth.pair") > +log(0, " veth.pair:%s", veth_pair) > +end > + > function test_config_items() > log(0, "Test set/clear configuration items...") > > @@ -325,6 +331,7 @@ test_container_start() > test_container_started() > > test_container_cgroup() > +test_container_cmd() > > test_container_freeze() > test_container_frozen() > -- > 1.8.3.1 > > > -- > November Webinars for C, C++, Fortran Developers > Accelerate application performance with scalable programming models. Explore > techniques for threading, error checking, porting, and tuning. Get the most > from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Stéphane Graber Ubuntu developer http://www.ubuntu.com signature.asc Description: Digital signature -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH 1/2] allow lxcapi_get_cgroup_item() on lxc-execute containers
On Mon, Nov 04, 2013 at 05:35:15PM -0500, Dwight Engen wrote: > Containers started with lxc-execute may not have a conf, but > nothing in the implementation of lxcapi_get_cgroup_item() > actually needs/uses it, and it can be useful to get items out > of the containers' cgroup items. > > Signed-off-by: Dwight Engen Acked-by: Stéphane Graber > --- > src/lxc/lxccontainer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c > index ef828dc..89b45ed 100644 > --- a/src/lxc/lxccontainer.c > +++ b/src/lxc/lxccontainer.c > @@ -1977,7 +1977,7 @@ static int lxcapi_get_cgroup_item(struct lxc_container > *c, const char *subsys, c > { > int ret; > > - if (!c || !c->lxc_conf) > + if (!c) > return -1; > > if (is_stopped(c)) > -- > 1.8.3.1 > > > -- > November Webinars for C, C++, Fortran Developers > Accelerate application performance with scalable programming models. Explore > techniques for threading, error checking, porting, and tuning. Get the most > from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Stéphane Graber Ubuntu developer http://www.ubuntu.com signature.asc Description: Digital signature -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH] fix leak when a veth.pair name is specified
On Mon, Nov 04, 2013 at 05:35:11PM -0500, Dwight Engen wrote: > Signed-off-by: Dwight Engen Acked-by: Stéphane Graber > --- > src/lxc/conf.c| 2 ++ > src/lxc/confile.c | 14 +- > 2 files changed, 3 insertions(+), 13 deletions(-) > > diff --git a/src/lxc/conf.c b/src/lxc/conf.c > index 2a47e77..0d1eccd 100644 > --- a/src/lxc/conf.c > +++ b/src/lxc/conf.c > @@ -3308,6 +3308,8 @@ static void lxc_remove_nic(struct lxc_list *it) > free(netdev->link); > if (netdev->name) > free(netdev->name); > + if (netdev->priv.veth_attr.pair) > + free(netdev->priv.veth_attr.pair); > if (netdev->upscript) > free(netdev->upscript); > if (netdev->hwaddr) > diff --git a/src/lxc/confile.c b/src/lxc/confile.c > index 680d260..0e0b7e8 100644 > --- a/src/lxc/confile.c > +++ b/src/lxc/confile.c > @@ -453,19 +453,7 @@ static struct lxc_netdev *network_netdev(const char > *key, const char *value, > > static int network_ifname(char **valuep, const char *value) > { > - if (strlen(value) >= IFNAMSIZ) { > - ERROR("interface name '%s' too long (>%d)\n", > - value, IFNAMSIZ - 1); > - return -1; > - } > - > - *valuep = strdup(value); > - if (!*valuep) { > - ERROR("failed to dup string '%s'", value); > - return -1; > - } > - > - return 0; > + return config_string_item_max(valuep, value, IFNAMSIZ); > } > > #ifndef MACVLAN_MODE_PRIVATE > -- > 1.8.3.1 > > > -- > November Webinars for C, C++, Fortran Developers > Accelerate application performance with scalable programming models. Explore > techniques for threading, error checking, porting, and tuning. Get the most > from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Stéphane Graber Ubuntu developer http://www.ubuntu.com signature.asc Description: Digital signature -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
Re: [lxc-devel] [PATCH 2/2] add statistics to lxc-info
On Mon, Nov 04, 2013 at 05:35:19PM -0500, Dwight Engen wrote: > - added list_all_containers() which returns both defined and > active containers. > > - allow lxc-info to show more than one container, using regex for the name > Wouldn't it be better to have list_all_containers be similar to list_(active|running)_containers and allow the caller to choose whether it wants to get a list of names or a list of lxc_container? > Signed-off-by: Dwight Engen > --- > doc/lxc-info.sgml.in | 65 - > src/lxc/lxc_info.c | 257 > + > src/lxc/lxccontainer.c | 47 + > src/lxc/lxccontainer.h | 2 + > 4 files changed, 349 insertions(+), 22 deletions(-) > > diff --git a/doc/lxc-info.sgml.in b/doc/lxc-info.sgml.in > index 819d5ca..791d780 100644 > --- a/doc/lxc-info.sgml.in > +++ b/doc/lxc-info.sgml.in > @@ -47,20 +47,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, > Boston, MA 02110-1301 USA > > >lxc-info > - -n name > + -n name >-c KEY >-s >-p >-i >-t state > + -S > + -H > > > > > Description > > - lxc-info queries and shows information about a > - container. > + lxc-info queries and shows information about > + containers. > > > > @@ -70,11 +72,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, > Boston, MA 02110-1301 USA > > > > - -n name > + -n > name > > > > -The container name. > +The container name. It is interpreted as a regular expression, > +so it is possible to get information on all containers, several > +of them or just one. See > + > + regex > + 7 > + for regular expression syntax. If not specified, > +name will default to '.*' which > +will give information on all containers in > +lxcpath. > > > > @@ -126,6 +137,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, > Boston, MA 02110-1301 USA > > > > + -S > + > + > + > +Just print the container's statistics. > +Note that for performance reasons the kernel does not account > +kernel memory use unless a kernel memory limit is set. If a limit > +is not set, lxc-info will display kernel > memory > +use as 0. A limit can be set by specifying > + > +lxc.cgroup.memory.kmem.limit_in_bytes = > number > + > +in your container configuration file, see > + > + lxc.conf > + 5 > +. > + > + > + > + > + > + > + -H > + > + > + > +Print the container's statistics in raw, non-humanized form. The > +default is to print statistics in humanized form. > + > + > + > + > + > + >-t > state > > > @@ -152,6 +198,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, > Boston, MA 02110-1301 USA > > > > +lxc-info -n 'ubuntu.*' > + > + > +Show information for all containers whose name starts with > ubuntu. > + > + > + > + > + > lxc-info -n foo -t RUNNING > > > diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c > index aeaf9a8..a05d610 100644 > --- a/src/lxc/lxc_info.c > +++ b/src/lxc/lxc_info.c > @@ -25,11 +25,14 @@ > #include > #include > #include > +#include > +#include > #include > #include > > #include > #include > +#include > #include > > #include "commands.h" > @@ -38,6 +41,8 @@ > static bool ips; > static bool state; > static bool pid; > +static bool stats; > +static bool humanize = true; > static char *test_state = NULL; > static char **key = NULL; > static int keys = 0; > @@ -53,6 +58,8 @@ static int my_parser(struct lxc_arguments* args, int c, > char* arg) > case 'i': ips = true; break; > case 's': state = true; break; > case 'p': pid = true; break; > + case 'S': stats = true; break; > + case 'H': humanize = false; break; > case 't': test_state = arg; break; > } > return 0; > @@ -63,6 +70,8 @@ static const struct option my_longopts[] = { > {"ips", no_argument, 0, 'i'}, > {"state", no_argument, 0, 's'}, > {"pid", no_argument, 0, 'p'}, > + {"stats", no_argument, 0, 'S'}, > + {"no-humanize", no_argument, 0, 'H'}, > {"state-is", required_argument, 0, 't'}, > LXC_COMMON_OPTIONS, > }; > @@ -79,33 +88,177 @@ Options :\n\ >-c, --config=KEY show configuration variable KEY from running > container\n\ >-i,
Re: [lxc-devel] [PATCH 1/1] resolve lxcpath and rcfile arguments
On Mon, Nov 04, 2013 at 02:44:44PM -0600, Serge Hallyn wrote: > So we don't always have to give full paths. > > realpath(x,NULL) mallocs memory, but these paths shouldn't get called > from the API so not freeing should be ok. > What's the reason behind this change? Am I reading this right that this will only affect cases where -P is passed and that the default value won't be resolved? In any case, I suspect this change is incomplete since we also support -P in some of the python tools which wouldn't be resolved, leading to lxc-info and others to fail to find the container (if for example /var/lib/lxc is a symlink to say /data/containers). > Signed-off-by: Serge Hallyn > --- > src/lxc/arguments.c | 9 - > src/lxc/lxc_execute.c | 10 +++--- > src/lxc/lxc_start.c | 9 + > 3 files changed, 24 insertions(+), 4 deletions(-) > > diff --git a/src/lxc/arguments.c b/src/lxc/arguments.c > index adcf8fe..65b2284 100644 > --- a/src/lxc/arguments.c > +++ b/src/lxc/arguments.c > @@ -155,6 +155,7 @@ See the %s man page for further information.\n\n", > static int lxc_arguments_lxcpath_add(struct lxc_arguments *args, >const char *lxcpath) > { > + char *resolved_path = NULL; > if (args->lxcpath_additional != -1 && > args->lxcpath_cnt > args->lxcpath_additional) { > fprintf(stderr, "This command only accepts %d -P,--lxcpath > arguments\n", > @@ -168,7 +169,13 @@ static int lxc_arguments_lxcpath_add(struct > lxc_arguments *args, > lxc_error(args, "no memory"); > return -ENOMEM; > } > - args->lxcpath[args->lxcpath_cnt++] = lxcpath; > + resolved_path = realpath(lxcpath, NULL); > + if (!resolved_path) { > + perror("realpath"); > + fprintf(stderr, "Error resolving lxcpath %s", lxcpath); > + return -1; > + } > + args->lxcpath[args->lxcpath_cnt++] = resolved_path; > return 0; > } > > diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c > index 6a54bf6..083b5db 100644 > --- a/src/lxc/lxc_execute.c > +++ b/src/lxc/lxc_execute.c > @@ -105,9 +105,13 @@ int main(int argc, char *argv[]) > return -1; > > /* rcfile is specified in the cli option */ > - if (my_args.rcfile) > - rcfile = (char *)my_args.rcfile; > - else { > + if (my_args.rcfile) { > + rcfile = realpath((char *)my_args.rcfile, NULL); > + if (!rcfile) { > + SYSERROR("Failed to resolve file path: %s", > my_args.rcfile); > + return -1; > + } > + } else { > int rc; > > rc = asprintf(&rcfile, "%s/%s/config", my_args.lxcpath[0], > my_args.name); > diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c > index add2542..7eea26a 100644 > --- a/src/lxc/lxc_start.c > +++ b/src/lxc/lxc_start.c > @@ -173,6 +173,15 @@ int main(int argc, char *argv[]) > > const char *lxcpath = my_args.lxcpath[0]; > > + if (my_args.rcfile) { > + char *r = realpath(my_args.rcfile, NULL); > + if (!r) { > + SYSERROR("Failure resolving path: %s", my_args.rcfile); > + exit(1); > + } > + my_args.rcfile = r; > + } > + > /* >* rcfile possibilities: >* 1. rcfile from random path specified in cli option > -- > 1.8.1.2 > > > -- > November Webinars for C, C++, Fortran Developers > Accelerate application performance with scalable programming models. Explore > techniques for threading, error checking, porting, and tuning. Get the most > from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk > ___ > Lxc-devel mailing list > Lxc-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/lxc-devel -- Stéphane Graber Ubuntu developer http://www.ubuntu.com signature.asc Description: Digital signature -- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel