go: formatting Go code with gofmt

fix code according with coding style

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: reformat code in serve_spawn()

Remove extra indent by using goto for handling error path.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: split serve_spawn function

because the part for extracting arguments will be used in serve_enter.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: correct handling of arguments and environments from protobuf messages

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
add python bindings

Here are python bindings for libct functions. There are
two modules, one, libctcapi, provides all libct functions
as is and shouldn't be used. Second - high-level API with
classes.

Example of usage:

import libct

def test(arg):
        print arg
        return 1

s = libct.open("local")
ct = s.container_create('qwe')
ct.spawn_cb(test, "testtesttest")
print ct.wait()
ct.destroy()
s.close()

Second example:

import libct

s = libct.open("unix:///var/run/libct.sock")
ct = s.container_create('qwe')
ct.set_root("/mnt")
ct.set_nsmask(libct.consts.CLONE_NEWIPC |
                libct.consts.CLONE_NEWNET |
                libct.consts.CLONE_NEWNS |
                libct.consts.CLONE_NEWUTS |
                libct.consts.CLONE_NEWPID)

ct.controller_add(libct.consts.CTL_CPU)
ct.spawn_execv("/sbin/init", ['/sbin/init', '3'])
print ct.wait()
ct.destroy()
s.close()

Drawbacks:
1. libctmod.c contains a lot of duplicated code, usually people
make some autogenerators for making such bindings for C-functions,
so it will be good to write such script.

2. We should store error descriptions in some single place, because
they needed in python bindings to provide clear exceptions.

3. libct_container_set_option is not implemented, we need to add
second version of this function with va_list argument.

4. All python functions and classes usually have documentation in
form of docstrings, so it should be written later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
unblock all signals before execve'ing process

Child process inherits blocked signals mask, so we
must clear it before executing a child. Now signal SIGCHLD
is blocked in libct_session_export.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
remove libctd and rpc client

Changes in v3:
	* fix grammar error in documentation

Changes in v2:
        * remove libctd tests
        * fix Documentation
        * remove go rpc client

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tests: fix Makefile after removing libctd

Signed-off: Dmitry Guryanov <dguryanov@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: s/execv/execvp

execvp searches for an executable file in the PATH list, if the
specified filename does not contain a slash (/) character.

I was writing a test for go bindings and understand that I can't
to call echo by path, because it depends on a distributive.

Fedora:
[avagin@localhost ~]$ type -P echo
/usr/bin/echo

Ubuntu:
avagin@ubuntu:~$ type -P echo
/bin/echo

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
py: add wrappers for libct_container_spawn_execv*fds

Add wrappers for functions libct_container_spawn_execv*fds.
You should use Container.spawn_execvfds and
Container.spawn_execvefds:

ct.spawn_execvfds("/bin/bash", ['/bin/bash'], [0, 1, 2])

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
return different errors from functions returning pointers

Now functions, which return pointers return NULL in case
of error. It's not very convenient, because it's better
to provide error reason. So introduce 3 new API calls:

void *libct_err_to_handle(long err);
long libct_handle_to_err(void *handle);
int libct_handle_is_err(void *handle);

Which handle error codes in pointers.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
py: fix error handling

Fix error handling in python wrappers because of changing
In C functions return values in functions

libct_session_open
libct_session_open_local
libct_container_create
libct_container_open

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: start CT in a new session by default (v2)

v2: add a NOSETSID option in uapi/libct.h

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: set console (v2)

A console is set as controll terminal for the init in CT.

v2: add a wrapper in the C library
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: Use ERR_ helpers instead of duplicating code

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: Require error codes to be explicitly signed if needed

Same as kernel does -- error constants are positive values
but signed when needed. This allows to unify all the code
where constant -1 is mixed with LCTERR_ codes.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: add initial go bindings

This patch is a prototype. I'm going to implement all other functions,
when all of you will say that it's what we want.

Cc: Michael Crosby <crosbymichael@gmail.com>
Cc: Dmitry Guryanov <dguryanov@parallels.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
test: check that CT is executed in a new session (v3)

with own control terminal.

v2: don't wait pid from libct_container_spawn_execvfds
v3: s/libct_container_set_console/libct_container_set_console_fd

Signed-off-by: Andrey Vagin <avagin@openvz.org>