nbd-server: read conf on SIGHUP and add new exports

This patch makes the root server process re-read its configuration files
and add new exports dynamically when SIGHUP is sent. The rehash feature
is non-destructive: it does not modify any existing exports, it only
lets the root server process to add new exports. However, it might be a
good idea to implement destructive counterparts (export deletion and
modification) too at some point.

Signed-off-by: Tuomas Räsänen <tuomasjjrasanen@tjjr.fi>
[change usage of __attribute__((unused)) into G_GNUC_UNUSED]
Signed-off-by: Wouter Verhelst <w@uter.be>
nbd-server: prefer assertions over if-then-exits

Assertions imply programming invariants which must be fulfilled,
otherwise there is a programming error.

Regarding this commit, it's a programming error to pass NULL to
append_serve(). And now it's explicitly stated with the assert(3)
statement.

If-then-exit -constructs could be interpreted as a valid and
semantically meaningful code: "it's a feature of append_serve() to
exit the process if NULL is passed", which does not make any sense. On
the other hand, assert(s != NULL) makes it very clear that NULL must
not be passed, or the contract will be terminated along with the
process.

This commit is part of the desensitization treatment for author's
assertion allergy.

Signed-off-by: Tuomas Räsänen <tuomasjjrasanen@tjjr.fi>
Signed-off-by: Wouter Verhelst <w@uter.be>
Ensure we don't bring the '-l fucks up nbd-server' bug again, by adding it to the test suite
Add a template to mktemp invocation

Not all mktemp implementations (e.g., the FreeBSD one) have an implicit
template. Add one explicitly so things will work properly again.
Use $TMPDIR rather than hardcoding for /tmp
Use the correct error handling routine
Be more portable

Using the leading - is a GNU extension (but not documented as such), which
 doesn't work on FreeBSD. Use the more portable way to do the same thing.
Clean up in all cases

Since we use 'set -e', there are plenty of cases where the cleanup code isn't called.
Use 'trap' to ensure that it does.
More portability fixes

It still doesn't work on FreeBSD, but I just ran out of time
Add todo item so we don't forget to fix this later
Revert "Be more portable"

This reverts commit 77ee0f392eaf292f2c0d350fa5c640253d2132d7.

It doesn't work on FreeBSD, and it doesn't work on Linux. Oops.
Handle portability better.

Yesterday's attempt was somewhat shortsighted. This one should actually
work.

We avoid the ugliness of having to do the same thing twice somewhat by
putting it in a separate function -- this is still ugly to some extent,
but at least it doesn't copy code around more than just for the function
name.
Open as many modern sockets as needed

Some systems need us to have a socket per address family (e.g.,
FreeBSD); others need us to have just one (e.g., Linux). Handle both
cases.
Don't attempt to free a NULL pointer.
Don't try to check whether invalid sockets are readable

this caused SIGBUS on FreeBSD
Fix ordering

FreeBSD wants non-option arguments to appear after option arguments
Improve signal handling

Setting SIGCHLD to SIG_DFL doesn't cut it; we need to ctually ignore
them with sigprocmask. In addition, we need to deal with more than
SIGCHLD.

Initial patch by Paul Clements.
Remove long-outdated conditional code
Prepare for 3.3
Distribute these files, too