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@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++; } }
On Fri, 1 Jun 2012 21:31:17 +0200 Niklas Söderlund niso@kth.se wrote:
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@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));
i changed this to msg_perr("Error: cannot resolve %s\n", ip); because errno is not set correctly by gethostbyaddr (which is obsolete and should be replaced anyway).
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);}
btw: this does explode spectacularly (not your fault, niklas, of course).
i think i kept the rest as is. thanks, niklas! applied in r1557.