[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ltp-list
Subject:    Re: [LTP] [PATCH v2 2/3] setns: add new syscall test setns01
From:       chrubis () suse ! cz
Date:       2013-02-12 12:33:23
Message-ID: 20130212123323.GA9378 () rei
[Download RAW message or body]

Hi!
> +#define NS_MAX 5
> +static int ns_types[NS_MAX];
> +static int ns_fds[NS_MAX];
> +static int ns_total;
> +
> +static int get_ns_fd(int pid, const char *ns)
> +{
> +	char tmp[PATH_MAX];
> +	struct stat st;
> +	int fd = -1;
> +
> +	sprintf(tmp, "/proc/%d/%s", pid, ns);
> +	if (stat(tmp, &st) == 0) {
> +		fd = open(tmp, O_RDONLY);
> +		if (fd == -1)
> +			tst_brkm(TBROK|TERRNO, NULL, "failed to open %s", tmp);
> +	} else {
> +		if (errno != ENOENT)
> +			tst_brkm(TBROK|TERRNO, NULL, "failed to stat %s", tmp);
> +	}
> +	return fd;
> +}
> +
> +static void init_available_ns()

Missing void in the function parameters.

> +{
> +#define INIT_NS_TYPE(clone_type, proc_name) \
> +{ \
> +	int fd; \
> +	fd = get_ns_fd(getpid(), "ns/"proc_name); \
> +	if (fd != -1) { \
> +		ns_types[ns_total] = clone_type; \
> +		ns_fds[ns_total] = fd; \
> +		tst_resm(TINFO, "ns_fds[%d]=%d, ns_types[%d]=0x%x", ns_total, \
> +			fd, ns_total, clone_type); \
> +		ns_total++; \
> +	} \
> +}

I'm wondering why this is a macro and not regular function. The only
thing that I see and that wouldn't work is the string
concatenation, which should have been done before the function is
called. Or the get_ns_fd() could have additional parameter, since it
uses sprintf() anyway.

> +#if defined(CLONE_NEWIPC)
> +	INIT_NS_TYPE(CLONE_NEWIPC, "ipc");
> +#endif
> +#if defined(CLONE_NEWNS)
> +	INIT_NS_TYPE(CLONE_NEWNS, "mnt");
> +#endif
> +#if defined(CLONE_NEWNET)
> +	INIT_NS_TYPE(CLONE_NEWNET, "net");
> +#endif
> +#if defined(CLONE_NEWPID)
> +	INIT_NS_TYPE(CLONE_NEWPID, "pid");
> +#endif
> +#if defined(CLONE_NEWUTS)
> +	INIT_NS_TYPE(CLONE_NEWUTS, "uts");
> +#endif
> +
> +#undef INIT_NS_TYPE
> +}
> +
> +static void close_ns_fds()

Here missing void as well.

> +{
> +	int i;
> +
> +	for (i = 0; i < ns_total; i++)
> +		if (ns_fds[i] != -1)
> +			close(ns_fds[i]);
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic