Try to fix filedescriptor leak and add additional debug output to get more info about the leak
This commit is contained in:
parent
ec4ac2763f
commit
dee4e5684a
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* application.c
|
||||
*
|
||||
* Written by Karsten Keil <kkeil@linux-pingi.de>
|
||||
|
@ -135,9 +135,30 @@ void ReleaseApplication(struct mApplication *appl, int unregister)
|
|||
|
||||
appl->unregistered = unregister;
|
||||
|
||||
ret = pipe2(appl->cpipe, O_NONBLOCK);
|
||||
if (ret)
|
||||
eprint("%s: Cannot open control pipe - %s\n", CAPIobjIDstr(&appl->cobj), strerror(errno));
|
||||
if (appl->cpipe[0] > -1) {
|
||||
if (appl->cpipe[1] > -1) {
|
||||
wprint("%s: appl->cpipe fds=(%d, %d) already open - reuse pipe\n",
|
||||
CAPIobjIDstr(&appl->cobj), appl->cpipe[0], appl->cpipe[1]);
|
||||
} else {
|
||||
wprint("%s: appl->cpipe[0] fd=%d open but appl->cpipe[1] not - close now\n",
|
||||
CAPIobjIDstr(&appl->cobj), appl->cpipe[0]);
|
||||
close(appl->cpipe[0]);
|
||||
appl->cpipe[0] = -1;
|
||||
}
|
||||
} else if (appl->cpipe[1] > -1) {
|
||||
wprint("%s: appl->cpipe[1] fd=%d open but appl->cpipe[0] not - close now\n",
|
||||
CAPIobjIDstr(&appl->cobj), appl->cpipe[1]);
|
||||
close(appl->cpipe[1]);
|
||||
appl->cpipe[1] = -1;
|
||||
}
|
||||
if (appl->cpipe[0] < 0) {
|
||||
ret = pipe2(appl->cpipe, O_NONBLOCK);
|
||||
if (ret)
|
||||
eprint("%s: Cannot open control pipe - %s\n", CAPIobjIDstr(&appl->cobj), strerror(errno));
|
||||
else
|
||||
dprint(MIDEBUG_CONTROLLER, "%s: open application control pipe fds=(%d, %d)\n",
|
||||
CAPIobjIDstr(&appl->cobj), appl->cpipe[0], appl->cpipe [1]);
|
||||
}
|
||||
close(appl->fd);
|
||||
appl->fd = -1;
|
||||
|
||||
|
|
|
@ -988,6 +988,16 @@ static int CreateBchannelThread(struct BInstance *bi, int pcnt)
|
|||
{
|
||||
int ret, i;
|
||||
|
||||
if (bi->cpipe[0] > -1) {
|
||||
wprint("bi->cpipe[0] open (fd=%d) - close now\n", bi->cpipe[0]);
|
||||
close(bi->cpipe[0]);
|
||||
bi->cpipe[0] = -1;
|
||||
}
|
||||
if (bi->cpipe[1] > -1) {
|
||||
wprint("bi->cpipe[1] open (fd=%d) - close now\n", bi->cpipe[1]);
|
||||
close(bi->cpipe[1]);
|
||||
bi->cpipe[1] = -1;
|
||||
}
|
||||
ret = pipe(bi->cpipe);
|
||||
if (ret) {
|
||||
eprint("error - %s\n", strerror(errno));
|
||||
|
@ -1592,11 +1602,23 @@ static void ShutdownAppl(int idx, int unregister)
|
|||
eprint("Application not assigned\n");
|
||||
return;
|
||||
}
|
||||
if (appl->cpipe[0] > -1) {
|
||||
wprint("%s appl->cpipe[0] open (fd=%d) - close now\n", CAPIobjIDstr(&appl->cobj), appl->cpipe[0]);
|
||||
close(appl->cpipe[0]);
|
||||
appl->cpipe[0] = -1;
|
||||
}
|
||||
if (appl->cpipe[1] > -1) {
|
||||
wprint("%s: appl->cpipe[1] open (fd=%d) - close now\n", CAPIobjIDstr(&appl->cobj), appl->cpipe[1]);
|
||||
close(appl->cpipe[1]);
|
||||
appl->cpipe[1] = -1;
|
||||
}
|
||||
ret = pipe2(appl->cpipe, O_NONBLOCK);
|
||||
if (ret) {
|
||||
eprint("Cannot open application %d control pipe - %s\n", appl->cobj.id2, strerror(errno));
|
||||
mainpoll[idx].fd = -1;
|
||||
} else {
|
||||
dprint(MIDEBUG_CONTROLLER, "%s: open application control pipe fds=(%d, %d)\n",
|
||||
CAPIobjIDstr(&appl->cobj), appl->cpipe[0], appl->cpipe [1]);
|
||||
}
|
||||
ReleaseApplication(appl, unregister);
|
||||
pollinfo[idx].type = PIT_ReleasedApp;
|
||||
|
@ -1917,6 +1939,9 @@ int main_loop(void)
|
|||
socklen_t alen;
|
||||
struct mApplication *appl;
|
||||
|
||||
if ((mIControl[0] > -1) || (mIControl[1] > -1)) {
|
||||
eprint("Error restarting main_loop with open mIControl pipe(%d,%d)\n", mIControl[0], mIControl[1]);
|
||||
}
|
||||
ret = pipe(mIControl);
|
||||
if (ret) {
|
||||
eprint("error setup MasterControl pipe - %s\n", strerror(errno));
|
||||
|
|
Loading…
Reference in New Issue