gen_init_cpio: avoid NULL pointer dereference and rework env expanding