diff mbox series

[3/3] Fix coverity #292133

Message ID 20200420165756.13275-3-sbabic@denx.de
State Accepted
Headers show
Series [1/3] progress: drop nasty printf Trying to.. | expand

Commit Message

Stefano Babic April 20, 2020, 4:57 p.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 ipc/progress_ipc.c            | 6 ++++++
 mongoose/mongoose_interface.c | 7 +++++++
 suricatta/server_general.c    | 8 ++++++++
 tools/swupdate-progress.c     | 8 ++++++++
 tools/swupdate-sysrestart.c   | 8 ++++++++
 5 files changed, 37 insertions(+)
diff mbox series

Patch

diff --git a/ipc/progress_ipc.c b/ipc/progress_ipc.c
index 49d4b91..b4af883 100644
--- a/ipc/progress_ipc.c
+++ b/ipc/progress_ipc.c
@@ -44,6 +44,12 @@  static int _progress_ipc_connect(const char *socketpath, bool reconnect)
 	servaddr.sun_family = AF_LOCAL;
 	strncpy(servaddr.sun_path, socketpath, sizeof(servaddr.sun_path) - 1);
 
+	/*
+	 * Check to get a valid socket
+	 */
+	if (fd < 0)
+		return -1;
+
 	do {
 		if (connect(fd, (struct sockaddr *) &servaddr, sizeof(servaddr)) == 0) {
 			break;
diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 4d2ab52..150210e 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -193,6 +193,13 @@  static void *broadcast_progress_thread(void *data)
 
 		if (fd < 0)
 			fd = progress_ipc_connect(true);
+		/*
+		 * if still fails, try later
+		 */
+		if (fd < 0) {
+			sleep(1);
+			continue;
+		}
 
 		ret = progress_ipc_receive(&fd, &msg);
 		if (ret != sizeof(msg))
diff --git a/suricatta/server_general.c b/suricatta/server_general.c
index bebbaa6..a099d68 100644
--- a/suricatta/server_general.c
+++ b/suricatta/server_general.c
@@ -279,6 +279,14 @@  static void *server_progress_thread (void *data)
 			progfd = progress_ipc_connect(true);
 		}
 
+		/*
+		 * if still fails, try later
+		 */
+		if (progfd < 0) {
+			sleep(1);
+			continue;
+		}
+
 		if (progress_ipc_receive(&progfd, &msg) == -1) {
 			continue;
 		}
diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
index 723d7dc..cd8abd1 100644
--- a/tools/swupdate-progress.c
+++ b/tools/swupdate-progress.c
@@ -235,6 +235,14 @@  int main(int argc, char **argv)
 			connfd = progress_ipc_connect(opt_w);
 		}
 
+		/*
+		 * if still fails, try later
+		 */
+		if (connfd < 0) {
+			sleep(1);
+			continue;
+		}
+
 		if (progress_ipc_receive(&connfd, &msg) == -1) {
 			continue;
 		}
diff --git a/tools/swupdate-sysrestart.c b/tools/swupdate-sysrestart.c
index 2435457..31cb29a 100644
--- a/tools/swupdate-sysrestart.c
+++ b/tools/swupdate-sysrestart.c
@@ -180,6 +180,14 @@  int main(int argc, char **argv)
 			connfd = progress_ipc_connect(opt_w);
 		}
 
+		/*
+		 * if still fails, try later
+		 */
+		if (connfd < 0) {
+			sleep(1);
+			continue;
+		}
+
 		if (progress_ipc_receive(&connfd, &msg) == -1) {
 			continue;
 		}