From 5ed04a6e72cc5ebefd1b7858531e405bf1720f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Date: Fri, 19 Oct 2007 18:26:27 +0000 Subject: [PATCH] Refactored and added more error checking. --- protocolext.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/protocolext.c b/protocolext.c index dbd441e..65ebeb0 100644 --- a/protocolext.c +++ b/protocolext.c @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: protocolext.c,v 1.5 2007/10/19 18:03:19 ajhseppa Exp $ + * $Id: protocolext.c,v 1.6 2007/10/19 18:26:27 ajhseppa Exp $ */ #include @@ -142,12 +142,16 @@ void cIptvProtocolExt::TerminateCommand(void) const unsigned int timeoutms = 100; unsigned int waitms = 0; siginfo_t waitStatus; - int retval = 0; bool waitOver = false; // signal and wait for termination - kill(pid, SIGINT); + int retval = kill(pid, SIGINT); + if (retval < 0) { + char tmp[64]; + error("ERROR: kill(): %s", strerror_r(errno, tmp, sizeof(tmp))); + waitOver = true; + } - do { + while (!waitOver) { retval = 0; waitms += timeoutms; if ((waitms % 2000) == 0) { @@ -160,7 +164,7 @@ void cIptvProtocolExt::TerminateCommand(void) retval = waitid(P_PID, pid, &waitStatus, WNOHANG | WEXITED); if (retval < 0) { char tmp[64]; - error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp))); + error("ERROR: waitid(): %s", strerror_r(errno, tmp, sizeof(tmp))); waitOver = true; } // These are the acceptable conditions under which child exit is @@ -175,7 +179,7 @@ void cIptvProtocolExt::TerminateCommand(void) // Unsuccessful wait, avoid busy looping if (!waitOver) cCondWait::SleepMs(timeoutms); - } while (!waitOver); + } pid = -1; isActive = false;