[Pkg-voip-commits] [dahdi-tools] 105/285: fxstest: Use DAHDI_SPECIFY when opening by integer channel number.

tzafrir at debian.org tzafrir at debian.org
Thu Jul 7 19:18:39 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 7939579d9e901d85749eadbdd40bc1c79ecd6478
Author: Shaun Ruffell <sruffell at digium.com>
Date:   Thu May 9 10:34:20 2013 -0500

    fxstest: Use DAHDI_SPECIFY when opening by integer channel number.
    
    In DAHDI-Linux 2.7 the layout of the /dev/dahdi files changes so that they are
    grouped by span. When opening channels by number all utilities need to use
    DAHDI_SPECIFY now.
    
    Signed-off-by: Shaun Ruffell <sruffell at digium.com>
    Signed-off-by: Russ Meyerriecks <rmeyerriecks at digium.com>
---
 fxstest.c | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/fxstest.c b/fxstest.c
index 130fad5..94709c6 100644
--- a/fxstest.c
+++ b/fxstest.c
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include <sys/stat.h>
 #include <dahdi/user.h>
 #include <dahdi/wctdm_user.h>
 
@@ -101,6 +102,41 @@ static int dahdi_ring_phone(int fd)
 	return res;
 }
 
+int channel_open(const char *name)
+{
+	int	channo, fd;
+	struct	stat filestat;
+	const char *DEVICE = "/dev/dahdi/channel";
+
+	/* stat file, if character device, open it */
+	channo = strtoul(name, NULL, 10);
+	fd = stat(name, &filestat);
+	if (!fd && S_ISCHR(filestat.st_mode)) {
+		fd = open(name, O_RDWR, 0600);
+		if (fd < 0) {
+			perror(name);
+			return -1;
+		}
+	/* try out the dahdi_specify interface */
+	} else if (channo > 0) {
+		fd = open(DEVICE, O_RDWR, 0600);
+		if (fd < 0) {
+			perror(DEVICE);
+			return -1;
+		}
+		if (ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
+			perror("DAHDI_SPECIFY ioctl failed");
+			return -1;
+		}
+	/* die */
+	} else {
+		fprintf(stderr, "Specified channel is not a valid character "
+			"device or channel number");
+		return -1;
+	}
+	return fd;
+}
+
 int main(int argc, char *argv[])
 {
 	int fd;
@@ -121,7 +157,7 @@ int main(int argc, char *argv[])
 		       "       dtmfcid - create a dtmf cid spill without polarity reversal\n");
 		exit(1);
 	}
-	fd = open(argv[1], O_RDWR);
+	fd = channel_open(argv[1]);
 	if (fd < 0) {
 		fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
 		exit(1);

-- 
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