Rewrite of cgroup locking

There was already cgroup locking in the version 14.03 code base
using different variable names and slighly different logic from
that in commit 3f6d9e3670cd931d987cb65e53e2cfbb4c153eb5.
This commit is a variant of that commit in order to make the logic
in version 2.6 match that of our next release (logic which is
already pretty well tested).
bug 447