Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit 217c8deb9484d1705bf26523b77dba7503d4d131 Author: Sven Eckelmann sven@narfation.org Date: Sat May 24 13:44:14 2014 +0200
alfred: Handle fcntl error return codes
fcntl doesn't return non-error return values when starting a F_GETFL operation. These have to be handled or otherwise a garbage value is given to fcntl for the F_SETFL operation.
Signed-off-by: Sven Eckelmann sven@narfation.org Signed-off-by: Simon Wunderlich sw@simonwunderlich.de
217c8deb9484d1705bf26523b77dba7503d4d131 netsock.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/netsock.c b/netsock.c index 8712c11..305983f 100644 --- a/netsock.c +++ b/netsock.c @@ -48,6 +48,7 @@ int netsock_open(struct globals *globals) int sock; struct sockaddr_in6 sin6; struct ifreq ifr; + int ret;
globals->netsock = -1;
@@ -86,7 +87,18 @@ int netsock_open(struct globals *globals) goto err; }
- fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK); + ret = fcntl(sock, F_GETFL, 0); + if (ret < 0) { + fprintf(stderr, "failed to get file status flags\n"); + goto err; + } + + ret = fcntl(sock, F_SETFL, ret | O_NONBLOCK); + if (ret < 0) { + fprintf(stderr, "failed to set file status flags\n"); + goto err; + } + globals->netsock = sock;
return 0;