Check return value of chmod(2)

Reported by:	coverity
Avoid close(-1) when accept(2) returns -1

Reported by:	coverity
Avoid ucl_iterate_object(NULL)

Reported by:	coverity
Fix fd leak if posix_spawn(3) fails

Reported by:	coverity
Fix permission checking for commands by checking the actual value iterated

Reported by:	coverity!