Improve locking for pkg-upgrade.
Improve locking for pkg-upgrade.

Reported by: Eugene Grossbein

junovitch/pkg,khorben/pkg,skoef/pkg,khorben/pkg,Open343/pkg,en90/pkg,skoef/pkg,en90/pkg,Open343/pkg,khorben/pkg,junovitch/pkg