Fix potential deadlock in the slurmctld when using list_for_each.
This partially reverts 89bcd975 and aac6bd39
Turns out you can't use a list_for_each and lock something inside the
list_for_each function that does a lock without the write lock.
Bug 4611