diff --git a/dahdi_cfg.c b/dahdi_cfg.c index c86eaac..4e9cc9e 100644 --- a/dahdi_cfg.c +++ b/dahdi_cfg.c @@ -219,6 +219,19 @@ static bool are_all_spans_assigned(void) return res; } +static bool wait_for_all_spans_assigned(unsigned long timeout_sec) +{ + bool all_assigned = are_all_spans_assigned(); + unsigned int timeout = 10*timeout_sec; + + while (!all_assigned && --timeout) { + usleep(100000); + all_assigned = are_all_spans_assigned(); + } + + return all_assigned; +} + static const char *sigtype_to_str(const int sig) { switch (sig) { @@ -1582,15 +1595,9 @@ int main(int argc, char *argv[]) } if (!restrict_channels && !only_span) { - bool all_assigned = are_all_spans_assigned(); - unsigned int timeout = 4*5; /* We'll wait 5 seconds */ + bool all_assigned = wait_for_all_spans_assigned(5); - while (!all_assigned && --timeout) { - usleep(250000); - all_assigned = are_all_spans_assigned(); - } - - if (0 == timeout) { + if (!all_assigned) { fprintf(stderr, "Timeout waiting for all spans to be assigned.\n"); } @@ -1673,13 +1680,16 @@ finish: if (-1 == sem_wait(lock)) { error("Failed to wait for dahdi_cfg mutex.\n"); exit_code = 1; - goto release_sem; + goto unlink_sem; } - for (x=0;x