Document what ret=2 is
Fix cleaning race when skipping ports

Fix this by only removing this package from other package's dependencies
after recursively skipping packages depending on this package. This ensures
that packages depending on this package retain a >0 count of needed
packages while recursively cleaning. Otherwise another clean.sh process
for a successful package may remove itself from its dependencies and then find
that some of them are empty, despite those dependencies about to be recursively
cleaned up and skipped.

This would result in ports being built without their dependencies having been
built, showing the following error:

    ===>   USE_PACKAGE_DEPENDS_ONLY set - not building missing dependency from source

Further explanation:

  Given these deps:
     /deps/dep_a
     /deps/dep_b
     /deps/leaf_a/dep_a
     /deps/leaf_a/dep_b

  1. dep_a fails and dep_b succeeds at the same time
  2. dep_a fails and cleans its reference from /deps/leaf_a
     via find /rdeps/dep_a|realpath|rm -f
  2. At the same time, dep_b finishes building and also
     removes itself from /deps/leaf_a via find|realpath|rm
     [ This leaves /deps/leaf_a empty ]
  3. dep_a cleaning recurses into leaf_a to skip it because
     dep_a has failed and leaf_a is not buildable now.
  3. dep_b falls through and checks all of its deps for empty
     dirs as they are now eligible for building. Because
     /deps/leaf_a is now empty, it moves it to /pool/
  4. dep_a's recursive call to skip leaf_a generates (hidden)
     warnings and finally tries to remove /deps/leaf_a so it
     is skipped
  5. leaf_a resides in /pool despite having dep_a failed

MFH
Add comment in clean.sh

MFH
Avoid racing when recursively cleaning up rdeps

This prevents multiple clean.sh processes from cleaning the same
package's reverse dependencies. This was mostly harmless before.

Now have clean.sh exclusively claim the rdep dir by moving it to
/cleaning/rdeps/<pkgname>. If the atomic mv fails, ignore it and
assume another process is currently cleaning it already.

MFH
Avoid rare race leading to incorrectly not skipping ports in some cases

This could occur when deleting the /deps dir, which was non-empty. For a brief
moment the dir would become empty after removing all entries. Another clean.sh
process would see the empty dir and consider it as ready-to-build. This would
result in ports being built without their dependencies having been built
showing the following error:

    ===>   USE_PACKAGE_DEPENDS_ONLY set - not building missing dependency from source

Race details (Before recent refactoring):

    Given these deps:
       /deps/dep_a
       /deps/dep_b
       /deps/dep_c
       /deps/leaf_a/dep_a
       /deps/leaf_a/dep_b
       /deps/leaf_a/dep_c

    1. dep_a fails and dep_b succeeds at the same time
    2. dep_a fails and cleans its reference from /deps/leaf_a
       via find /rdeps/dep_a|realpath|rm -f
    2. At the same time, dep_b finishes building and also
       removes itself from /deps/leaf_a via find|realpath|rm
       [ This leaves /deps/leaf_a/dep_c - leaf_a is not
         satisfied to build ]
    3. dep_a cleaning recurses into leaf_a to skip it because
       dep_a has failed and leaf_a is not buildable now. It
       calls rm -rf /deps/leaf_a so it is skipped.
       [ This is non-atomic and leaves /deps/leaf_a empty for
         a brief moment ]
    3. dep_b falls through and checks all of its rdeps for empty
       dirs as they are now eligible for building. Because
       /deps/leaf_a is briefly empty, it moves it to /pool/
    4. dep_a's rm -rf /deps/leaf_a call to unlink leaf_a generates
       (hidden) warnings
    5. leaf_a resides in /pool despite missing dep_c and having
       dep_a failed

Race details (As of this commit):

    Given these deps:
       /deps/dep_a
       /deps/dep_b
       /deps/dep_c
       /deps/leaf_a/dep_a
       /deps/leaf_a/dep_b
       /deps/leaf_a/dep_c

    1. dep_a fails and dep_b succeeds at the same time
    2. dep_a recurses into leaf_a to skip it because
       dep_a has failed and leaf_a is not buildable now. It
       calls rm -rf /deps/leaf_a so it is skipped. [ This briefly
       leaves /deps/leaf_a empty after all entries are deleted. ]
    2. dep_b searches everything depending on it for now empty
       dirs, incorrectly finds leaf_a and moves it to /pool/.
    3. dep_a's rm -rf /deps/leaf_a call to unlink leaf_a generates
       (hidden) warnings
    4. leaf_a resides in /pool despite missing dep_c and having
       dep_a failed

This is fixed by atomically removing the /deps/<pkgname> dir and avoiding
a briefly empty dir that another process may see.

MFH
clean.sh: Now that rdeps is exclusively "locked", there is no reason to check empty dir.

/rdeps is only created when there is an actual dependency.
clean.sh: Optimize slightly by avoiding rechecking clean_rdepends many times.

For large port depdenencies, such as ports-mgmt/pkg, this can result in 24000
[] calls.
clean.sh: Only consider ready-to-build if not recursively cleaning.

This is mostly a NOP. The code is more proper now, there is no reason to
try moving ports to /unbalanced if recursively cleaning. The code
would just do an echo ""|xargs before anyhow.