OSv Init: http client

The http client is loosely based on the boost http client example.
The original example can be found here:
http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp03/http/client/sync_client.cpp

The client class redirect its output to an output stream so if the c is
a client the following can be done:
std::cout << c;

The client is used to retrieve init files from a remote server. It can
be replaced by a library client if need arises.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: the osvinit class

The osvinit object uses command from a yaml parser to either call an API
command or to perform internal command.
The supported options are:
Each command contains: GET, PUT, POST or DELETE with a url of the
command. Path parameters comes as part of the url.
Query parameteres follow as a yaml parameters.

The osvinit can be set to stop on errors or ignore them.

When opening the api, the osv init creates a new thread for that, it
would wait for that thread to terminate.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: the main

The main starts an osvinit task. It should get in the command line
either a file name or a server name and path on the server as the init
file.

It uses a parser for passing the configuration to the osvinit

It call the osvinit wait, it would return imidiatialy if the httpserver
was not run.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: A basic configuration file

The default configuration file is empty. When the osvinit will be in use
it should replace the httpserver and the osvinit would start the api
server when the configuration is done.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: Makefile

Adding the make file. It create the osvinit.so for use with the image
and the osvinit for standalon testing.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSv Init: add the module.py

Package the yaml-cpp lib, the osvinit.so and the osvinit.yaml init file.
By default the osvinit will not be started, but the httpserver will.

To change that, the starting line can be uncommentted or the osvinit can
be started with a -e directly.

The osvinit and httpserver should not be both started.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>

module.py need merge
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
OSvInit: add directory of the yaml-cpp library

Add the directory of the yaml-cpp library to the path

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mgmt: compile osvinit after httpserver

Explicitly specify to the build system that the osvinit module needs
to be compiled after the httpserver module. Otherwise, we may randomly
get opposite order, and the compilation will fail.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
osvinit: fix compilation error

handle() returns void now.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
osvinit: express compilation-time dependency on httpserver with require()

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
osvinit: update location of httpserver module

This fixes 'make' in osv.git

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add ncurses module

A requirement for libedit, which is required by the cli.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add libedit module

Required by the cli.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add lua module

Required by cli. Downloads and builds Lua 5.2.

Lua's original Makefile comes without a target to create a shared-object.
For this, this build extract the sources to `src/` which contains a Makefile
that creates the shared-object.

Also adds the following modules:

* LuaSocket
* LPeg
* LuaJSON

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add cli module code

cli.c embeds Lua as the engine of the CLI. It makes it dynamic and scriptable.
The added benefit is that Lua maintains its own state, which enables us to
treat it as a single entity that can be reset when needed.

The cli takes a command with libedit and passes it to cli() in cli.lua. If an
error occures (assert() or error()), it is being taken care of with a proper
message.

Some utilities are available, like table/column printing (see table_print())
and getopt_long()-like method (see echo commands for usage example).

It is possible to use this cli locally (outside OSv), but you need to build
its dependencies first: modules/{ncurses,libedit,lua}.

Commands are placed under commands/ folder.
More documentation is placed under docs/, currently.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Build code for cli module

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Some documents created while working on the CLI

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mmu: file-mapped vma flag

Add flag bit to mark if a vma region is file mapped or not + add gdb
script to query individual vma entry.

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: snprintf for "infinite" lengths

Fixes #111.

The standard C snprintf() has an interesting design flaw: snprintf()
takes a "size_t" length, and returns an "int". Unfortunately, size_t
is 64-bit while int is 32-bit, so it is theoretically possible for
snprintf() to succeed writing over 4 gigabytes, and not be able to return
the actual size it wrote!
This is why Posix mandates that when snprintf() is given a length that
cannot fit in 32 bits, it must immediately fail and set errno=EOVERFLOW.
Our implementation, copied from Musl, did this.

However, it turns out that neither glibc nor gcc's builtin snprintf
goes along with this decision, as the test in this patch demonstrates.
We can snprintf with maximum lengths = 2^64-1 or 2^40, and it works well.
This patch tests that we do this like Linux (the test can be run on both
OSv and Linux), and removes the EOVERFLOW case to be more like Linux.

Interestingly, this issue caused bug #111. With -D_FORTIFY_SOURCE=2,
ncurses's use of sprintf() was converted to __sprintf_chk() with a "len"
of -1 (2^64-1). Our implementation of this function called snprintf()
with that len - and failed because our implementation refused to work
when given len=-1.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add __longjmp_chk()

When compiled with -D_FORTIFY_SOURCE=1 (this is the default in Ubuntu),
a program that uses longjmp() can end up calling __longjmp_chk() instead.
This patch adds a trivial implementation of this missing function.

Ideally, __longjmp_chk() should do some sanity checks on the "env" we're
jumping to, namely that it actually points to a stack frame earlier on
our stack. This patch is functionally-correct, but includes no such checks.
Glibc does some checks, but they are also far from being bulletproof (they
do little more than checking the env address is higher than the current
stack pointer).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>