Change pbs_geterrmsg() so that it returns a pointer to a duplicated string instead of a pointer to the string. This string is mutex protected so having an unprotected pointer to it means there is a risk of a crash.
TRQ-2046. Refactor the send_job_work() function to make it easier to follow and unit testable. Also, add unit tests for the refactored code.