[Asterisk-cvs] asterisk/channels chan_zap.c,1.344.2.4,1.344.2.5

russell at lists.digium.com russell at lists.digium.com
Sun Oct 24 20:14:30 CDT 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv22421/channels

Modified Files:
      Tag: v1-0
	chan_zap.c 
Log Message:
Make sure close() is not called on a fd < 1 with a wrapper call (bug #2710)


Index: chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.344.2.4
retrieving revision 1.344.2.5
diff -u -d -r1.344.2.4 -r1.344.2.5
--- chan_zap.c	14 Oct 2004 22:46:56 -0000	1.344.2.4
+++ chan_zap.c	25 Oct 2004 00:18:06 -0000	1.344.2.5
@@ -153,6 +153,8 @@
 
 #define DCHAN_AVAILABLE	(DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
 
+#define zt_close(fd) if(fd > 0) close(fd);
+
 static char context[AST_MAX_EXTENSION] = "default";
 static char callerid[256] = "";
 
@@ -758,7 +760,7 @@
 	if (chan) {
 		if (ioctl(fd, ZT_SPECIFY, &chan)) {
 			x = errno;
-			close(fd);
+			zt_close(fd);
 			errno = x;
 			ast_log(LOG_WARNING, "Unable to specify channel %d: %s\n", chan, strerror(errno));
 			return -1;
@@ -769,11 +771,6 @@
 	return fd;
 }
 
-static void zt_close(int fd)
-{
-	close(fd);
-}
-
 int zt_setlinear(int zfd, int linear)
 {
 	int res;
@@ -6080,7 +6077,7 @@
 		x = channels[y];
 		if (ioctl(fd, ZT_SPECIFY, &x)) {
 			ast_log(LOG_WARNING, "Failed to specify channel %d: %s\n", channels[y], strerror(errno));
-			close(fd);
+			zt_close(fd);
 			return -1;
 		}
 		if (ioctl(fd, ZT_GET_PARAMS, &p)) {
@@ -6089,18 +6086,18 @@
 		}
 		if (ioctl(fd, ZT_SPANSTAT, &si)) {
 			ast_log(LOG_WARNING, "Failed go get span information on channel %d (span %d)\n", channels[y], p.spanno);
-			close(fd);
+			zt_close(fd);
 			return -1;
 		}
 		span = p.spanno - 1;
 		if (pris[span].trunkgroup) {
 			ast_log(LOG_WARNING, "Span %d is already provisioned for trunk group %d\n", span + 1, pris[span].trunkgroup);
-			close(fd);
+			zt_close(fd);
 			return -1;
 		}
 		if (pris[span].pvts[0]) {
 			ast_log(LOG_WARNING, "Span %d is already provisioned with channels (implicit PRI maybe?)\n", span + 1);
-			close(fd);
+			zt_close(fd);
 			return -1;
 		}
 		if (!y) {
@@ -6111,7 +6108,7 @@
 		pris[ospan].dchannels[y] = channels[y];
 		pris[ospan].dchanavail[y] |= DCHAN_PROVISIONED;
 		pris[span].span = span + 1;
-		close(fd);
+		zt_close(fd);
 	}
 	return 0;	
 }
@@ -7055,7 +7052,7 @@
 			else {
 				/* Looks good.  Drop the pseudo channel now, clear up the assignment, and
 				   wakeup the potential sleeper */
-				close(crv->subs[SUB_REAL].zfd);
+				zt_close(crv->subs[SUB_REAL].zfd);
 				pri->pvts[principle]->call = crv->call;
 				pri_assign_bearer(crv, pri, pri->pvts[principle]);
 				ast_log(LOG_DEBUG, "Assigning bearer %d/%d to CRV %d:%d\n",
@@ -8057,13 +8054,13 @@
 		}
 		res = ioctl(pri->fds[i], ZT_GET_PARAMS, &p);
 		if (res) {
-			close(pri->fds[i]);
+			zt_close(pri->fds[i]);
 			pri->fds[i] = -1;
 			ast_log(LOG_ERROR, "Unable to get parameters for D-channel %d (%s)\n", x, strerror(errno));
 			return -1;
 		}
 		if (p.sigtype != ZT_SIG_HDLCFCS) {
-			close(pri->fds[i]);
+			zt_close(pri->fds[i]);
 			pri->fds[i] = -1;
 			ast_log(LOG_ERROR, "D-channel %d is not in HDLC/FCS mode.  See /etc/zaptel.conf\n", x);
 			return -1;
@@ -8071,7 +8068,7 @@
 		memset(&si, 0, sizeof(si));
 		res = ioctl(pri->fds[i], ZT_SPANSTAT, &si);
 		if (res) {
-			close(pri->fds[i]);
+			zt_close(pri->fds[i]);
 			pri->fds[i] = -1;
 			ast_log(LOG_ERROR, "Unable to get span state for D-channel %d (%s)\n", x, strerror(errno));
 		}
@@ -8085,7 +8082,7 @@
 		bi.bufsize = 1024;
 		if (ioctl(pri->fds[i], ZT_SET_BUFINFO, &bi)) {
 			ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d\n", x);
-			close(pri->fds[i]);
+			zt_close(pri->fds[i]);
 			pri->fds[i] = -1;
 			return -1;
 		}
@@ -8098,7 +8095,7 @@
 		if (i)
 			pri_enslave(pri->dchans[0], pri->dchans[i]);
 		if (!pri->dchans[i]) {
-			close(pri->fds[i]);
+			zt_close(pri->fds[i]);
 			pri->fds[i] = -1;
 			ast_log(LOG_ERROR, "Unable to create PRI structure\n");
 			return -1;
@@ -8113,7 +8110,7 @@
 		for (i=0;i<NUM_DCHANS;i++) {
 			if (!pri->dchannels[i])
 				break;
-			close(pri->fds[i]);
+			zt_close(pri->fds[i]);
 			pri->fds[i] = -1;
 		}
 		ast_log(LOG_ERROR, "Unable to spawn D-channel: %s\n", strerror(errno));




More information about the svn-commits mailing list