./run: chcon the tmp directory in the builddir.

Not just some random tmp directory which happens to be in the
local directory.

(cherry picked from commit b6cb67d958f5f9ac96b885c8e792beca2d6cac18)
daemon: add and use a reply_with_unavailable_feature macro

Handy macro to reply the right way for an unavailable feature.
While generally used so far in generated code, it can shorten that a
bit, and avoid copy&paste when wanting to do manual feature checking.

(cherry picked from commit f5c74637e36b6c8eb1281f93f7fe26f9016e405c)
rescue: fix sscanf placeholders for --smp and --memsize

Use %d to parse them as int (since the variables for them as int)
instead of %u, even if they both need to be at least > 0; the library
will check for the validity of them anyway.

(cherry picked from commit d1f580550b32e8552ee64f12872b0fa10147957f)
daemon: initialize memory when handling DeviceList params

When dealing with DeviceList parameters, the generator produces code
similar to the following:

  CLEANUP_FREE_STRING_LIST char **devices = NULL;
  [...]
  devices = malloc (sizeof (char *) * (args.devices.devices_len+1));
  {
    size_t i;
    for (i = 0; i < args.devices.devices_len; ++i)
      RESOLVE_DEVICE (args.devices.devices_val[i], devices[i],
                      , goto done);
    devices[i] = NULL;
  }

The block hidden within the RESOLVE_DEVICE macro is supposed to
assign something to devices[i]; on the other hand, the code in
RESOLVE_DEVICE can cause to just end (with an error) the current RPC,
which would cause the cleanup of the "devices" array... whose members
from the i-th to the (args.devices.devices_len-1)-th would be garbage
pointers, causing random memory to be free'd (and thus crashing the
daemon).

Avoid the access to garbage memory just by having a cleaned "devices"
array, so there will be always a NULL element after the initialized
members.

Add a test for vgcreate which passes a wrong device path causing the
situation above, to test that vgcreate would fail gracefully.

(cherry picked from commit 8d23fb31f11019b7b8c4834166748143cec84c0c)
tests: c-api: do not crash w/ missing hash entry

If an hash does not have the requested key, just error out cleanly
instead of crashing when trying to compare a null string.

(cherry picked from commit fef0881b3a31adebf66e0374fed3eb41f9d1471d)
daemon: blkid: fix memory issues in "no -p/-i" mode

Fix the memory issues in the implementation that uses no -p nor -i:
- use add_string_nodup to add results from get_blkid_tag (which returns
  new strings), so those strings are not leaked
- use free_stringslen to clean the hash on error, as in such case the
  stringbuf will not be terminated with a null entry, thus causing
  free_strings to crash

(cherry picked from commit ad4ba5997be030ee4b67614d9e6004107482bbc3)
daemon: add CLEANUP_CLOSE

Just call close on the specified fd, if valid.

(cherry picked from commit 4249ddd8bbd0d38f7e63890b999c6199b54af5b3)
daemon: use CLEANUP_CLOSE

(cherry picked from commit bb124552155667c082c075cb09267b12a7a567c1)
df: unlock retire_mutex on early exit

If pthread_cond_wait fails and the thread worker ends, make sure to
unlock retire_mutex, which has been locked for the condition.

The return value of pthread_mutex_unlock is ignored, as there's nothing
that can be done with it at that point.

(cherry picked from commit a26a9e68819dab5f9c8eed821d8a686fffabbc5b)
python: fix possible free on uninit memory with OStringList optargs

When using optional arguments of type OStringList, the code free'ing
the member in the optargs_s struct corresponding to that optional
argument would just check for a non-PyNone PyObject for that argument.
If before that optional argument there are other arguments which can
cause an earlier error return from that binding function, the free'ing
code will then act on garbage values.

Enhance the check by also checking whether the optargs struct has the
bitmask with the element for that argument, meaning that the
corresponding struct member was initialized.

(cherry picked from commit 841b20c39cfd53bd7097d2e3f81fd36f8135cc75)
lib: Typo in comment.

(cherry picked from commit 34feb37879ea3d3a9adbb5de5baa62882f7c6a9d)
builder: Missing include of <locale.h>.

Required by setlocale.  For some reason you only see the error
when compiling with -O0.

(cherry picked from commit 6a51ae503c372b2548c91639e8c23c8bbeac3c44)
lib: Missing include of <locale.h>.

Required by setlocale.  For some reason you only see the error
when compiling with -O0.

(cherry picked from commit 8a23c1d79e878599a17c70bfc0737159acd5b61d)
appliance: update distros in comments

Update the list of recognized names of distributions in the comments.

No functional changes.

(cherry picked from commit d9a4c481c940e0c83b8133ce21225c3820a40c28)
appliance: add libc-bin to Debian's packagelist

It provides libc binaries like ldconfig and its configuration.

(cherry picked from commit c21176386080029d285ffdf672e293c62e986640)
launch: direct: Only issue Debian /dev/kvm group warning if /dev/kvm wasn't openable (RHBZ#1130189).

This warning was meant for the case where /dev/kvm is inaccessible and
the user must add themselves to a special group.

However we didn't take into account whether /dev/kvm was openable in
this test.  If it's openable, no point issuing the warning.

Move the is_openable ("/dev/kvm") test earlier, and don't issue the
warning if that was successful.

(cherry picked from commit 9609521734c661ec70c34a68f6201a2601190fa6)
configure: add java-8-openjdk and java-7-openjdk as locations for java

This helps some distros (e.g. Archlinux) where openjdk is installed in
java-MAJOR-openjdk directories, without any "default version" symlink.

(cherry picked from commit 1d9388b80066529f58b873bc601eab92ebd3c8a6)
configure: look for "java-default-runtime" as directory for Java

This seems to be the new way [1] in Archlinux to specify, as symlink,
the default version of Java.

Thanks to Peter Wu for the notice about it.

[1] https://wiki.archlinux.org/index.php/Java

(cherry picked from commit ddfe82e823ff1112e4f75436ece439adc34b2ac9)
utils: Add new CLEANUP_PCLOSE cleanup.  It calls pclose(3).

(cherry picked from commit 9fa9d39d71af63fe96a95ea5668c14b73555c348)
appliance: add mtools to Archlinux' packagelist

It is an optional dependency but syslinux uses it, so pull it always in
the appliance.

(cherry picked from commit df88e30ff1af1dd70a80e12991c5a40ffe611189)