From b34223345b07b16008e3b4253c2572bea25fca55 Mon Sep 17 00:00:00 2001 From: Tom Keiser Date: Fri, 16 Dec 2005 03:27:17 +0000 Subject: [PATCH] multibreak-rework-avoiding-race-20051215 avoid a potential race finding the correct connection during MultiBreakCallBack_r --- src/viced/callback.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/viced/callback.c b/src/viced/callback.c index 8b25dfce1..4ad97f45c 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -778,6 +778,7 @@ MultiBreakCallBack_r(struct cbstruct cba[], int ncbas, int i, j; struct rx_connection *conns[MAX_CB_HOSTS]; static struct AFSCBs tc = { 0, 0 }; + int multi_to_cba_map[MAX_CB_HOSTS]; assert(ncbas <= MAX_CB_HOSTS); @@ -788,6 +789,7 @@ MultiBreakCallBack_r(struct cbstruct cba[], int ncbas, continue; } rx_GetConnection(thishost->callback_rxcon); + multi_to_cba_map[j] = i; conns[j++] = thishost->callback_rxcon; #ifdef ADAPT_MTU @@ -806,28 +808,14 @@ MultiBreakCallBack_r(struct cbstruct cba[], int ncbas, struct host *hp; char hoststr[16]; - idx = 0; - /* If there's an error, we have to hunt for the right host. - * The conns array _should_ correspond one-to-one to the cba - * array, except in some rare cases it might be missing one - * or more elements. So the optimistic case is almost - * always right. At worst, it's the starting point for the - * hunt. */ - for (hp = 0, i = multi_i; i < j; i++) { - hp = cba[i].hp; /* optimistic, but usually right */ - if (!hp) { - break; - } - if (conns[multi_i] == hp->callback_rxcon) { - idx = cba[i].thead; - break; - } - } + i = multi_to_cba_map[multi_i]; + hp = cba[i].hp; + idx = cba[i].thead; - if (!hp) { + if (!hp || !idx) { ViceLog(0, - ("BCB: INTERNAL ERROR: hp=%x, cba=%x\n", hp, - cba)); + ("BCB: INTERNAL ERROR: hp=%x, cba=%x, thead=%u\n", + hp, cba, idx)); } else { /* ** try breaking callbacks on alternate interface addresses -- 2.39.5