Package: dpkg Version: 1.20.9 Apt somewhat recently added the ability for an invocation of apt to wait until the db lock which was held by another apt instance is released[1]. It would be nice to have similar functionality in dpkg. I propose two solutions.
The simplest and least work, is to return an error code indicating that a dpkg exited due to a lock already being held (exit code 3 is the next available). This allows scripts to know that dpkg failed due to a held lock and can then do its own retry logic. Currently the returned error doesn't allow the caller to determine that the failure was due to a held lock (yes, output could be parsed, but that's a big hack). The second solution is to add an option, perhaps -w and --wait <nsec>, which tells dpkg to wait a specified amount of time to the lock to be released. If the timeout is exceeded the exit code should be unique to a failure due to a held lock, as in the first solution. Otherwise, dpkg should try to grab the lock and perform the requested action. Glenn [1] https://salsa.debian.org/apt-team/apt/-/merge_requests/109/diffs