headers: Big rework

 - every header must not be sensitive in which order it's
   included into the source file

 - in some headers we use tabs aligned members, in some -- not,
   unify it

 - declare routines in headers as external, especially in uapi

 - provide arguments names in header function declarations

Now it's a way simplier to include headers when develop new
C file.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: server -- Make sure the socket is initialized

In case of start listening for commands make sure
the libct_session_export_prepare was called before
and socket is listening.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
docs: libct -- Update UAPI

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libct: check req->create for CT_{CREATE,OPEN}

./src/libctd/libctd -s /var/run/libct.sock
Segmentation fault

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
make: Fix misnamed variable

There is no such variable as PROGRAM, we use LIBCT
instead. It's leftover from early draft.

Reported-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tests: make -- Make explicit test rules

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rpc: move functions for sending responses in a separate file

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rpc: remove send_err_resp

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rpc: set req_id in responses v2

This is required for multithreaded clients. They can send a few requests
simultaneously and then get reponses for each of them.

req_id is copied from a request to a response.
In a future it will be used for asynchronous requests.

v2: push the whole original req into send_resp()
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
local: don't forget about env in local_enter_execve

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
server: handle the env array from a protobuf message

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: make -- Add dep over piggy file

Some tests are using piggy file, thus
add a dependency otherwise make -C test/ run
fails.

 | ./ct_create_exec > ct_create_exec.out
 | make: *** [ct_create_exec.out] Error 1

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

This package can be used for integration with Docker

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
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>