[asterisk-commits] jpeeler: branch 1.6.1 r140206 - in /branches/1.6.1: ./ channels/chan_dahdi.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 26 13:50:48 CDT 2008
Author: jpeeler
Date: Tue Aug 26 13:50:47 2008
New Revision: 140206
URL: http://svn.digium.com/view/asterisk?view=rev&rev=140206
Log:
Merged revisions 140205 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r140205 | jpeeler | 2008-08-26 13:48:55 -0500 (Tue, 26 Aug 2008) | 17 lines
Merged revisions 140056 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r140056 | jpeeler | 2008-08-26 10:57:02 -0500 (Tue, 26 Aug 2008) | 9 lines
(closes issue #12071)
Reported by: tzafrir
Patches:
dahdi_close.diff uploaded by tzafrir (license 46)
Tested by: tzafrir, jpeeler
This patch fixes closing open file descriptors in the case of an error.
........
................
Modified:
branches/1.6.1/ (props changed)
branches/1.6.1/channels/chan_dahdi.c
Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.
Modified: branches/1.6.1/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/channels/chan_dahdi.c?view=diff&rev=140206&r1=140205&r2=140206
==============================================================================
--- branches/1.6.1/channels/chan_dahdi.c (original)
+++ branches/1.6.1/channels/chan_dahdi.c Tue Aug 26 13:50:47 2008
@@ -1141,6 +1141,28 @@
close(fd);
}
+static void dahdi_close_sub(struct dahdi_pvt *chan_pvt, int sub_num)
+{
+ dahdi_close(chan_pvt->subs[sub_num].dfd);
+ chan_pvt->subs[sub_num].dfd = -1;
+}
+
+#ifdef HAVE_PRI
+static void dahdi_close_pri_fd(struct dahdi_pri *pri, int fd_num)
+{
+ dahdi_close(pri->fds[fd_num]);
+ pri->fds[fd_num] = -1;
+}
+#endif
+
+#ifdef HAVE_SS7
+static void dahdi_close_ss7_fd(struct dahdi_ss7 *ss7, int fd_num)
+{
+ dahdi_close(ss7->fds[fd_num]);
+ ss7->fds[fd_num] = -1;
+}
+#endif
+
static int dahdi_setlinear(int dfd, int linear)
{
int res;
@@ -1180,7 +1202,7 @@
if (ioctl(p->subs[x].dfd, DAHDI_CHANNO, &p->subs[x].chan) == 1) {
ast_log(LOG_WARNING, "Unable to get channel number for pseudo channel on FD %d: %s\n", p->subs[x].dfd, strerror(errno));
- dahdi_close(p->subs[x].dfd);
+ dahdi_close_sub(p, x);
p->subs[x].dfd = -1;
return -1;
}
@@ -1195,10 +1217,7 @@
return -1;
}
ast_debug(1, "Released sub %d of channel %d\n", x, p->channel);
- if (p->subs[x].dfd > -1) {
- dahdi_close(p->subs[x].dfd);
- }
- p->subs[x].dfd = -1;
+ dahdi_close_sub(p, x);
p->subs[x].linear = 0;
p->subs[x].chan = 0;
p->subs[x].owner = NULL;
@@ -2782,6 +2801,7 @@
if (p->vars)
ast_variables_destroy(p->vars);
ast_mutex_destroy(&p->lock);
+ dahdi_close_sub(p, SUB_REAL);
if (p->owner)
p->owner->tech_pvt = NULL;
free(p);
@@ -2817,9 +2837,6 @@
else
ifend = NULL;
}
- if (cur->subs[SUB_REAL].dfd > -1) {
- dahdi_close(cur->subs[SUB_REAL].dfd);
- }
destroy_dahdi_pvt(&cur);
}
} else {
@@ -2836,9 +2853,6 @@
else
ifend = NULL;
}
- if (cur->subs[SUB_REAL].dfd > -1) {
- dahdi_close(cur->subs[SUB_REAL].dfd);
- }
destroy_dahdi_pvt(&cur);
}
return 0;
@@ -2860,9 +2874,6 @@
/* Free any callerid */
if (p->cidspill)
ast_free(p->cidspill);
- /* Close the DAHDI thingy */
- if (p->subs[SUB_REAL].dfd > -1)
- dahdi_close(p->subs[SUB_REAL].dfd);
pl = p;
p = p->next;
x = pl->channel;
@@ -8190,7 +8201,7 @@
x = channels[y];
if (ioctl(fd, DAHDI_SPECIFY, &x)) {
ast_log(LOG_WARNING, "Failed to specify channel %d: %s\n", channels[y], strerror(errno));
- dahdi_close(fd);
+ close(fd);
return -1;
}
if (ioctl(fd, DAHDI_GET_PARAMS, &p)) {
@@ -8199,18 +8210,18 @@
}
if (ioctl(fd, DAHDI_SPANSTAT, &si)) {
ast_log(LOG_WARNING, "Failed go get span information on channel %d (span %d): %s\n", channels[y], p.spanno, strerror(errno));
- dahdi_close(fd);
+ 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);
- dahdi_close(fd);
+ 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);
- dahdi_close(fd);
+ close(fd);
return -1;
}
if (!y) {
@@ -8221,7 +8232,7 @@
pris[ospan].dchannels[y] = channels[y];
pris[ospan].dchanavail[y] |= DCHAN_PROVISIONED;
pris[span].span = span + 1;
- dahdi_close(fd);
+ close(fd);
}
return 0;
}
@@ -10161,7 +10172,7 @@
else {
/* Looks good. Drop the pseudo channel now, clear up the assignment, and
wakeup the potential sleeper */
- dahdi_close(crv->subs[SUB_REAL].dfd);
+ dahdi_close_sub(crv, SUB_REAL);
pri->pvts[principle]->call = crv->call;
pri_assign_bearer(crv, pri, pri->pvts[principle]);
ast_debug(1, "Assigning bearer %d/%d to CRV %d:%d\n",
@@ -11503,22 +11514,19 @@
}
res = ioctl(pri->fds[i], DAHDI_GET_PARAMS, &p);
if (res) {
- dahdi_close(pri->fds[i]);
- pri->fds[i] = -1;
+ dahdi_close_pri_fd(pri, i);
ast_log(LOG_ERROR, "Unable to get parameters for D-channel %d (%s)\n", x, strerror(errno));
return -1;
}
if ((p.sigtype != DAHDI_SIG_HDLCFCS) && (p.sigtype != DAHDI_SIG_HARDHDLC)) {
- dahdi_close(pri->fds[i]);
- pri->fds[i] = -1;
+ dahdi_close_pri_fd(pri, i);
ast_log(LOG_ERROR, "D-channel %d is not in HDLC/FCS mode.\n", x);
return -1;
}
memset(&si, 0, sizeof(si));
res = ioctl(pri->fds[i], DAHDI_SPANSTAT, &si);
if (res) {
- dahdi_close(pri->fds[i]);
- pri->fds[i] = -1;
+ dahdi_close_pri_fd(pri, i);
ast_log(LOG_ERROR, "Unable to get span state for D-channel %d (%s)\n", x, strerror(errno));
}
if (!si.alarms)
@@ -11531,8 +11539,7 @@
bi.bufsize = 1024;
if (ioctl(pri->fds[i], DAHDI_SET_BUFINFO, &bi)) {
ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", x, strerror(errno));
- dahdi_close(pri->fds[i]);
- pri->fds[i] = -1;
+ dahdi_close_pri_fd(pri, i);
return -1;
}
switch (pri->sig) {
@@ -11556,8 +11563,7 @@
if (i)
pri_enslave(pri->dchans[0], pri->dchans[i]);
if (!pri->dchans[i]) {
- dahdi_close(pri->fds[i]);
- pri->fds[i] = -1;
+ dahdi_close_pri_fd(pri, i);
ast_log(LOG_ERROR, "Unable to create PRI structure\n");
return -1;
}
@@ -11577,8 +11583,7 @@
for (i = 0; i < NUM_DCHANS; i++) {
if (!pri->dchannels[i])
break;
- dahdi_close(pri->fds[i]);
- pri->fds[i] = -1;
+ dahdi_close_pri_fd(pri, i);
}
ast_log(LOG_ERROR, "Unable to spawn D-channel: %s\n", strerror(errno));
return -1;
@@ -12077,7 +12082,7 @@
#ifdef HAVE_PRI
for (i = 0; i < NUM_SPANS; i++) {
for (j = 0; j < NUM_DCHANS; j++)
- dahdi_close(pris[i].fds[j]);
+ dahdi_close_pri_fd(&(pris[i]), j);
}
memset(pris, 0, sizeof(pris));
@@ -12094,7 +12099,7 @@
#ifdef HAVE_SS7
for (i = 0; i < NUM_SPANS; i++) {
for (j = 0; j < NUM_DCHANS; j++)
- dahdi_close(linksets[i].fds[j]);
+ dahdi_close_ss7_fd(&(linksets[i]), j);
}
memset(linksets, 0, sizeof(linksets));
@@ -13094,14 +13099,12 @@
}
res = ioctl(link->fds[curfd], DAHDI_GET_PARAMS, &p);
if (res) {
- dahdi_close(link->fds[curfd]);
- link->fds[curfd] = -1;
+ dahdi_close_ss7_fd(link, curfd);
ast_log(LOG_ERROR, "Unable to get parameters for sigchan %d (%s)\n", sigchan, strerror(errno));
return -1;
}
if ((p.sigtype != DAHDI_SIG_HDLCFCS) && (p.sigtype != DAHDI_SIG_HARDHDLC) && (p.sigtype != DAHDI_SIG_MTP2)) {
- dahdi_close(link->fds[curfd]);
- link->fds[curfd] = -1;
+ dahdi_close_ss7_fd(link, curfd);
ast_log(LOG_ERROR, "sigchan %d is not in HDLC/FCS mode.\n", sigchan);
return -1;
}
@@ -13113,8 +13116,7 @@
if (ioctl(link->fds[curfd], DAHDI_SET_BUFINFO, &bi)) {
ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", sigchan, strerror(errno));
- dahdi_close(link->fds[curfd]);
- link->fds[curfd] = -1;
+ dahdi_close_ss7_fd(link, curfd);
return -1;
}
@@ -13128,8 +13130,7 @@
memset(&si, 0, sizeof(si));
res = ioctl(link->fds[curfd], DAHDI_SPANSTAT, &si);
if (res) {
- dahdi_close(link->fds[curfd]);
- link->fds[curfd] = -1;
+ dahdi_close_ss7_fd(link, curfd);
ast_log(LOG_ERROR, "Unable to get span state for sigchan %d (%s)\n", sigchan, strerror(errno));
}
@@ -13493,8 +13494,7 @@
static int __unload_module(void)
{
- int x;
- struct dahdi_pvt *p, *pl;
+ struct dahdi_pvt *p;
#if defined(HAVE_PRI) || defined(HAVE_SS7)
int i, j;
#endif
@@ -13542,34 +13542,14 @@
monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
- ast_mutex_lock(&iflock);
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while (p) {
- /* Free any callerid */
- if (p->cidspill)
- ast_free(p->cidspill);
- /* Close the DAHDI thingy */
- if (p->subs[SUB_REAL].dfd > -1)
- dahdi_close(p->subs[SUB_REAL].dfd);
- pl = p;
- p = p->next;
- x = pl->channel;
- /* Free associated memory */
- if (pl)
- destroy_dahdi_pvt(&pl);
- ast_verb(3, "Unregistered channel %d\n", x);
- }
- iflist = NULL;
- ifcount = 0;
- ast_mutex_unlock(&iflock);
+ destroy_all_channels();
#if defined(HAVE_PRI)
for (i = 0; i < NUM_SPANS; i++) {
if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL))
pthread_join(pris[i].master, NULL);
for (j = 0; j < NUM_DCHANS; j++) {
- dahdi_close(pris[i].fds[j]);
+ dahdi_close_pri_fd(&(pris[i]), j);
}
}
#endif
@@ -13579,7 +13559,7 @@
if (linksets[i].master && (linksets[i].master != AST_PTHREADT_NULL))
pthread_join(linksets[i].master, NULL);
for (j = 0; j < NUM_DCHANS; j++) {
- dahdi_close(linksets[i].fds[j]);
+ dahdi_close_ss7_fd(&(linksets[i]), j);
}
}
#endif
More information about the asterisk-commits
mailing list