All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Simon Wunderlich <sw@simonwunderlich.de>
Cc: b.a.t.m.a.n@lists.open-mesh.org, Antonio Quartulli <a@unstable.cc>
Subject: Re: [B.A.T.M.A.N.] [PATCH 2/3] alfred: Add support for network namespaces
Date: Tue, 2 Feb 2016 03:22:38 +0100	[thread overview]
Message-ID: <20160202022238.GD12673@lunn.ch> (raw)
In-Reply-To: <3299385.slEDhCLINf@prime>

On Fri, Jan 29, 2016 at 01:18:13PM +0100, Simon Wunderlich wrote:
> On Thursday 28 January 2016 04:53:14 Andrew Lunn wrote:
> > When running within a network namespace, access to files within
> > debugfs have to take into account the network name space. Each
> > namespace has its own directory under
> > /sys/kernel/debug/batman_adv/netns.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> >  batadv_query.c |  2 +-
> >  debugfs.c      | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
> >  vis/vis.h      |  2 +-
> >  3 files changed, 50 insertions(+), 3 deletions(-)
> > 
> > diff --git a/batadv_query.c b/batadv_query.c
> > index c289b80..fe7c007 100644
> > --- a/batadv_query.c
> > +++ b/batadv_query.c
> > @@ -31,7 +31,7 @@
> >  #include <sys/types.h>
> >  #include "debugfs.h"
> > 
> > -#define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s"
> > +#define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s%s"
> >  #define DEBUG_TRANSTABLE_GLOBAL "transtable_global"
> >  #define DEBUG_ORIGINATORS "originators"
> > 
> > diff --git a/debugfs.c b/debugfs.c
> > index fc39322..35c1bdf 100644
> > --- a/debugfs.c
> > +++ b/debugfs.c
> > @@ -20,11 +20,15 @@
> > 
> >  #include "debugfs.h"
> >  #include <errno.h>
> > +#include <fcntl.h>
> > +#include <limits.h>
> >  #include <stdio.h>
> >  #include <string.h>
> >  #include <sys/mount.h>
> >  #include <sys/stat.h>
> >  #include <sys/statfs.h>
> > +#include <sys/types.h>
> > +#include <unistd.h>
> > 
> >  #ifndef DEBUGFS_MAGIC
> >  #define DEBUGFS_MAGIC          0x64626720
> > @@ -42,16 +46,59 @@ static const char *debugfs_known_mountpoints[] = {
> >  	NULL,
> >  };
> > 
> > +/* Return the current net namespace number. 0 is never a valid
> > + * namespace, so use it to return that there is no name space
> > + * support.
> > + */
> > +
> > +static unsigned int debugfs_get_netns_inum(void)
> > +{
> > +	char net_path[] = "/proc/self/ns/net";
> > +	struct stat netst;
> > +	int netns;
> > +
> > +	netns = open(net_path, O_RDONLY);
> > +	if (netns < 0) {
> > +		if (errno == ENOENT)
> > +			/* Probably means no netns support in the kernel */
> > +			return 0;
> > +
> > +		fprintf(stderr,
> > +			"Error - can't open /proc/self/ns/net for read: %s\n",
> > +			strerror(errno));
> > +		return 0;
> > +	}
> > +
> > +	if (fstat(netns, &netst) < 0) {
> > +		fprintf(stderr, "Stat of netns failed: %s\n",
> > +			strerror(errno));
> > +		return 0;
> 
> Aren't we leaking the netns file descriptor here?

Yes, it is leaking. I will fix that in a v2.

Thanks
     Andrew


  reply	other threads:[~2016-02-02  2:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-28  3:53 [B.A.T.M.A.N.] [PATCH 1/3] alfred: vis: Use debugfs_make_path helper Andrew Lunn
2016-01-28  3:53 ` [B.A.T.M.A.N.] [PATCH 2/3] alfred: Add support for network namespaces Andrew Lunn
2016-01-29 12:18   ` Simon Wunderlich
2016-02-02  2:22     ` Andrew Lunn [this message]
2016-01-28  3:53 ` [B.A.T.M.A.N.] [PATCH 3/3] alfred: Mount debugfs before reducing capabilities Andrew Lunn
2016-01-29 12:14   ` Simon Wunderlich
2016-02-02  2:25     ` Andrew Lunn
2016-03-10 15:09       ` Simon Wunderlich
2016-03-10 15:49         ` Andrew Lunn
2016-03-11 13:48 ` [B.A.T.M.A.N.] [PATCH 1/3] alfred: vis: Use debugfs_make_path helper 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=20160202022238.GD12673@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=a@unstable.cc \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=sw@simonwunderlich.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.