locking.c: Refactor the main locking flow.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 24 Apr 2016 22:30:30 +0000 (23:30 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 29 Apr 2016 00:16:23 +0000 (01:16 +0100)
commitb7ec4e9118fa390ec20408390a06f3c51a035155
treefa6548566f08e41b9392a7634e42f32b170dca18
parent0f4f1fb606d18e2c2e157f008e0dc7e4a03683d5
locking.c: Refactor the main locking flow.

  * Calculate the open(2) flags ahead of time.

  * Move the open(2) until after we set up the alarm.  This means that
    we might not actually set `fd' at all, if we get delayed and the
    alarm goes off.

  * Use a separate static (because setjmp(3)) variable to record the
    fcntl(2) return code.

  * Use `goto' and labels for the control flow, rather than having
    everything in an `else' branch.

  * Use `switch' to pick the results of fcntl(2) apart.
locking.c