Put the logic to decide which synchronous standby is active into a function.

This avoids duplicating the code.

Michael Paquier, reviewed by Simon Riggs and me