libc: make dlopen() return main program for empty file name

This is not a documented behavior but glibc's dlopen behaves this way.

Spotted when debugging assertion failure when java is started with a
debugger, we try to read elf header from "/" on dlopen("", ...):

Assertion failed: data.uio_resid == 0 (osv/fs/fs.cc: read: 27)

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: add tests for dlopen()

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
imgedit: fix potential deadlock between qemu and nbd_file.__init__

Found during code inspection.

Qemu process is started with stdout=PIPE but the pipe will not be read
until _process.communicate() is called and it is called when nbd_file
is closed. So if the pipe buffer fills up we may have a deadlock. Qemu
will be blocked on stdout.write() and imgedit.py will be waiting for
it to open a socket.

Solution here is to redirect to /dev/null as this has the same
effect as current code.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
imgedit: simplify the loop

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
imgedit: fix hang in case qemu terminates before nbd client connects

To make it work self._closed needs to be initialized early because
even though exception is thrown from __init__(), __exit__() still will
be called and that one expects self._closed to be defined.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
imgedit: fail if qemu exits with non-zero code

It's a good practice to propagate failures so that make does not
succeed if something goes wrong.

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