diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-03-28 23:29:23 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-04-01 16:41:15 +0200 |
commit | 7ce1356c9f571c55af70bd6b966fe50898c1582d (patch) | |
tree | 8fd743d1747582bd1a662e3338db07ee1013f55e /lib/util/idtree.c | |
parent | 794525f3427e5f01656f205504d478318d9620a4 (diff) | |
download | samba-7ce1356c9f571c55af70bd6b966fe50898c1582d.tar.gz samba-7ce1356c9f571c55af70bd6b966fe50898c1582d.tar.xz samba-7ce1356c9f571c55af70bd6b966fe50898c1582d.zip |
lib/util: fallback to any id in idr_get_new_random()
metze
Diffstat (limited to 'lib/util/idtree.c')
-rw-r--r-- | lib/util/idtree.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/util/idtree.c b/lib/util/idtree.c index c8a8b6346ad..0af93a229d3 100644 --- a/lib/util/idtree.c +++ b/lib/util/idtree.c @@ -372,12 +372,16 @@ _PUBLIC_ int idr_get_new_random(struct idr_context *idp, void *ptr, int limit) /* first try a random starting point in the whole range, and if that fails, then start randomly in the bottom half of the range. This can only - fail if the range is over half full */ + fail if the range is over half full, and finally fallback to any + free id */ id = idr_get_new_above(idp, ptr, 1+(generate_random() % limit), limit); if (id == -1) { id = idr_get_new_above(idp, ptr, 1+(generate_random()%(limit/2)), limit); } - + if (id == -1) { + id = idr_get_new_above(idp, ptr, 1, limit); + } + return id; } |