[svn-commits] tzafrir: branch tools/tzafrir/sysfs r8743 - /tools/team/tzafrir/sysfs/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 3 13:52:10 CDT 2010


Author: tzafrir
Date: Thu Jun  3 13:52:06 2010
New Revision: 8743

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8743
Log:
Make dahdi_cfg properly support '-S <only_span>':

* The '-S' accept relative/absolute span string:
  Example: -S 'span-names/usb_INT01216(02)'
* Skip other spans and channels belonging to them.

Modified:
    tools/team/tzafrir/sysfs/dahdi_cfg.c

Modified: tools/team/tzafrir/sysfs/dahdi_cfg.c
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/dahdi_cfg.c?view=diff&rev=8743&r1=8742&r2=8743
==============================================================================
--- tools/team/tzafrir/sysfs/dahdi_cfg.c (original)
+++ tools/team/tzafrir/sysfs/dahdi_cfg.c Thu Jun  3 13:52:06 2010
@@ -112,7 +112,8 @@
 
 static int keep_going = 0;
 
-static int only_span_num = 0;
+static int  only_span_num = 0;
+static char *only_span;
 
 static int numdynamic = 0;
 
@@ -141,6 +142,7 @@
 
 static int	path_channels;
 static char	*chan_pathnames[DAHDI_MAX_CHANNELS];
+static int	belong2span[DAHDI_MAX_CHANNELS];
 static int	chan_indexes[DAHDI_MAX_CHANNELS];
 static char	*span_names[DAHDI_MAX_SPANS];
 
@@ -195,6 +197,14 @@
 	return only_span_num && only_span_num != x + 1;
 }
 
+static int skip_chan(int x)
+{
+	int in_span;
+
+	in_span = belong2span[x];
+	return only_span_num && in_span && only_span_num != in_span;
+}
+
 int ind_ioctl(int channo, int fd, int op, void *data)
 {
 	struct dahdi_indirect_data ind;
@@ -344,7 +354,10 @@
 	}
 	dahdi_copy_string(tmppath, span_string, sizeof(tmppath));
 	str_replace(tmppath, '!', '/');
-	snprintf(path, sizeof(path), "/dev/dahdi/%s", tmppath);
+	/*
+	 * Relative paths -- below /dev/dahdi
+	 */
+	snprintf(path, sizeof(path), "%s%s", (tmppath[0] == '/') ? "" : "/dev/dahdi/", tmppath);
 	if (lstat(path, &stbuf) >= 0) {
 		int	n;
 		char	*tmp;
@@ -517,18 +530,24 @@
 	int start, finish;
 	char argcopy[256];
 	char *pname;
+	int in_span = 0;
 	char prefix[PATH_MAX];
 
 	snprintf(prefix, sizeof(prefix), "/dev/dahdi/%s", argstr);
 	pname = strrchr(prefix, '!');
 	if (pname) {
 		*pname = '\0';
+		in_span = span_string2num(prefix);
+		if(in_span <= 0) {
+			error("Bad span string '%s'\n", pname);
+			return -1;
+		}
+		if(only_span_num && only_span_num != in_span)
+			return 0;
 		argstr = pname + 1;
 		str_replace(prefix, '!', '/');
 		pname = prefix;
 		if (access(pname, R_OK | X_OK) < 0) {
-			if (only_span_num)
-				return 0;
 			error("Missing '%s'\n", pname);
 			return -1;
 		}
@@ -577,6 +596,7 @@
 					continue;
 				chans[realchan]=1;
 				chan_pathnames[realchan] = pname;
+				belong2span[realchan] = in_span;
 				chan_indexes[realchan] = y;
 				//fprintf(stderr, "DEBUG: %s\t%d -> %d\n", pname, y, realchan);
 			}
@@ -601,6 +621,7 @@
 				continue;
 			chans[realchan]=1;
 			chan_pathnames[realchan] = pname;
+			belong2span[realchan] = in_span;
 			chan_indexes[realchan] = chan;
 			//fprintf(stderr, "DEBUG: %s\t%d -> %d\n", pname, chan, realchan);
 		}
@@ -661,6 +682,8 @@
 		return -1;
 	for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
 		if (chans[x]) {
+			if(skip_chan(x))
+				continue;
 			if (slineno[x]) {
 				error("Channel %d already configured as '%s' at line %d\n", x, sig[x], slineno[x]);
 				continue;
@@ -834,6 +857,8 @@
 	int chanfd;
 
 	for (x = 1; x < DAHDI_MAX_CHANNELS; x++) {
+		if(skip_chan(x))
+			continue;
 		chanfd = open("/dev/dahdi/channel", O_RDWR);
 		if (chanfd == -1) {
 			fprintf(stderr, 
@@ -1402,6 +1427,8 @@
 		for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
 			char	channame[BUFSIZ];
 
+			if(skip_chan(x))
+				continue;
 			if(showpaths) {
 				y = chan_indexes[x];
 				snprintf(channame, sizeof(channame), "%s!%02d",
@@ -1577,11 +1604,15 @@
 			keep_going = 1;
 			break;
 		case 'S':
-			only_span_num = atoi(optarg);
+			only_span = optarg;
+			only_span_num = span_string2num(only_span);
+			if (verbose || showpaths) {
+				fprintf(stderr, "Only span '%s' (%d)\n", only_span, only_span_num);
+			}
 			break;
 		}
 	}
-	
+
 	if (verbose) {
 		fprintf(stderr, "%s\n", dahdi_tools_version);
 	}
@@ -1686,6 +1717,8 @@
 		int master;
 		int needupdate = force;
 		
+		if(skip_chan(x))
+			continue;
 		if (debug & DEBUG_APPLY) {
 			printf("Configuring device %d\n", x);
 			fflush(stdout);




More information about the svn-commits mailing list