Fix fd leak in lxc log

lxc_log_init will leak an fd when it is called by a long running
program that may call lxc_container_new multiple times. Fix by
only opening the log if it is not already open.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Fix use of list item memory after free

Valgrind showed use of ->next field after item has been free()ed.
Introduce a lxc_list_for_each_safe() which allows traversal of a list
when the body of the loop may remove the currently iterated item.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Free allocated configuration memory

Most of these were found with valgrind by repeatedly doing lxc_container_new
followed by lxc_container_put. Also free memory when config items are
re-parsed, as happens when lxcapi_set_config_item() is called. Refactored
path type config items to use a common underlying routine.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Ensure argv passed by createl to create is NULL terminated

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
lxc-info: add option -t, --state-is=STATE to test for a given test

Add an option to test for a give state. This is useful for scripts.
It lets us you do thing like:

 if lxc-info --name myname --state-is RUNNING; then
   ...

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
fix lxc-ubuntu-cloud option parsing bugs

The -u shortopt matching --userdata was not specified, and when -L
is found shift should have been by 1 not 2 since there is no optarg.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
lxc-version: use POSIX shell instead of bash

There is no reason to depend on bash for a single echo.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
lxc-checkconfig: use POSIX shell instead of bash

- replace 'echo -e' with printf
- replace 'if [[ ... ]]' with 'if [ ... ]'
- add \ at after && and || when those are at end of line

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Use autoconf LXCPATH instead of hardcoded LXCDIR

LXCDIR is only used in lxc_container_new, whereas LXCPATH is used throughout
the rest of lxc, and even in the same file as lxc_container_new (for example
create_container_dir()).

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
lxc-setcap: use POSIX shell instead of bash

Avoid getopt --longoptions

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
lxc-setuid: use POSIX shell instead of bash

Avoid getop --longoptions.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Make config api items const

This makes it easier to write a binding, and presents a cleaner API. Use
strdupa in a few places to get mutable strings for tokenizing / parsing.
Also change the argv type in lxcapi_start and lxcapi_create to match
that of execv(3).

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Oracle template: make container also boot under libvirt

This allows containers created with lxc-create to also boot under
libvirt/Virtual Machine Monitor

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
revert inadvertent un-doing of lxc-clone fix

commit 8f2c3a702aae3545b631a2b4c6db99f87528553a reverted a fix
for bad handling by lxc-clone of 'lxc.mount[ \t]' lines.
Fix.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Rewrite lxc-ls in python

This rewrite is mostly compatible with the shell version.
--active and -1 still work and behave as they used to.

This adds --running, --stopped and --frozen as state filters.

A new "fancy" view is also implemented (can be used with --fancy) and
will show containers in a column-based interface with the following fields:
 - name
 - state
 - ipv4
 - ipv6
 - pid of init

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>