lxc_id_mapping: don't try to write mappings if there are none

Otherwise containers fail to start even if they aren't trying to map
ids.

Also don't allocate buf unless we need to.

Reported-by: Alexander Vladimirov <alexander.idkfa.vladimirov@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>