Reduce nesting in sysv ipc code.

Split out so that the "real patch(es)" for #554 make more sense.