Add error checking to chmod() in manage_agents