aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_dahdi.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-02 21:46:38 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-02 21:46:38 +0000
commitd82e6c48cfaab526148775f91c083dc66a14c717 (patch)
tree1c8b2f5990db9df55f7ad5e676a54f7d89f2c43c /channels/chan_dahdi.c
parent46bcf33151d27f721fa6ce8f9b5b3ccc549aca75 (diff)
Merged revisions 115313,121770,123272,139624,140205,144257 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r115313 | tilghman | 2008-05-05 15:22:08 -0500 (Mon, 05 May 2008) | 10 lines Merged revisions 115312 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r115312 | tilghman | 2008-05-05 15:17:55 -0500 (Mon, 05 May 2008) | 2 lines Reverse order, such that user configs override default selections ........ ................ r121770 | crichter | 2008-06-11 06:52:18 -0500 (Wed, 11 Jun 2008) | 9 lines Merged revisions 121751 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r121751 | crichter | 2008-06-11 11:28:04 +0200 (Mi, 11 Jun 2008) | 1 line fixed issue with previous commit, the find_free_channel test for channels which where inuse was broken. ........ ................ r123272 | russell | 2008-06-17 10:52:13 -0500 (Tue, 17 Jun 2008) | 12 lines Merged revisions 123271 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r123271 | russell | 2008-06-17 10:48:31 -0500 (Tue, 17 Jun 2008) | 4 lines Fix a memory leak in astobj2 that was pointed out by seanbright. When a container got destroyed, the underlying bucket list entry for each object that was in the container at that time did not get free'd. ........ ................ r139624 | jpeeler | 2008-08-22 16:57:32 -0500 (Fri, 22 Aug 2008) | 13 lines Merged revisions 139621 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r139621 | jpeeler | 2008-08-22 16:36:13 -0500 (Fri, 22 Aug 2008) | 5 lines (closes issue #13359) Reported by: Laureano Patches: originate_channel_check.patch uploaded by Laureano (license 265) ........ ................ 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. ........ ................ r144257 | crichter | 2008-09-24 03:42:55 -0500 (Wed, 24 Sep 2008) | 9 lines Merged revisions 144238 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r144238 | crichter | 2008-09-24 10:20:52 +0200 (Mi, 24 Sep 2008) | 1 line improved helptext of misdn_set_opt. ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@160386 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_dahdi.c')
-rw-r--r--channels/chan_dahdi.c114
1 files changed, 47 insertions, 67 deletions
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 518ae1571..46e74fa89 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -1130,6 +1130,28 @@ static void dahdi_close(int fd)
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;
@@ -1169,7 +1191,7 @@ static int alloc_sub(struct dahdi_pvt *p, int x)
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;
}
@@ -1184,10 +1206,7 @@ static int unalloc_sub(struct dahdi_pvt *p, int x)
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;
@@ -2771,6 +2790,7 @@ static void destroy_dahdi_pvt(struct dahdi_pvt **pvt)
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);
@@ -2806,9 +2826,6 @@ static int destroy_channel(struct dahdi_pvt *prev, struct dahdi_pvt *cur, int no
else
ifend = NULL;
}
- if (cur->subs[SUB_REAL].dfd > -1) {
- dahdi_close(cur->subs[SUB_REAL].dfd);
- }
destroy_dahdi_pvt(&cur);
}
} else {
@@ -2825,9 +2842,6 @@ static int destroy_channel(struct dahdi_pvt *prev, struct dahdi_pvt *cur, int no
else
ifend = NULL;
}
- if (cur->subs[SUB_REAL].dfd > -1) {
- dahdi_close(cur->subs[SUB_REAL].dfd);
- }
destroy_dahdi_pvt(&cur);
}
return 0;
@@ -2849,9 +2863,6 @@ static void destroy_all_channels(void)
/* 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;
@@ -8010,7 +8021,7 @@ static int pri_create_trunkgroup(int trunkgroup, int *channels)
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)) {
@@ -8019,18 +8030,18 @@ static int pri_create_trunkgroup(int trunkgroup, int *channels)
}
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) {
@@ -8041,7 +8052,7 @@ static int pri_create_trunkgroup(int trunkgroup, int *channels)
pris[ospan].dchannels[y] = channels[y];
pris[ospan].dchanavail[y] |= DCHAN_PROVISIONED;
pris[span].span = span + 1;
- dahdi_close(fd);
+ close(fd);
}
return 0;
}
@@ -9986,7 +9997,7 @@ static int pri_fixup_principle(struct dahdi_pri *pri, int principle, q931_call *
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",
@@ -11334,22 +11345,19 @@ static int start_pri(struct dahdi_pri *pri)
}
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)
@@ -11362,8 +11370,7 @@ static int start_pri(struct dahdi_pri *pri)
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) {
@@ -11387,8 +11394,7 @@ static int start_pri(struct dahdi_pri *pri)
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;
}
@@ -11408,8 +11414,7 @@ static int start_pri(struct dahdi_pri *pri)
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;
@@ -11888,7 +11893,7 @@ static int dahdi_restart(void)
#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));
@@ -11905,7 +11910,7 @@ static int dahdi_restart(void)
#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));
@@ -12904,14 +12909,12 @@ static int linkset_addsigchan(int sigchan)
}
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;
}
@@ -12923,8 +12926,7 @@ static int linkset_addsigchan(int sigchan)
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;
}
@@ -12938,8 +12940,7 @@ static int linkset_addsigchan(int sigchan)
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));
}
@@ -13287,8 +13288,7 @@ static struct ast_cli_entry dahdi_ss7_cli[] = {
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
@@ -13336,34 +13336,14 @@ static int __unload_module(void)
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
@@ -13373,7 +13353,7 @@ static int __unload_module(void)
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