On 05/07/2011 01:53 AM, Francois-Xavier Bourlet wrote:
ok thanks for all the information and example.I believe that rather than trying to iterate over every containers running or not and trying to merge the result we could simply iterate only on running container, or only stopped container (I simplify). So lxc_for_each could simply take a state in parameter, in case we are looking for running containers we only have to look in /proc/net/unix else browsing LXCPATH. But then what about state like booting/stopping etc? Is booting/stopping are "running" in some way? Maybe rather than passing a state to lxc_for_each we can imagine a boolean parameter with the notion of *active* *inactive*, or something with a better name to introduce the fact we are looking for "running" container or simply registered ones? I have to run really ofter lxc_for_each, and adding complexity (and so slowing down the function) is a big concern for me. I dont need a full list of every containers in every state, but only whats is actually present in the cgroup filesystem and what is registered. I would prefer to let the user (the developer using lxc_for_each) decide and implement itself the appropriate complexity.
Ok, as the name of 'volatile' container is already presented in the man page, we can add this boolean to lxc_for_each and let the caller of this function to handle the duplicate names.
In attachment the routine to look for containers in /proc/net/unix and not in LXCPATH/<name>.
So when 'volatile' is set, this routine should be called otherwise the other one I sent in a previous email.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/param.h> #define LXCPATH "/var/lib/lxc" static int is_volatile(const char *name) { char *path; int ret; if (asprintf(&path, LXCPATH "/%s", name) < 0) return -1; ret = access(path, F_OK); free(path); return !!ret; } int main(int argc, char *argv[]) { const char *file = "/proc/net/unix"; const char *format = "%*lx: %*x %*x %*d %*d %*d %*d @" LXCPATH "/%s"; char buffer[MAXPATHLEN]; FILE *f; int ret; f = fopen(file, "r"); if (!f) { perror("fopen '%s' failed"); return -1; } for (ret = fscanf(f, "%*[^\n]"); ret != EOF; ret = fscanf(f, format, buffer)) { char *aux; if (!ret) { ret = fscanf(f, "%*[^\n]"); continue; } aux = strchr(buffer, '/'); *aux = '\0'; printf("%s : [%sregistered]\n", buffer, is_volatile(buffer) ? "not " : ""); } fclose(f); return 0; }
------------------------------------------------------------------------------ WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel