[flashrom] [PATCH] remove exit calls from sp_opensocket

Niklas Söderlund niso at kth.se
Fri Jun 1 21:31:17 CEST 2012


Replace with return statements and adopt the only upstream caller which
in turn all plumbing is place for

Signed-off-by: Niklas Söderlund <niso at kth.se>
---
 serprog.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/serprog.c b/serprog.c
index d06fb0b..02996ea 100644
--- a/serprog.c
+++ b/serprog.c
@@ -110,20 +110,25 @@ static int sp_opensocket(char *ip, unsigned int port)
 	int sock;
 	msg_pdbg(MSGHEADER "IP %s port %d\n", ip, port);
 	sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
-	if (sock < 0)
-		sp_die("Error: serprog cannot open socket");
+	if (sock < 0) {
+		msg_perr("Error: serprog cannot open socket: %s\n", strerror(errno));
+		return -1;
+	}
 	hostPtr = gethostbyname(ip);
 	if (NULL == hostPtr) {
 		hostPtr = gethostbyaddr(ip, strlen(ip), AF_INET);
-		if (NULL == hostPtr)
-			sp_die("Error: cannot resolve");
+		if (NULL == hostPtr) {
+			msg_perr("Error: cannot resolve: %s\n", strerror(errno));
+			return -1;
+		}
 	}
 	sp.si.sin_family = AF_INET;
 	sp.si.sin_port = htons(port);
 	(void)memcpy(&sp.si.sin_addr, hostPtr->h_addr, hostPtr->h_length);
 	if (connect(sock, &sp.s, sizeof(sp.si)) < 0) {
 		close(sock);
-		sp_die("Error: serprog cannot connect");
+		msg_perr("Error: serprog cannot connect:  %s\n", strerror(errno));
+		return -1;
 	}
 	/* We are latency limited, and sometimes do write-write-read    *
 	 * (write-n) - so enable TCP_NODELAY.				*/
@@ -398,6 +403,10 @@ int serprog_init(void)
 		}
 		if (strlen(device)) {
 			sp_fd = sp_opensocket(device, atoi(baudport));
+			if (sp_fd < 0) {
+				free(device);
+				return 1;
+			}
 			have_device++;
 		}
 	}
-- 
1.7.10.3





More information about the flashrom mailing list