summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngela Stegmaier <angelabaker@ti.com>2017-07-26 09:57:00 -0500
committerAngela Stegmaier <angelabaker@ti.com>2017-08-03 11:44:01 -0500
commita967b6b039bff1288506489f754583597ad90e19 (patch)
tree73689385a50b8563dd8e274d7218db37212ee149
parent6736bb2b9b060cf37d3e6728e21509b24ec12da8 (diff)
downloadipc-a967b6b039bff1288506489f754583597ad90e19.tar.gz
Linux: LAD_client: Avoid hang in fopen during connect
If the application is started and calls Ipc_start before the LAD is started and created/opened the fifo, then the application can block in the fopen trying to connect to the command FIFO. This patch makes the sequence more robust by first checking if the fifo exists, then trying to open it as non-blocking, thereby getting an immediate success or error instead of blocking until it has been opened for reading by LAD. Once the non-blocking open returns successfully, the regular connect sequence can continue. If it returns with a failure, it will sleep and then try again for a period of time, eventually returning a timeout failure if it is unable to connect. This should prevent the application from hanging if LAD is not started before it calls Ipc_start. Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
-rw-r--r--linux/src/utils/LAD_client.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/linux/src/utils/LAD_client.c b/linux/src/utils/LAD_client.c
index 3aafb67..390e9c5 100644
--- a/linux/src/utils/LAD_client.c
+++ b/linux/src/utils/LAD_client.c
@@ -388,8 +388,36 @@ static LAD_Status initWrappers(Void)
*/
static Bool openCommandFIFO(Void)
{
+ time_t currentTime;
+ time_t startTime;
+ struct stat statBuf;
+ double delta = 0;
+ int commandFIFOFd = 0;
int flags;
+ startTime = time ((time_t *) 0);
+ while (delta <= LAD_CONNECTTIMEOUT) {
+ /* check if FIFO exists. LAD daemon will be creating it,
+ * we don't want the client to create it */
+ if (stat(commandFIFOFileName, &statBuf) == 0) {
+ /* open a file for writing to FIFO, non-blocking */
+ commandFIFOFd = open(commandFIFOFileName, O_WRONLY | O_TRUNC | O_NONBLOCK);
+ if (commandFIFOFd != -1) {
+ close(commandFIFOFd);
+ break;
+ }
+ }
+ PRINTVERBOSE0("\nLAD_connect: LAD is not yet running, will retry\n")
+ usleep(100);
+ currentTime = time ((time_t *) 0);
+ delta = difftime(currentTime, startTime);
+ }
+
+ if (delta > LAD_CONNECTTIMEOUT) {
+ PRINTVERBOSE0("\nERROR: timed out waiting for LAD to be started\n");
+ return(FALSE);
+ }
+
/* open a file for writing to FIFO */
commandFIFOFilePtr = fopen(commandFIFOFileName, "w");