[mISDNuser PATCH] Fix handling of file descriptor zero
Thomas Jarosch <[email protected]> Mon, 08 Sep 2014 11:52:21 +0200
| Newsgroups | gmane.linux.isdn.i4l.user |
|---|---|
| Message-ID | <23507388.UvGR6hoNsE@storm> |
---
capi20/application.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/capi20/application.c b/capi20/application.c
index eb21ee7..f7cdc7a 100644
--- a/capi20/application.c
+++ b/capi20/application.c
@@ -38,7 +38,7 @@ static void app_sendcontrol(struct mApplication *appl, int cmd)
{
int ret;
- if (appl->cpipe[1] > 0) {
+ if (appl->cpipe[1] >= 0) {
ret = write(appl->cpipe[1], &cmd, sizeof(cmd));
if (ret < sizeof(cmd))
eprint("%s: refcount %d cannot write cmd=%x to controlpipe(%d) ret=%d - %s\n",
@@ -138,7 +138,8 @@ void ReleaseApplication(struct mApplication *appl, int unregister)
ret = pipe2(appl->cpipe, O_NONBLOCK);
if (ret)
eprint("%s: Cannot open control pipe - %s\n", CAPIobjIDstr(&appl->cobj), strerror(errno));
- close(appl->fd);
+ if (appl->fd >= 0)
+ close(appl->fd);
appl->fd = -1;
pthread_rwlock_unlock(&appl->cobj.lock);
@@ -193,13 +194,13 @@ void Free_Application(struct mCAPIobj *co)
}
if (!appl->unregistered) /* filedescriptor was closed */
capi_freeapplid(appl->cobj.id2);
- if (appl->fd > 0)
+ if (appl->fd >= 0)
close(appl->fd);
appl->fd = -1;
- if (appl->cpipe[1] > 0)
+ if (appl->cpipe[1] >= 0)
close(appl->cpipe[1]);
appl->cpipe[1] = -1;
- if (appl->cpipe[0] > 0)
+ if (appl->cpipe[0] >= 0)
close(appl->cpipe[0]);
appl->cpipe[0] = -1;
@@ -246,7 +247,7 @@ void Put_Application_cleaned(struct mCAPIobj *co)
{
struct mApplication *appl = container_of(co, struct mApplication, cobj);
- if (appl->cobj.cleaned && appl->cpipe[1] > 0)
+ if (appl->cobj.cleaned && appl->cpipe[1] >= 0)
app_sendcontrol(appl, MI_PUT_APPLICATION);
}
--
1.9.3