[Pkg-voip-commits] [dahdi-tools] 162/285: dahdi_cfg: Allow dynamic spans to handle udev based span assignment.

tzafrir at debian.org tzafrir at debian.org
Thu Jul 7 19:18:49 UTC 2016


This is an automated email from the git hooks/post-receive script.

tzafrir pushed a commit to branch master
in repository dahdi-tools.

commit 69ce6f07e0842e1dcb8b18f19fd3d61f577d3022
Author: Shaun Ruffell <sruffell at digium.com>
Date:   Wed Jan 8 14:11:03 2014 -0600

    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 at digium.com>
    Signed-off-by: Russ Meyerriecks <rmeyerriecks at digium.com>
---
 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 */
-
-		while (!all_assigned && --timeout) {
-			usleep(250000);
-			all_assigned = are_all_spans_assigned();
-		}
+		bool all_assigned = wait_for_all_spans_assigned(5);
 
-		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<numdynamic;x++) {
-		/* destroy them all */
-		ioctl(fd, DAHDI_DYNAMIC_DESTROY, &zds[x]);
+	if (!restrict_channels && !only_span) {
+		for (x=0;x<numdynamic;x++) {
+			/* destroy them all */
+			ioctl(fd, DAHDI_DYNAMIC_DESTROY, &zds[x]);
+		}
 	}
+
 	if (stopmode) {
 		for (x=0;x<spans;x++) {
 			if (only_span && lc[x].span != only_span)
@@ -1704,14 +1714,28 @@ finish:
 			goto release_sem;
 		}
 	}
-	for (x=0;x<numdynamic;x++) {
-		if (ioctl(fd, DAHDI_DYNAMIC_CREATE, &zds[x])) {
-			fprintf(stderr, "DAHDI dynamic span creation failed: %s\n", strerror(errno));
-			close(fd);
+
+	if (!restrict_channels && !only_span) {
+
+		sem_post(lock);
+
+		for (x=0;x<numdynamic;x++) {
+			if (ioctl(fd, DAHDI_DYNAMIC_CREATE, &zds[x])) {
+				fprintf(stderr, "DAHDI dynamic span creation failed: %s\n", strerror(errno));
+				close(fd);
+				exit_code = 1;
+				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 release_sem;
+			goto unlink_sem;
 		}
 	}
+
 	for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
 		struct dahdi_params current_state;
 		int master;
@@ -1891,9 +1915,11 @@ finish:
 	exit_code = apply_fiftysix();
 
 release_sem:
-	if (SEM_FAILED != lock) {
+	if (SEM_FAILED != lock)
 		sem_post(lock);
+
+unlink_sem:
+	if (SEM_FAILED != lock)
 		sem_unlink(SEM_NAME);
-	}
 	exit(exit_code);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/dahdi-tools.git



More information about the Pkg-voip-commits mailing list