summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisael Lopez Cruz <misael.lopez@ti.com>2015-12-21 11:39:30 -0600
committerAngela Stegmaier <angelabaker@ti.com>2016-01-05 12:59:18 -0600
commit9e48f0b4e0c41b7f2916d3ca9e930f919c2c5762 (patch)
tree89b0ef2be9e7f704e42a88c4b9296ab3fc51edf9
parente44419a48eb8780116a525e3d00945c11ca19986 (diff)
downloadipc-9e48f0b4e0c41b7f2916d3ca9e930f919c2c5762.tar.gz
lad: Clean-up old response FIFOs
The LAD daemon was only deleting specific FIFOs for new clients whose PIDs had a corresponding old FIFO left over. This was not effective as the client side checks if the FIFO doesn't exist before sending the LAD_CONNECT command, so the old FIFO was not deleted. The cleanup is changed to delete any old FIFO left over from previous LAD sessions. The cleanup implementation is based on wpa_supplicant's. Signed-off-by: Vishal Mahaveer <vishalm@ti.com> Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
-rw-r--r--linux/src/daemon/lad.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/linux/src/daemon/lad.c b/linux/src/daemon/lad.c
index 11dc1a7..1c7c707 100644
--- a/linux/src/daemon/lad.c
+++ b/linux/src/daemon/lad.c
@@ -45,6 +45,7 @@
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
+#include <dirent.h>
#include <ti/ipc/MessageQ.h>
#include <_MessageQ.h>
@@ -80,6 +81,7 @@ static FILE * responseFIFOFilePtr[LAD_MAXNUMCLIENTS];
/* local internal routines */
static LAD_ClientHandle assignClientId(Void);
+static Void cleanupFifos(Void);
static Void cleanupDepartedClients(Void);
static Int connectToLAD(String clientName, Int pid, String clientProto, Int *clientIdPtr);
static Void disconnectFromLAD(Int clientId);
@@ -160,6 +162,8 @@ int main(int argc, char * argv[])
"\nERROR: Failed to change to LAD's working directory!\n");
exit(EXIT_FAILURE);
}
+ } else {
+ cleanupFifos();
}
/* process command line args */
@@ -882,6 +886,38 @@ static LAD_ClientHandle assignClientId(Void)
return(clientId);
}
+/*
+ * ======== cleanupFifos ========
+ */
+static void cleanupFifos(Void)
+{
+ DIR *dir;
+ struct dirent entry;
+ struct dirent *result;
+ size_t dirnamelen;
+ size_t maxcopy;
+ Char pathname[PATH_MAX];
+ Char *namep;
+
+ if ((dir = opendir(LAD_WORKINGDIR)) == NULL)
+ return;
+
+ dirnamelen = snprintf(pathname, sizeof(pathname), "%s/", LAD_WORKINGDIR);
+ if (dirnamelen >= sizeof(pathname)) {
+ closedir(dir);
+ return;
+ }
+ namep = pathname + dirnamelen;
+ maxcopy = PATH_MAX - dirnamelen;
+ while (readdir_r(dir, &entry, &result) == 0 && result != NULL) {
+ /* Delete old FIFOs left over */
+ if ((entry.d_type == DT_FIFO) && (strlen(entry.d_name) < maxcopy)) {
+ strncpy(namep, entry.d_name, maxcopy);
+ unlink(pathname);
+ }
+ }
+ closedir(dir);
+}
/*
* ======== cleanupDepartedClients ========
@@ -983,9 +1019,6 @@ static Int connectToLAD(String clientName, Int pid, String clientProto, Int *cli
openResponseFIFO:
- /* if response FIFO exists from previous LAD session delete it now */
- unlink(clientName);
-
/* create the dedicated response FIFO to the client */
statusIO = mkfifo(clientName, 0777);
if (statusIO != 0) {