agent: Close fds before spawning agent for security reasons

Don't leak fds into the agent child process after dropping
privileges.

Fixes #506