From 69ce6f07e0842e1dcb8b18f19fd3d61f577d3022 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Wed, 8 Jan 2014 14:11:03 -0600 Subject: [PATCH] dahdi_cfg: Allow dynamic spans to handle udev based span assignment. Prior to this commit, if auto_assign_spans was set to 0, it was possible to get in an endless loop creating and destroying spans. The primary reason was that all dynamic spans are destroyed and recreated each time dahdi_cfg runs, BUT dahdi_cfg was run each time a new span showed up in udev when auto_assign_spans was set to 0. Now dahdi_cfg will only destroy and recreate dynamic spans if dahdi_cfg is run without a specifc span number. Also, while creating dynamic spans, dahdi_cfg will pause for up to one second for the span to be assigned in order to ensure that the spans are numbered consistently when auto span assignment is configured. Signed-off-by: Shaun Ruffell Signed-off-by: Russ Meyerriecks --- dahdi_cfg.c | 64 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 19 deletions(-) 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