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 <sruffell@digium.com> Signed-off-by: Russ Meyerriecks <rmeyerriecks@digium.com>
This commit is contained in:
parent
9989b8779c
commit
69ce6f07e0
48
dahdi_cfg.c
48
dahdi_cfg.c
@ -219,6 +219,19 @@ static bool are_all_spans_assigned(void)
|
|||||||
return res;
|
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)
|
static const char *sigtype_to_str(const int sig)
|
||||||
{
|
{
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
@ -1582,15 +1595,9 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!restrict_channels && !only_span) {
|
if (!restrict_channels && !only_span) {
|
||||||
bool all_assigned = are_all_spans_assigned();
|
bool all_assigned = wait_for_all_spans_assigned(5);
|
||||||
unsigned int timeout = 4*5; /* We'll wait 5 seconds */
|
|
||||||
|
|
||||||
while (!all_assigned && --timeout) {
|
if (!all_assigned) {
|
||||||
usleep(250000);
|
|
||||||
all_assigned = are_all_spans_assigned();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == timeout) {
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Timeout waiting for all spans to be assigned.\n");
|
"Timeout waiting for all spans to be assigned.\n");
|
||||||
}
|
}
|
||||||
@ -1673,13 +1680,16 @@ finish:
|
|||||||
if (-1 == sem_wait(lock)) {
|
if (-1 == sem_wait(lock)) {
|
||||||
error("Failed to wait for dahdi_cfg mutex.\n");
|
error("Failed to wait for dahdi_cfg mutex.\n");
|
||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto release_sem;
|
goto unlink_sem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!restrict_channels && !only_span) {
|
||||||
for (x=0;x<numdynamic;x++) {
|
for (x=0;x<numdynamic;x++) {
|
||||||
/* destroy them all */
|
/* destroy them all */
|
||||||
ioctl(fd, DAHDI_DYNAMIC_DESTROY, &zds[x]);
|
ioctl(fd, DAHDI_DYNAMIC_DESTROY, &zds[x]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (stopmode) {
|
if (stopmode) {
|
||||||
for (x=0;x<spans;x++) {
|
for (x=0;x<spans;x++) {
|
||||||
if (only_span && lc[x].span != only_span)
|
if (only_span && lc[x].span != only_span)
|
||||||
@ -1704,6 +1714,11 @@ finish:
|
|||||||
goto release_sem;
|
goto release_sem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!restrict_channels && !only_span) {
|
||||||
|
|
||||||
|
sem_post(lock);
|
||||||
|
|
||||||
for (x=0;x<numdynamic;x++) {
|
for (x=0;x<numdynamic;x++) {
|
||||||
if (ioctl(fd, DAHDI_DYNAMIC_CREATE, &zds[x])) {
|
if (ioctl(fd, DAHDI_DYNAMIC_CREATE, &zds[x])) {
|
||||||
fprintf(stderr, "DAHDI dynamic span creation failed: %s\n", strerror(errno));
|
fprintf(stderr, "DAHDI dynamic span creation failed: %s\n", strerror(errno));
|
||||||
@ -1711,7 +1726,16 @@ finish:
|
|||||||
exit_code = 1;
|
exit_code = 1;
|
||||||
goto release_sem;
|
goto release_sem;
|
||||||
}
|
}
|
||||||
|
wait_for_all_spans_assigned(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (-1 == sem_wait(lock)) {
|
||||||
|
error("Failed to wait for dahdi_cfg mutex after creating dynamic spans.\n");
|
||||||
|
exit_code = 1;
|
||||||
|
goto unlink_sem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
|
for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
|
||||||
struct dahdi_params current_state;
|
struct dahdi_params current_state;
|
||||||
int master;
|
int master;
|
||||||
@ -1891,9 +1915,11 @@ finish:
|
|||||||
exit_code = apply_fiftysix();
|
exit_code = apply_fiftysix();
|
||||||
|
|
||||||
release_sem:
|
release_sem:
|
||||||
if (SEM_FAILED != lock) {
|
if (SEM_FAILED != lock)
|
||||||
sem_post(lock);
|
sem_post(lock);
|
||||||
|
|
||||||
|
unlink_sem:
|
||||||
|
if (SEM_FAILED != lock)
|
||||||
sem_unlink(SEM_NAME);
|
sem_unlink(SEM_NAME);
|
||||||
}
|
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user