Pass exitCode by reference

Arguments to defer statements are evaluated when the defer statement is
evaluated, so pass exitCode by reference instead.

Fixes issue #346
Remove test code duplication
Fix style issue in remote_exec_test
Also change the call sites. *sigh*
Merge pull request #347 from sorenh/remote_exec_exit_code

agent: Pass exitCode by reference