]> git.ipfire.org Git - thirdparty/lxc.git/commit
Eliminate duplicate entries from list_active_containers (v2)
authorS.Çağlar Onur <caglar@10ur.org>
Thu, 24 Oct 2013 04:02:37 +0000 (00:02 -0400)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 25 Oct 2013 21:15:21 +0000 (16:15 -0500)
commit9c88ff1f95eea1e1b2c06c22fcc09c5cb94bd270
tree2b367dca372c2fa1974107cfaf0ecc0210013c98
parent44f820e30b6fab2094dff1269a137983208b3b6d
Eliminate duplicate entries from list_active_containers (v2)

list_active_containers parses /proc/net/unix which can contain multiple entries for the same container;

000000000000000000000002 00000000 00010000 0001 01 273672 @/var/lib/lxc/6/command
000000000000000000000002 00000000 00010000 0001 01 274395 @/var/lib/lxc/5/command
000000000000000000000002 00000000 00010000 0001 01 273890 @/var/lib/lxc/4/command
000000000000000000000002 00000000 00010000 0001 01 273141 @/var/lib/lxc/3/command
000000000000000000000002 00000000 00010000 0001 01 273915 @/var/lib/lxc/2/command
000000000000000000000002 00000000 00010000 0001 01 273683 @/var/lib/lxc/1/command
000000000000000000000002 00000000 00010000 0001 01 273074 @/var/lib/lxc/0/command
000000000000000000000002 00000000 00010000 0001 01 273931 @/var/lib/lxc/9/command
000000000000000000000002 00000000 00010000 0001 01 273110 @/var/lib/lxc/8/command
000000000000000000000002 00000000 00010000 0001 01 273390 @/var/lib/lxc/7/command
000000000000000000000003 00000000 00000000 0001 03 275903 @/var/lib/lxc/8/command
000000000000000000000003 00000000 00000000 0001 03 276043 @/var/lib/lxc/1/command
000000000000000000000003 00000000 00000000 0001 03 273301 @/var/lib/lxc/0/command
000000000000000000000003 00000000 00000000 0001 03 275650 @/var/lib/lxc/4/command

On this system list_active_containers returns 14 containers while only 10 containers are running.

Following patch;

* Introduces array_contains function to do a binary search on given array,
* Starts to sort arrays inside the add_to_clist and add_to_names functions,
* Consumes array_contains in list_active_containers to eliminate duplicates,
* Replaces the linear search code in lxcapi_get_interfaces with the new function.

Changes since v1:
* Do not load containers if a if a container list is not passed in
* Fix possible memory leaks in lxcapi_get_ips and lxcapi_get_interfaces if realloc fails

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxccontainer.c