netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shawn Landden <shawn@churchofgit.com>
To: netfilter-devel@vger.kernel.org
Cc: Shawn Landden <shawn@churchofgit.com>
Subject: [PATCH] netlink: do not SIGSEGV when socket() fails
Date: Wed,  4 Dec 2013 11:12:20 -0800	[thread overview]
Message-ID: <1386184340-74134-1-git-send-email-shawn@churchofgit.com> (raw)

---
 src/netlink.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/netlink.c b/src/netlink.c
index 533634a..664487d 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -33,8 +33,11 @@ static struct mnl_socket *nf_sock;
 static void __init netlink_open_sock(void)
 {
 	nf_sock = mnl_socket_open(NETLINK_NETFILTER);
-	if (nf_sock == NULL)
+	if (nf_sock == NULL) {
+                fprintf(fdopen(STDERR_FILENO, "a"), "Could not open AF_NETLINK socket: %s\n",
+                                        strerror(errno));
 		memory_allocation_error();
+        }
 
 	fcntl(mnl_socket_get_fd(nf_sock), F_SETFL, O_NONBLOCK);
 	mnl_batch_init();
@@ -42,7 +45,8 @@ static void __init netlink_open_sock(void)
 
 static void __exit netlink_close_sock(void)
 {
-	mnl_socket_close(nf_sock);
+        if (nf_sock)
+                mnl_socket_close(nf_sock);
 }
 
 int netlink_io_error(struct netlink_ctx *ctx, const struct location *loc,
-- 
1.8.5.1


             reply	other threads:[~2013-12-04 19:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04 19:12 Shawn Landden [this message]
2013-12-04 19:30 ` [PATCH] netlink: do not SIGSEGV when socket() fails Arturo Borrero Gonzalez
2013-12-04 20:01   ` [nftables PATCH] " Shawn Landden
2013-12-04 20:30     ` Florian Westphal
2013-12-05  3:18       ` [PATCH] " Shawn Landden
2013-12-05  9:03         ` Pablo Neira Ayuso

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=1386184340-74134-1-git-send-email-shawn@churchofgit.com \
    --to=shawn@churchofgit.com \
    --cc=netfilter-devel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).