public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [B.A.T.M.A.N.] [PATCH 09/10] alfred: Handle fcntl error return codes
Date: Sat, 24 May 2014 13:44:14 +0200	[thread overview]
Message-ID: <1400931855-7961-9-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1400931855-7961-1-git-send-email-sven@narfation.org>

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>

---
 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;
-- 
2.0.0.rc2


  parent reply	other threads:[~2014-05-24 11:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-24 11:44 [B.A.T.M.A.N.] [PATCH 01/10] batadv-vis: Avoid memory leak after failed realloc Sven Eckelmann
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 02/10] alfred: Force null termination of string after strncpy Sven Eckelmann
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 03/10] batadv-vis: Avoid memory leak when tl parsing failed Sven Eckelmann
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 04/10] alfred: Use pre-allocated object for global variables Sven Eckelmann
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 05/10] batadv-vis: Avoid invalid access in orig_list Sven Eckelmann
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 06/10] alfred-gpsd: Fix altitute verification check Sven Eckelmann
2014-05-24 14:45   ` Andrew Lunn
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 07/10] alfred: Use strncpy instead of strcpy for string copy Sven Eckelmann
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 08/10] alfred: Free hash iterator when breaking out of loop Sven Eckelmann
2014-05-24 11:44 ` Sven Eckelmann [this message]
2014-05-24 11:44 ` [B.A.T.M.A.N.] [PATCH 10/10] alfred: Fix length check for push_data Sven Eckelmann
2014-05-27 14:08 ` [B.A.T.M.A.N.] [PATCH 01/10] batadv-vis: Avoid memory leak after failed realloc Simon Wunderlich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400931855-7961-9-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox