libct: local_enter_execve should call local_enter_cb

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: add -Wno-unused-result

It's enabled on Ubuntu by default.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
cgroups: Don't forget to remove created dir on fail

If we fail to bind mount the directory we've created
a few lines earlier -- don't forget to remove it then.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
server: keep track states of containers (v2)

The daemon polls signalfd and when it gets SIGCHLD, a state of a proper
container is update.

v2: call waitid with WNOWAIT

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: add support of asynchronous requests (v3)

The ibct server has a limmitted number of threads (currently it has
only one), so the command can't block for a long time.

Now let's look at the ct->wait(). This operation are not going to
complete immediately. This patch adds interface for asynchronous
requests, which allows to handle long requests like ct->wait().

v2: don't forget to set cb_destroy()
v3: include async.h in src/session.c
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
server: don't block in ct->wait

ct->wait() will be done asynchronously. A client request is postponed
and it will be completed when the container will stop.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rpc: prepare to receive packets with file descriptors

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rpc: receive packets with file descriptors

It will be used to set file descriptors for executing processes.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
exec: add ability to set file descriptors for stdin, stdout, stderr (v2)

v2: add separate functions, which take file descriptor array

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: typo fix s/responce/response/

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
go: Fix /responce/response/ change

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: set SOCK_CLOEXEC on sockets

We want to be sure, that children will not inherit these sockets.

Probably we need to think which file descriptors should be closed
in spawn_cb and enter_cb.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
go: reports errors from requests

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
go: handle interrupted connections

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
go: There's no /home/avagin/ on generic host

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
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>