coverity: Check fstat return value

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
coverity: Check return value of setenv

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
coverity: Check fcntl return value

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
coverity: Don't pass uninitialized var to write

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>